flask-restplus
flask-restplus copied to clipboard
@api.expect decorator with RequestParser does not generate expected swagger.json
What I did
- Defined my model in an instance of
flask_restplus.reqparse.RequestParser
- Used
parser.parse_args(strict=True)
to perform auto-validating as documented here - Used
@api.expect(parser)
as documented here
What I expected
A swagger output like this: https://github.com/austindebruyn/flask-reqparse-repro/blob/master/swagger_expected.json
It works when using @api.expect('SomeModel')
instead of @api.expect(parser)
. This correctly identified both fields task
and priority
as members of a payload json.
Actual output
https://github.com/austindebruyn/flask-reqparse-repro/blob/master/swagger_actual.json
This corresponds to two json bodies, and is not serialized and sent by the UI. It is impossible to send a valid request via the swagger UI "try it out" in this case.
The OpenAPI docs on the parameter definition specifies that there can only be one body
parameter, so I'm positive that bad output is being generated by flask-restplus here.

Here's a quick repro, but the use case is not very unusual. https://github.com/austindebruyn/flask-reqparse-repro
@api.expect has issues with nested data validation. I personally feel its better to use marshmallow.
I use @api.expect because i'm using reqparse to manage werkzeug.datastructures.FileStorage.
The data displays OK in the documentation website generated but these input files don't appear when I use print(json.dump(api.__schema__, f))
Anyone know a way to generate @api.expect documentation for inputs? If not, anyone know to to use marshmallow with input models with files?
It seems related with https://github.com/noirbizarre/flask-restplus/issues/724