From 3f222361c8bd859873abd76a35341969dd659f0d Mon Sep 17 00:00:00 2001 From: Ben Strutt Date: Thu, 4 Jul 2019 16:30:17 +0100 Subject: [PATCH 1/2] Add tests for nested/polymorphic with ordered api. The 6 tests added tests shadow the only tests that fail when ordered=True was set in the fixture. --- tests/test_swagger.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_swagger.py b/tests/test_swagger.py index 859994ae..af1eb56d 100644 --- a/tests/test_swagger.py +++ b/tests/test_swagger.py @@ -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, @@ -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, @@ -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): @@ -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 @@ -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, @@ -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, From 6c443d39bedeabbec03c25a67cb57c4937e5f2be Mon Sep 17 00:00:00 2001 From: Ben Strutt Date: Thu, 4 Jul 2019 16:32:42 +0100 Subject: [PATCH 2/2] Add checks for OrderedModel in swagger.py Add check for OrderedModel in Swagger.register_model(self, model) Add check for OrderedModel in ref(model) --- flask_restplus/swagger.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flask_restplus/swagger.py b/flask_restplus/swagger.py index 681b08d2..3f71050a 100644 --- a/flask_restplus/swagger.py +++ b/flask_restplus/swagger.py @@ -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 @@ -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)} @@ -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)