From b75798aa62151cbc403c0389698e1c21852218b7 Mon Sep 17 00:00:00 2001 From: Artur Maciag Date: Fri, 17 Aug 2018 11:42:52 +0100 Subject: [PATCH] Handle parameter deserialization errors --- openapi_core/schema/parameters/models.py | 5 ++++- tests/integration/test_petstore.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/openapi_core/schema/parameters/models.py b/openapi_core/schema/parameters/models.py index 62a3a39..9b495a2 100644 --- a/openapi_core/schema/parameters/models.py +++ b/openapi_core/schema/parameters/models.py @@ -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) diff --git a/tests/integration/test_petstore.py b/tests/integration/test_petstore.py index d6b8a5d..0cbe55d 100644 --- a/tests/integration/test_petstore.py +++ b/tests/integration/test_petstore.py @@ -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'