flask-restplus
flask-restplus copied to clipboard
Swagger UI assumes body payload when using api_ns.expect(model) for HTTP GET handler
Looking through the the docs, there's an example of setting a model as an expected input to the get request handler, and to me it would be reasonable to assume that restplus would use this model to validate query string parameters as it's the only place that would make sense for it to be in the request. When using the same model for a post, swagger UI renders it as body request parameter, which makes sense. I'm just wondering if I'm wrong in my assumptions and this is by design, or it's a bug?
Current version of flask-restplus: 0.11.0
class SomeResource(Resource):
@my_api_ns.expect(my_super_cool_model)
def get(self):
# This will render as a body request param, not expected
return {}
@my_api_ns.expect(my_super_cool_model)
def post(self):
# This will render as a body request param, as expected
return {}
I met the same issue.
Use parser to solve this.
parser = api.parser()
parser.add_argument('param', type=int, help='Some param', location='path') # `location` specifies the parameter type
@api.expect(parser)
...
I've encountered the same issue. I've worked around it for now with parser, but it seems like you lose some of the flexibility of models going that way. Also, parser appears to be a deprecated piece of functionality.
Is there a model based way to achieve this? Digging around in the source it all gets passed through the doc method, so I'm guessing there must be some way to do it, I just haven't figured it out yet.
You could put it into the doc yourself with the doc method, but there isn't currently a model-based way of achieving this.
Any update on this issue? I am facing the same problem, wanting to use model as my @api.expect rather than parser due to the limited flexibility of parser.