Skip to content

Handle parameter deserialization errors #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion openapi_core/schema/parameters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ def unmarshal(self, value):
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)
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/test_petstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,26 @@ def test_get_pets_tags_param(self, spec, response_validator):
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'
Expand Down