Skip to content
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

collectionFormat=multi is missing for MultiChoiceFields #257

Closed
oselz opened this issue Nov 28, 2018 · 2 comments
Closed

collectionFormat=multi is missing for MultiChoiceFields #257

oselz opened this issue Nov 28, 2018 · 2 comments
Assignees
Labels
bug Bug report/fix

Comments

@oselz
Copy link

oselz commented Nov 28, 2018

drf uses multiple parameter instances for passing multiple fields on query parameters (of the form ?param=one&param=two); however the swagger spec defaults to csv for multiple parameters (https://swagger.io/docs/specification/2-0/describing-parameters/#array).

drf-yasg needs to insert 'collectionFormat=multi' onto the parameter schema to correctly describe the format. eg.

"parameters": [{
  "name": "myparam",
  "in": "query",
  "type": "array",
  "collectionFormat": "multi",
  "items": {
    "type": "string",
    "enum": [
      "item1",
      "item2"
    ]
  },
},]

At present this means that selecting multiple values in swagger-ui for a field defined as a MultipleChoiceField doesn't work as the ui generates csv queries, which don't work in drf.

I'm not exactly sure how to fix this correctly in drf-yasg as it is dependent on parameter type (formData and query only). I brute forced it for now which solved my problem, but it's not ideal. Suggestions?

@axnsan12 axnsan12 added the bug Bug report/fix label Nov 28, 2018
@axnsan12 axnsan12 self-assigned this Nov 28, 2018
@oselz
Copy link
Author

oselz commented Nov 29, 2018

Impressive turnaround, thank you.

@axnsan12
Copy link
Owner

Looking at past issues, you would likely notice that this is more of an exception rather than a rule 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report/fix
Projects
None yet
Development

No branches or pull requests

2 participants