flask-accept icon indicating copy to clipboard operation
flask-accept copied to clipboard

Flask-REST Marshmallow Two-way Nesting Schemas

Open froggylab opened this issue 4 years ago • 1 comments

TL;DR : Is there a way to accept string Nested marshmallow fields ?

In order to avoid circular import in a flask/marshmallow project, it's possible to reference the Nested field by using its name (as described here https://marshmallow.readthedocs.io/en/latest/nesting.html#two-way-nesting)

Unfortunately, flask_accept doesn't support it :

` File env/lib/python3.8/site-packages/flask_accepts/decorators/decorators.py", line 110, in decorator body = for_swagger( File "env/lib/python3.8/site-packages/flask_accepts/utils.py", line 63, in for_swagger fields = { File "env/lib/python3.8/site-packages/flask_accepts/utils.py", line 64, in k: map_type(v, api, model_name, operation) File "env/lib/python3.8/site-packages/flask_accepts/utils.py", line 182, in map_type return type_map[value_type](val, api, model_name, operation) File "env/lib/python3.8/site-packages/flask_accepts/utils.py", line 19, in unpack_nested model_name = get_default_model_name(val.nested) File "env/lib/python3.8/site-packages/flask_accepts/utils.py", line 152, in get_default_model_name return "".join(schema.name.rsplit("Schema", 1))

AttributeError: 'str' object has no attribute 'name' `

Can you please add the possibility to support this configuration ?

froggylab avatar Jan 27 '20 12:01 froggylab