Skip to content

Commit 573bfde

Browse files
Register models nested inside response fields (python-restx#613)
Fix python-restx#613. When using e.g. `fields.List` for response structures, any models nested inside are now correctly registered.
1 parent f1eeaa0 commit 573bfde

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

flask_restx/swagger.py

+7
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ def serialize_schema(self, model):
680680
return self.serialize_schema(model())
681681

682682
elif isinstance(model, fields.Raw):
683+
self.register_field(model)
683684
return model.__schema__
684685

685686
elif isinstance(model, (type, type(None))) and model in PY_TYPES:
@@ -704,6 +705,12 @@ def register_model(self, model):
704705
return ref(model)
705706

706707
def register_field(self, field):
708+
"""
709+
Traverse a "container" field (`Nested`, `List`, `Wildcard`,
710+
and `Polymorph`) and register any nested models. Used for
711+
models nested inside other models or responses using fields
712+
for definition.
713+
"""
707714
if isinstance(field, fields.Polymorph):
708715
for model in field.mapping.values():
709716
self.register_model(model)

0 commit comments

Comments
 (0)