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

@api.expect decorator with RequestParser does not generate expected swagger.json

Open austindebruyn opened this issue 7 years ago • 2 comments

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. screen shot 2017-11-12 at 1 24 22 pm

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.

screen shot 2017-11-12 at 1 24 08 pm

Here's a quick repro, but the use case is not very unusual. https://github.com/austindebruyn/flask-reqparse-repro

austindebruyn avatar Nov 12 '17 21:11 austindebruyn

@api.expect has issues with nested data validation. I personally feel its better to use marshmallow.

rahulmg05 avatar Dec 05 '17 16:12 rahulmg05

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

vgonisanz avatar Feb 28 '20 11:02 vgonisanz