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 should support key[]=value #442

Closed
Algiras opened this issue Aug 15, 2015 · 8 comments
Closed

collectionFormat should support key[]=value #442

Algiras opened this issue Aug 15, 2015 · 8 comments

Comments

@Algiras
Copy link

Algiras commented Aug 15, 2015

Regarding joi not integrating delimeters hapijs/joi#570 and https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md not supporting key[]=value. I would like to suggest adding this so it would be easy to use swagger-ui in more platforms that predefined key[]=value for array values. Currently I am using https://github.com/z0mt3c/hapi-swaggered. Hope you guys can help. If needed I can update the code myself. It's just adding one more way of parsing and adding more tests.

@webron
Copy link
Member

webron commented Aug 15, 2015

It supports it already. Just give the parameter the name key[].

@Algiras
Copy link
Author

Algiras commented Aug 15, 2015

The ui when generated with:

{
"required": false,
"collectionFormat": "multi",
"type": "array",
"items": {
"type": "string"
},
"name": "categories",
"in": "query"
}

generates request that sends

?categories=word&categories=otherWord

What I need is

?categories[]=word&categories[]=otherWord

@webron
Copy link
Member

webron commented Aug 16, 2015

Right, so the generated name should be categories[] and not categories That's a problem with whatever is producing your definition, not the spec itself.

@Algiras
Copy link
Author

Algiras commented Aug 16, 2015

I can make the tool generate name categories[]:

{
"required": false,
"collectionFormat": "multi",
"type": "array",
"items": {
"type": "string"
},
"name": "categories[]",
"in": "query"
}

the problem is that swagger-ui then encodes [] to categories%5B%5D.

Another big problem is semantics:

  • when using no []
    • ?categories=word&categories=otherWord -> array of categories
    • ?categories=word -> single category as string(or predefined type)
  • when using []
    • ?categories[]=word&categories[]=otherWord -> array of categories
    • ?categories[]=word -> array of categories with single value

Problem is swagger-ui can't differentiate, because it doesn't see the differences.

@webron
Copy link
Member

webron commented Aug 16, 2015

As far as the ui encoding the square brackets, just open an issue on swagger-ui.

As for the difference in semantics, that's a tooling issue. We can't accommodate for every single variation a tool out there decides to use. Whether a single value, or an array of a single value, in most cases (I'm sure there are edge cases), those should mean the same thing (especially to an API consumer). Therefore, the ui doesn't need to differentiate as the meaning is pretty much the same.

@Algiras
Copy link
Author

Algiras commented Aug 16, 2015

To create an issue I need to differentiate between parameters that can be either string or array via spec. Otherwise I have no ground rule for ui to differentiate.

@webron
Copy link
Member

webron commented Aug 16, 2015

As long as you define the name as categories[] it should be sent as categories[] and not as categories%5B%5D. That has nothing to do with differentiating the logic. Other than that, I don't think there's anything to do with this issue as it is supported by the spec.

@jharmn
Copy link
Contributor

jharmn commented Feb 12, 2016

Seems like there's quite a bit of overlap in #380, closing this we can carry on there. Please add any refinements you feel may have been missed.

@jharmn jharmn closed this as completed Feb 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants