-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Looking for a way to use a schema to define acceptable query params #45
Comments
I personally have been down this path and totally understand what you are after; however, there are some philosophical concerns with wanting to provide a body with a GET request. This SO post summarizes it. In my experience, the use cases where you think you want this behavior boil down to largely three cases:
Happy to discuss further. |
Closing |
I agree with you that a GET request cannot accept a body. In this case I am trying to accomplish case #3 more easily. I want to use Marshmallow schemas to add query params for several reasons:
With the current implementation of accepts if you pass a schema object it assumes everything in that schema goes in the payload. Unfortunately that means you cannot define a GET with a schema in the request because the swagger example that gets generated by flask-restplus requires a body and most browsers will throw an error just for attempting to pass a body with a GET. I am proposing we allow the passing of a schema to @accepts on GETs. By default all the fields in the schema are assumed to be location='args' if you want to support multiple locations you can override the schema field location in the decorator with a dict(name=schema_field_name, location=['headers', 'args', 'values'...etc]) |
I second BenC14s request. Being able to use a Schema for uri parameters for a GET would be very welcomed. |
+1 on this — I have a few |
Marking this as a feature request. This could be implemented by adding an additional parameter to the decorators that accepted a |
@apryor6 Awesome thanks for the response. Adding those parameters would vastly improve things on my end — thank you. |
@apryor6 Do you have a sense for your bandwidth to complete this request? If you're slammed (understandably so during these times), then I'd be happy to take a whack at it. |
My bandwidth is pretty nonexistent, unfortunately. I would be happy to review and accept a backwards compatible PR with tests. I would think we could accomplish this with an additional keyword parameter to the accepts decorator like |
I have a case where I defined a marshmallow schema that is being used in both @accepts and @responds for different methods. I would like to use the schema object in an @accepts for a get_all route but instead of the fields being defined in the body of the request they should be query params. For example a UserSchema might have 3 fields.
and we might have a get_all route like this
I would like to have a route with documented parameters based on the schema
Perhaps something like
It seems like if we are returning a UserSchema object/s with this request we should be able to easily make all of that schemas dump-able fields queryable.
End result would document the existence of ?userId ?firstName and ?emailAddress.
and request.parsed_args would be a dict with 'user_id', 'first_name', 'email' as well as the other query arg dicts 'limit' and 'page'
The text was updated successfully, but these errors were encountered: