Skip to content

Commit d24e57d

Browse files
committed
Parameter simple scenarion for any schema type fix
1 parent 98f4ae7 commit d24e57d

File tree

3 files changed

+84
-4
lines changed

3 files changed

+84
-4
lines changed

openapi_core/schema/parameters.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
from __future__ import division
2+
3+
14
def get_aslist(param):
2-
return (
3-
param.get('schema', None) and
4-
param['schema']['type'] in ['array', 'object']
5-
)
5+
"""Checks if parameter is described as list for simpler scenarios"""
6+
# if schema is not defined it's a complex scenario
7+
if 'schema' not in param:
8+
return False
9+
10+
param_schema = param / 'schema'
11+
schema_type = param_schema.getkey('type', 'any')
12+
# TODO: resolve for 'any' schema type
13+
return schema_type in ['array', 'object']
614

715

816
def get_style(param):
17+
"""Checks parameter style for simpler scenarios"""
918
if 'style' in param:
1019
return param['style']
1120

@@ -16,6 +25,7 @@ def get_style(param):
1625

1726

1827
def get_explode(param):
28+
"""Checks parameter explode for simpler scenarios"""
1929
if 'explode' in param:
2030
return param['explode']
2131

tests/integration/data/v3.0/petstore.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ paths:
6060
items:
6161
type: integer
6262
format: int32
63+
- name: order
64+
in: query
65+
schema:
66+
oneOf:
67+
- type: string
68+
- type: integer
69+
format: int32
6370
- name: tags
6471
in: query
6572
description: Filter pets with tags

tests/integration/validation/test_petstore.py

+63
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,69 @@ def test_get_pets_none_value(self, spec):
365365

366366
assert body is None
367367

368+
def test_get_pets_param_order(self, spec):
369+
host_url = 'http://petstore.swagger.io/v1'
370+
path_pattern = '/v1/pets'
371+
query_params = {
372+
'limit': None,
373+
'order': 'desc',
374+
}
375+
376+
request = MockRequest(
377+
host_url, 'GET', '/pets',
378+
path_pattern=path_pattern, args=query_params,
379+
)
380+
381+
parameters = validate_parameters(spec, request)
382+
383+
assert parameters == RequestParameters(
384+
query={
385+
'limit': None,
386+
'order': 'desc',
387+
'page': 1,
388+
'search': '',
389+
}
390+
)
391+
392+
body = validate_body(spec, request)
393+
394+
assert body is None
395+
396+
@pytest.mark.xfail(
397+
reason="No parameters deserialization support for complex scenarios"
398+
)
399+
def test_get_pets_param_coordinates(self, spec):
400+
host_url = 'http://petstore.swagger.io/v1'
401+
path_pattern = '/v1/pets'
402+
coordinates = {
403+
'lat': 1.12,
404+
'lon': 32.12,
405+
}
406+
query_params = {
407+
'limit': None,
408+
'coordinates': json.dumps(coordinates),
409+
}
410+
411+
request = MockRequest(
412+
host_url, 'GET', '/pets',
413+
path_pattern=path_pattern, args=query_params,
414+
)
415+
416+
parameters = validate_parameters(spec, request)
417+
418+
assert parameters == RequestParameters(
419+
query={
420+
'limit': None,
421+
'page': 1,
422+
'search': '',
423+
'coordinates': coordinates,
424+
}
425+
)
426+
427+
body = validate_body(spec, request)
428+
429+
assert body is None
430+
368431
def test_post_birds(self, spec, spec_dict):
369432
host_url = 'https://staging.gigantic-server.com/v1'
370433
path_pattern = '/v1/pets'

0 commit comments

Comments
 (0)