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

Default value for collectionFormat field is csv. Should be multi. #1160

Closed
pedrombl opened this issue Jun 11, 2015 · 13 comments
Closed

Default value for collectionFormat field is csv. Should be multi. #1160

pedrombl opened this issue Jun 11, 2015 · 13 comments
Labels
Milestone

Comments

@pedrombl
Copy link

Currently the default value in the field collectionFormat is csv. However the default way of passing a list of parameters is multi (foo=bar&foo=baz). Talking with ron, who_ and jeremyw in #swagger/freenode this was identified as a bug.

Here is the part of the code that does that ->

@webron webron added this to the v1.5.1 milestone Jun 11, 2015
@webron
Copy link
Contributor

webron commented Jun 17, 2015

For the sake of documentation, the format is csv because of the intent in 1.3.X and we tried to keep it backwards compatible. However, since it really doesn't make sense and breaks the API documentation then it definitely needs to be multi. I believe this makes allowMultiple obsolete, but for now it should probably also give a multi value.

@webron
Copy link
Contributor

webron commented Jul 14, 2015

Fixed in develop_2.0.

@webron webron closed this as completed Jul 14, 2015
@Armanda888
Copy link

Can I set collectionFormat to be csv for query parameter? as my rest api is like foo=bar, baz

@fehguy
Copy link
Contributor

fehguy commented Jul 21, 2016

yes you can

@Armanda888
Copy link

@fehguy how do I set it? in the annotation ApiParam?

@Armanda888
Copy link

by checking https://github.com/kongchen/swagger-maven-plugin/blob/master/src/main/java/com/github/kongchen/swagger/docgen/reader/AbstractReader.java, Line 417, it sets collectionFormat to multi for query param.
Here is my query parameter:
ApiParam(name = "include", allowableValues = "a, b", allowMultiple = true, required = false)
@QueryParam("include") String include,
in the swagger.json, it's like this:
{
"name" : "include",
"in" : "query",
"required" : false,
"type" : "array",
"items" : {
"type" : "string",
"default" : "csv",
"enum" : [ "a", "b" ]
},
"collectionFormat" : "multi"
}

@gkozyryatskyy
Copy link

@Armanda888 do you solve your question? have the same problem after update.
There is a support of collectionFormat now available in annotations #1180, but seems swagger plugin do not use it.

@gkozyryatskyy
Copy link

@fehguy can you please show how we can set collectionFormat to csv through annotations + swagger plugin?

@fehguy
Copy link
Contributor

fehguy commented Feb 8, 2017

@gkozyryatskyy what swagger plugin are you referring to? If this is springfox, then it's a separate project that may not support the latest annotations.

@fehguy
Copy link
Contributor

fehguy commented Feb 8, 2017

OK looks like we need to open a ticket in that project.

@gkozyryatskyy
Copy link

@apiwoni
Copy link

apiwoni commented Sep 19, 2019

@gkozyryatskyy @fehguy This issue has nothing to do with swagger-maven-plugin but more with ParameterProcessor in swagger-core 1.5.x. Currently setting collectionFormat to csv via annotation is ignored when producing swagger json spec because io.swagger.models.parameters.AbstractSerializableParameter#setType resets collectionFormat to null after it has been set to "csv" anytime type is not array.

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

No branches or pull requests

7 participants