Skip to content

Issue ordered api nested model problems #662

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

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 3 additions & 3 deletions flask_restplus/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from werkzeug.routing import parse_rule

from . import fields
from .model import Model, ModelBase
from .model import Model, OrderedModel, ModelBase
from .reqparse import RequestParser
from .utils import merge, not_none, not_none_sorted
from ._http import HTTPStatus
Expand Down Expand Up @@ -50,7 +50,7 @@

def ref(model):
'''Return a reference to model in definitions'''
name = model.name if isinstance(model, ModelBase) else model
name = model.name if isinstance(model, (ModelBase, OrderedModel)) else model
return {'$ref': '#/definitions/{0}'.format(name)}


Expand Down Expand Up @@ -578,7 +578,7 @@ def register_model(self, model):
if isinstance(specs, ModelBase):
for parent in specs.__parents__:
self.register_model(parent)
if isinstance(specs, Model):
if isinstance(specs, (Model, OrderedModel)):
for field in itervalues(specs):
self.register_field(field)
return ref(model)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,10 @@ def post(self):
assert path['get']['responses']['200']['schema']['$ref'] == '#/definitions/Person'
assert path['post']['responses']['200']['schema']['$ref'] == '#/definitions/Person'

@pytest.mark.api(ordered=True)
def test_model_as_nested_dict_with_api_ordered(self, api, client):
self.test_model_as_nested_dict(api, client)

def test_model_as_nested_dict_with_details(self, api, client):
address_fields = api.model('Address', {
'road': restplus.fields.String,
Expand Down Expand Up @@ -1641,6 +1645,10 @@ def post(self):
'type': 'object'
}

@pytest.mark.api(ordered=True)
def test_model_as_nested_dict_with_details_with_api_ordered(self, api, client):
self.test_model_as_nested_dict_with_details(api, client)

def test_model_as_flat_dict_with_marchal_decorator(self, api, client):
fields = api.model('Person', {
'name': restplus.fields.String,
Expand Down Expand Up @@ -1879,6 +1887,10 @@ def get(self):
assert 'Person' in data['definitions']
assert 'Address' in data['definitions']

@pytest.mark.api(ordered=True)
def test_model_as_nested_dict_with_list_with_api_ordered(self, api, client):
self.test_model_as_nested_dict_with_list(api, client)

def test_model_list_of_primitive_types(self, api, client):
@api.route('/model-list/')
class ModelAsDict(restplus.Resource):
Expand Down Expand Up @@ -2191,6 +2203,10 @@ def get(self):
}]
}

@pytest.mark.api(ordered=True)
def test_inherit_inline_with_api_ordered(self, api, client):
self.test_inherit_inline(api, client)

def test_polymorph_inherit(self, api, client):
class Child1:
pass
Expand Down Expand Up @@ -2297,6 +2313,10 @@ def get(self):
}]
}

@pytest.mark.api(ordered=True)
def test_polymorph_inherit_with_api_ordered(self, api, client):
self.test_polymorph_inherit_list(api, client)

def test_expect_model(self, api, client):
person = api.model('Person', {
'name': restplus.fields.String,
Expand Down Expand Up @@ -2344,6 +2364,10 @@ def post(self):
}
assert 'description' not in parameter

@pytest.mark.api(ordered=True)
def test_polymorph_inhert_list_with_api_ordered(self, api, client):
self.test_polymorph_inherit_list(api, client)

def test_body_model_shortcut(self, api, client):
fields = api.model('Person', {
'name': restplus.fields.String,
Expand Down