From e88bef490de6b1b2c9b4dbe0e23404b26c69ec9f Mon Sep 17 00:00:00 2001 From: Gouji Ochiai Date: Tue, 19 Nov 2019 13:06:50 +0900 Subject: [PATCH 1/2] webob's multidict protocol does not support getlist. --- requirements_dev.txt | 1 + setup.cfg | 1 + .../integration/validation/test_validators.py | 27 ++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 37815b2..bac940f 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -4,3 +4,4 @@ pytest-flake8 pytest-cov==2.5.1 flask django==2.2.6; python_version>="3.0" +webob diff --git a/setup.cfg b/setup.cfg index bd43a27..6cfa768 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,6 +37,7 @@ tests_require = pytest-flake8 pytest-cov flask + webob [options.packages.find] exclude = diff --git a/tests/integration/validation/test_validators.py b/tests/integration/validation/test_validators.py index 449fdf4..b3f98ea 100644 --- a/tests/integration/validation/test_validators.py +++ b/tests/integration/validation/test_validators.py @@ -94,7 +94,7 @@ class TestRequestValidator(object): def test_get_pets(self, validator): request = MockRequest( self.host_url, 'get', '/v1/pets', - path_pattern='/v1/pets', args={'limit': '10'}, + path_pattern='/v1/pets', args={'limit': '10', 'ids': ['1', '2']}, ) result = validator.validate(request) @@ -106,6 +106,31 @@ class TestRequestValidator(object): 'limit': 10, 'page': 1, 'search': '', + 'ids': [1, 2], + }, + ) + + def test_get_pets_webob(self, validator): + from webob.multidict import GetDict + request = MockRequest( + self.host_url, 'get', '/v1/pets', + path_pattern='/v1/pets', + ) + request.parameters.query = GetDict( + [('limit', '5'), ('ids', '1'), ('ids', '2')], + {} + ) + + result = validator.validate(request) + + assert result.errors == [] + assert result.body is None + assert result.parameters == RequestParameters( + query={ + 'limit': 5, + 'page': 1, + 'search': '', + 'ids': [1, 2], }, ) From 8152d20e8e254ed86f51fd2ad55f7841d99399aa Mon Sep 17 00:00:00 2001 From: Gouji Ochiai Date: Tue, 19 Nov 2019 13:07:20 +0900 Subject: [PATCH 2/2] use getall instead of getlist --- openapi_core/schema/parameters/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openapi_core/schema/parameters/models.py b/openapi_core/schema/parameters/models.py index 98af859..766116d 100644 --- a/openapi_core/schema/parameters/models.py +++ b/openapi_core/schema/parameters/models.py @@ -87,6 +87,8 @@ class Parameter(object): return self.schema.default if self.aslist and self.explode: + if hasattr(location, 'getall'): + return location.getall(self.name) return location.getlist(self.name) return location[self.name]