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

application/x-www-form-urlencoded array encoding #4071

Closed
banders opened this issue Jan 4, 2018 · 4 comments
Closed

application/x-www-form-urlencoded array encoding #4071

banders opened this issue Jan 4, 2018 · 4 comments

Comments

@banders
Copy link
Contributor

banders commented Jan 4, 2018

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 3
Which Swagger-UI version? 3.8.0
How did you install Swagger-UI? cloned git repo, npm install, npm build
Which browser & version? Chrome Version 63.0.3239.84
Which operating system? Windows 10

Demonstration API definition

https://gist.githubusercontent.com/banders/29352a89a8ca4a17b46f46a6dd9fc84a/raw/afcf0137adf7f6ecb8e1b15cb0bb86b323807330/jobposting.json

Configuration

Test with:
[swagger-ui url]?url=https://gist.githubusercontent.com/banders/29352a89a8ca4a17b46f46a6dd9fc84a/raw/afcf0137adf7f6ecb8e1b15cb0bb86b323807330/jobposting.json#/Job_Feed/post_jobs

Test the 'POST Jobs' operation

Expected Behavior

The "industries" array parameter should be encoded as a csv list like this industries=1,16

Current Behavior

For an OAS2 spec the desired encoding for the array parameter could be achieved with "collectionFormat": "multi" in the parameter definition.

The OAS3 spec indicates that "collectionFormat": "multi" is now replaced by a "style": "form" value within the encoding. I have tried this (see the demonstration API definition), but the "industries" parameter gets encoded like this industries=[1,16]. The brackets are a problem for the underlying API.

Context

Is there any way to modify my OAS3 spec to encourage swagger-ui to encode the "industries" parameter without the brackets?

@shockey
Copy link
Contributor

shockey commented Jan 8, 2018

yep, this looks like a bug!

the specification document suggests that industries=1,16 is the correct style for an array with style: matrix:

messages image 907309341

@shockey
Copy link
Contributor

shockey commented Jan 8, 2018

also, [1,16] could be a JS array being coerced to a string somewhere in Swagger-Client.

@shockey
Copy link
Contributor

shockey commented Jan 13, 2018

Okay! I've fixed this specific case by adding a saner default for encoding array values: use toString instead of JSON.stringify.

However... the problem still remains that Swagger-Client isn't considering OAS3 encoding values (you're the first to mention it afaik!). I'll see if I can set aside some time to tackle that in the coming week(s).

@webron
Copy link
Contributor

webron commented Jul 11, 2018

Issue is fixed (:tada:), closing.

@webron webron closed this as completed Jul 11, 2018
@lock lock bot locked and limited conversation to collaborators Jul 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants