-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Passing array in query via axios #517
Comments
There's two issues
1/ is a webargs issue, so I'll transfer to webargs. You'll have to write a custom parser (see https://webargs.readthedocs.io/en/latest/advanced.html#custom-parsers). 2/ is an apispec issue. I'm not sure there's a way to write a spec that will display correctly in a frontend such as ReDoc or Swagger-UI, so you might end up just adding a generic comment at the beginning of the spec. |
Great, thanks for pointing me in the right direction! Update: I just realized I probably should leave this ticket open so that the webargs team can have a look at it and decide to take it up or not. |
As @lafrech said, you could write a custom parser which handles this for you. That's the best approach available today. Since axios appears to be a pretty popular, I'd be happy to have a new section in the docs for examples, with an It looks to me like axios is actually using another library, Looking at how |
Thank you for considering this. FWIW, I cobbled something together that serves my purpose, but it's far from a full parser of qs generated querystrings. It doesn't handle complex nested objects for example (see the last test in the code below). I might try and create a PR later, but I wanted to leave this already here if that's ok with you. By the way, I couldn't find a way for marshmallow or flask_smorest to use this parser. If someone can point me in the right direction, I'd like to add an explanation to the docs about that.
|
Just FYI, you can configure axios to not do this Just pass |
To support both communities (agree axios looks wired... ejm ejm) the better would might be to "decode" the axios transformation back. To do so, you mentioned that you are using from marshmallow import Schema, pre_load
from werkzeug.datastructures import ImmutableMultiDict
...
class BaseSchema(Schema):
"""Base schema to control your common schema features."""
class Meta:
"""Normally your Meta go here"""
....
@pre_load # Support PHP¿? and axios query framework
def process_input(self, data, **kwargs):
fixed_args = [(x.replace('[]', ''), y) for x,y in data.data._iter_hashitems()]
data.data = ImmutableMultiDict(fixed_args)
return data Note it is a |
Hi,
I'm using axios to send a GET request to my flask-smorest endpoint.
I know there's no real agreement on this spec-wise, but the request's querystring contains an array, and axios sends it in this format:
I've defined the schema used for reading the arguments as
Yet when I try to read the data received in my endpoint, types is empty:
Is this a missing feature in flask-smorest or should I ask on SO whether I should use another way to pass data?
The text was updated successfully, but these errors were encountered: