mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-22 03:00:10 +00:00
Handle parameter deserialization errors
This commit is contained in:
parent
06e80079fe
commit
b75798aa62
2 changed files with 24 additions and 1 deletions
|
@ -108,7 +108,10 @@ class Parameter(object):
|
|||
if not self.schema:
|
||||
return value
|
||||
|
||||
deserialized = self.deserialize(value)
|
||||
try:
|
||||
deserialized = self.deserialize(value)
|
||||
except (ValueError, AttributeError) as exc:
|
||||
raise InvalidParameterValue(str(exc))
|
||||
|
||||
try:
|
||||
return self.schema.unmarshal(deserialized)
|
||||
|
|
|
@ -297,6 +297,26 @@ class TestPetstore(object):
|
|||
assert response_result.errors == []
|
||||
assert response_result.data == data_json
|
||||
|
||||
def test_get_pets_parameter_deserialization_error(self, spec):
|
||||
host_url = 'http://petstore.swagger.io/v1'
|
||||
path_pattern = '/v1/pets'
|
||||
query_params = {
|
||||
'limit': 1,
|
||||
'tags': 12,
|
||||
}
|
||||
|
||||
request = MockRequest(
|
||||
host_url, 'GET', '/pets',
|
||||
path_pattern=path_pattern, args=query_params,
|
||||
)
|
||||
|
||||
with pytest.raises(InvalidParameterValue):
|
||||
request.get_parameters(spec)
|
||||
|
||||
body = request.get_body(spec)
|
||||
|
||||
assert body is None
|
||||
|
||||
def test_get_pets_wrong_parameter_type(self, spec):
|
||||
host_url = 'http://petstore.swagger.io/v1'
|
||||
path_pattern = '/v1/pets'
|
||||
|
|
Loading…
Reference in a new issue