diff --git a/openapi_core/schema/parameters.py b/openapi_core/schema/parameters.py index 78d39db3..cfc5ca19 100644 --- a/openapi_core/schema/parameters.py +++ b/openapi_core/schema/parameters.py @@ -1,11 +1,20 @@ +from __future__ import division + + def get_aslist(param): - return ( - param.get('schema', None) and - param['schema']['type'] in ['array', 'object'] - ) + """Checks if parameter is described as list for simpler scenarios""" + # if schema is not defined it's a complex scenario + if 'schema' not in param: + return False + + param_schema = param / 'schema' + schema_type = param_schema.getkey('type', 'any') + # TODO: resolve for 'any' schema type + return schema_type in ['array', 'object'] def get_style(param): + """Checks parameter style for simpler scenarios""" if 'style' in param: return param['style'] @@ -16,6 +25,7 @@ def get_style(param): def get_explode(param): + """Checks parameter explode for simpler scenarios""" if 'explode' in param: return param['explode'] diff --git a/tests/integration/data/v3.0/petstore.yaml b/tests/integration/data/v3.0/petstore.yaml index 9db095bd..55813c4f 100644 --- a/tests/integration/data/v3.0/petstore.yaml +++ b/tests/integration/data/v3.0/petstore.yaml @@ -60,6 +60,13 @@ paths: items: type: integer format: int32 + - name: order + in: query + schema: + oneOf: + - type: string + - type: integer + format: int32 - name: tags in: query description: Filter pets with tags diff --git a/tests/integration/validation/test_petstore.py b/tests/integration/validation/test_petstore.py index 4992e336..56065395 100644 --- a/tests/integration/validation/test_petstore.py +++ b/tests/integration/validation/test_petstore.py @@ -365,6 +365,69 @@ def test_get_pets_none_value(self, spec): assert body is None + def test_get_pets_param_order(self, spec): + host_url = 'http://petstore.swagger.io/v1' + path_pattern = '/v1/pets' + query_params = { + 'limit': None, + 'order': 'desc', + } + + request = MockRequest( + host_url, 'GET', '/pets', + path_pattern=path_pattern, args=query_params, + ) + + parameters = validate_parameters(spec, request) + + assert parameters == RequestParameters( + query={ + 'limit': None, + 'order': 'desc', + 'page': 1, + 'search': '', + } + ) + + body = validate_body(spec, request) + + assert body is None + + @pytest.mark.xfail( + reason="No parameters deserialization support for complex scenarios" + ) + def test_get_pets_param_coordinates(self, spec): + host_url = 'http://petstore.swagger.io/v1' + path_pattern = '/v1/pets' + coordinates = { + 'lat': 1.12, + 'lon': 32.12, + } + query_params = { + 'limit': None, + 'coordinates': json.dumps(coordinates), + } + + request = MockRequest( + host_url, 'GET', '/pets', + path_pattern=path_pattern, args=query_params, + ) + + parameters = validate_parameters(spec, request) + + assert parameters == RequestParameters( + query={ + 'limit': None, + 'page': 1, + 'search': '', + 'coordinates': coordinates, + } + ) + + body = validate_body(spec, request) + + assert body is None + def test_post_birds(self, spec, spec_dict): host_url = 'https://staging.gigantic-server.com/v1' path_pattern = '/v1/pets'