From 573bfde681a87f1ab3068bd8c66d2f01a14e96c4 Mon Sep 17 00:00:00 2001 From: "christoph.elfmann" Date: Mon, 12 Aug 2024 13:37:20 +0200 Subject: [PATCH] Register models nested inside response fields (#613) Fix #613. When using e.g. `fields.List` for response structures, any models nested inside are now correctly registered. --- flask_restx/swagger.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/flask_restx/swagger.py b/flask_restx/swagger.py index ec0a1975..53d44803 100644 --- a/flask_restx/swagger.py +++ b/flask_restx/swagger.py @@ -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: @@ -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)