Skip to content

Commit

Permalink
Register models nested inside response fields (python-restx#613)
Browse files Browse the repository at this point in the history
Fix python-restx#613. When using e.g. `fields.List` for response structures, any models nested inside are now correctly registered.
  • Loading branch information
christoph-elfmann committed Aug 12, 2024
1 parent f1eeaa0 commit 573bfde
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions flask_restx/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ def serialize_schema(self, model):
return self.serialize_schema(model())

elif isinstance(model, fields.Raw):
self.register_field(model)
return model.__schema__

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

def register_field(self, field):
"""
Traverse a "container" field (`Nested`, `List`, `Wildcard`,
and `Polymorph`) and register any nested models. Used for
models nested inside other models or responses using fields
for definition.
"""
if isinstance(field, fields.Polymorph):
for model in field.mapping.values():
self.register_model(model)
Expand Down

0 comments on commit 573bfde

Please sign in to comment.