Open db0 opened 2 years ago
I think this is actually a shortfall of Swagger 2.0 rather than flask-restx
. We currently use OpenAPI 2.0 to generate the swagger.json
file. The Parameter Object
specification requires you to set the in:
location, which only accepts a single string value:
Field Name: in
Type: string
Description: Required. The location of the parameter. Possible values are "query", "header", "path", "formData" or "body".
If this is just for authorizations, you might want to add them to swagger differently, such as using the build in documenting authorizations fields?
Oh cool. I'll look into that.
nevertheless, according to the documentation, my approach should work as well, no?
Yes, I agree the docs are unclear on this. The actual request parser will work correctly with your code (i.e. it will check both locations for the value), it's just the swagger docs that fail to be generated and that isn't mentioned anywhere currently, and it's all a bit messy!
A workaround I've used in the past is to define a separate API model / reqparser (which you can do with copy()
and replace_argument()
) for the endpoint with only a single location, but then use the multi-location one in code to actually do the parsing, but obviously that is not ideal either.
The replacement of request parsing / models with something more flexible has been under discussion for a long time on this project too!
Code
Expected Behavior
The swagger API should renger my regparser requirements correctly
Actual Behavior
If I set the
location
parameter of add_argument to a list of locations, theapi.expect(parser)
errorsError Messages/Stack Trace
Environment