Skip to content

Commit c46ff09

Browse files
AbdealiLoKoSahil Jolly
authored andcommitted
apidoc: Set default_in correctly for Schema/fields
default_in was changed to a mandatory kwarg parameter in apispec 3.x In a flask-apispec 0.8.4 this was changed to be set to "body" But this does not work correctly for GET urls where the params should be set to query-params base on the existig default_in value. Now, we retain the previous behavior where if a default-in is provided use that, if not provided - use "body"
1 parent e767e39 commit c46ff09

File tree

2 files changed

+17
-32
lines changed

2 files changed

+17
-32
lines changed

flask_apispec/apidoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def get_parameters(self, rule, view, docs, parent=None):
9898
locations = options.pop('locations', None)
9999
if locations:
100100
options['default_in'] = locations[0]
101-
else:
101+
elif 'default_in' not in options:
102102
options['default_in'] = 'body'
103103
extra_params += converter(schema, **options) if args else []
104104

tests/test_openapi.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def test_params(self, app, path):
299299
assert params == expected
300300

301301

302-
class TestFiledsNoLocationProvided:
302+
class TestGetFieldsNoLocationProvided:
303303

304304
@pytest.fixture
305305
def function_view(self, app):
@@ -320,26 +320,19 @@ def path(self, app, spec, function_view):
320320

321321
def test_params(self, app, path):
322322
params = path['get']['parameters']
323-
rule = app.url_map._rules_by_endpoint['get_band'][0]
324-
expected = (
325-
[{
326-
'in': 'body',
327-
'name': 'body',
328-
'required': False,
329-
'schema': {
330-
'properties': {
331-
'address': {
332-
'type': 'string'
333-
},
334-
'name': {
335-
'type': 'string'
336-
}
337-
},
338-
'type': 'object'
339-
},
340-
}] + rule_to_params(rule)
341-
)
342-
assert params == expected
323+
assert {
324+
'in': 'body',
325+
'name': 'body',
326+
'required': False,
327+
'schema': {
328+
'properties': {
329+
'address': {'type': 'string'},
330+
'name': {'type': 'string'},
331+
},
332+
'type': 'object',
333+
},
334+
} in params
335+
343336

344337
class TestSchemaNoLocationProvided:
345338

@@ -364,13 +357,5 @@ def path(self, app, spec, function_view):
364357

365358
def test_params(self, app, path):
366359
params = path['get']['parameters']
367-
rule = app.url_map._rules_by_endpoint['get_band'][0]
368-
expected = (
369-
[{
370-
'in': 'body',
371-
'name': 'body',
372-
'required': False,
373-
'schema': {'$ref': '#/definitions/Body'}
374-
}] + rule_to_params(rule)
375-
)
376-
assert params == expected
360+
assert {'name': 'body', 'in': 'body', 'required': False,
361+
'schema': {'$ref': '#/definitions/Body'}} in params

0 commit comments

Comments
 (0)