Is it possible to use flask_restful + marshmallow
See original GitHub issueI’m looking at this example that uses the docstring
to specify the swagger:
https://github.com/rochacbruno/flasgger/blob/master/examples/restful.py
In this example it seems like I cannot use use @swag_from
like in the marshmallow example, instead I must use the docstring
to pass the swagger description:
https://github.com/rochacbruno/flasgger/blob/master/examples/marshmallow_apispec.py
However, I would like to define my models using a Marshmallow schema, and then simply refer to those in the $ref
. Is that possible?
I mean currently, since I never tell flasgger anywhere about my schemas, it does not know that it should output them to the definitions
in the final swagger JSON. Can I make it do this somehow?
There’s a lot of overlapping functionality with all these projects flask, flask_restful and marshmallow, so maybe there is some easier way.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (3 by maintainers)
I made a little workaround, “not beautiful but rare”. At first I tried to register my Schemas via the
swagger.definition
decorator. As this decorator accepts only classes with the yaml docstring annotation I shortly converted the Marshmallow-Schema to these (Named “Magic” here as it does the very uncommon stuff; Also cut some sqlalchemy stuff from my application, so it has no claim to be complete):I hope this helps anyone who finds this ticket like me 😃 Also, maybe I missed a way where this is implemented correctly inside flasgger, this was only an internal prototype anyway. It still would be nice to have a common way for this (maybe by just adjusting the swagger.definition decorator, like
).
Ah yes that is one use case.
But from articulating my question and now looking at the Marshmallow example again I now saw this that I had missed before: https://github.com/rochacbruno/flasgger/blob/master/examples/marshmallow_apispec.py#L45-L47
Which does what I requested above. Except that it’s inside of the
SwaggerView
class. And it works now like I want 😃