Skip to content

Parameter simple scenarion for any schema type fix #323

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
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
18 changes: 14 additions & 4 deletions openapi_core/schema/parameters.py
Original file line number Diff line number Diff line change
@@ -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']

Expand All @@ -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']

Expand Down
7 changes: 7 additions & 0 deletions tests/integration/data/v3.0/petstore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions tests/integration/validation/test_petstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down