mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-29 11:09:25 +00:00
Merge pull request #16 from p1c2u/fix/boolean-value-cast-fix
Boolean value cast fix
This commit is contained in:
commit
c30bef179d
3 changed files with 58 additions and 2 deletions
|
@ -17,10 +17,18 @@ from openapi_core.models import ModelFactory
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def forcebool(val):
|
||||
if isinstance(val, str):
|
||||
val = strtobool(val)
|
||||
|
||||
return bool(val)
|
||||
|
||||
|
||||
DEFAULT_CAST_CALLABLE_GETTER = {
|
||||
SchemaType.INTEGER: int,
|
||||
SchemaType.NUMBER: float,
|
||||
SchemaType.BOOLEAN: lambda x: bool(strtobool(x)),
|
||||
SchemaType.BOOLEAN: forcebool,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -161,6 +161,8 @@ components:
|
|||
$ref: "#/components/schemas/Address"
|
||||
position:
|
||||
$ref: "#/components/schemas/Position"
|
||||
healthy:
|
||||
type: boolean
|
||||
Pets:
|
||||
type: array
|
||||
items:
|
||||
|
|
|
@ -370,6 +370,7 @@ class TestPetstore(object):
|
|||
pet_tag = 'cats'
|
||||
pet_street = 'Piekna'
|
||||
pet_city = 'Warsaw'
|
||||
pet_healthy = False
|
||||
data_json = {
|
||||
'name': pet_name,
|
||||
'tag': pet_tag,
|
||||
|
@ -377,7 +378,8 @@ class TestPetstore(object):
|
|||
'address': {
|
||||
'street': pet_street,
|
||||
'city': pet_city,
|
||||
}
|
||||
},
|
||||
'healthy': pet_healthy,
|
||||
}
|
||||
data = json.dumps(data_json)
|
||||
|
||||
|
@ -402,6 +404,50 @@ class TestPetstore(object):
|
|||
assert body.address.__class__.__name__ == address_model
|
||||
assert body.address.street == pet_street
|
||||
assert body.address.city == pet_city
|
||||
assert body.healthy == pet_healthy
|
||||
|
||||
def test_post_pets_boolean_string(self, spec, spec_dict):
|
||||
host_url = 'http://petstore.swagger.io/v1'
|
||||
path_pattern = '/v1/pets'
|
||||
pet_name = 'Cat'
|
||||
pet_tag = 'cats'
|
||||
pet_street = 'Piekna'
|
||||
pet_city = 'Warsaw'
|
||||
pet_healthy = 'false'
|
||||
data_json = {
|
||||
'name': pet_name,
|
||||
'tag': pet_tag,
|
||||
'position': '2',
|
||||
'address': {
|
||||
'street': pet_street,
|
||||
'city': pet_city,
|
||||
},
|
||||
'healthy': pet_healthy,
|
||||
}
|
||||
data = json.dumps(data_json)
|
||||
|
||||
request = MockRequest(
|
||||
host_url, 'POST', '/pets',
|
||||
path_pattern=path_pattern, data=data,
|
||||
)
|
||||
|
||||
parameters = request.get_parameters(spec)
|
||||
|
||||
assert parameters == {}
|
||||
|
||||
body = request.get_body(spec)
|
||||
|
||||
schemas = spec_dict['components']['schemas']
|
||||
pet_model = schemas['PetCreate']['x-model']
|
||||
address_model = schemas['Address']['x-model']
|
||||
assert body.__class__.__name__ == pet_model
|
||||
assert body.name == pet_name
|
||||
assert body.tag == pet_tag
|
||||
assert body.position == 2
|
||||
assert body.address.__class__.__name__ == address_model
|
||||
assert body.address.street == pet_street
|
||||
assert body.address.city == pet_city
|
||||
assert body.healthy is False
|
||||
|
||||
def test_post_pets_empty_body(self, spec, spec_dict):
|
||||
host_url = 'http://petstore.swagger.io/v1'
|
||||
|
|
Loading…
Reference in a new issue