-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Multiple Different Styles for Query Parameters #1508
Comments
Hi @dekryptic , Are you talking about passing the array values in the query parameter? Please refer https://tools.ietf.org/html/rfc3986#section-3.4 Thanks, |
As far as I understand that specification seems to only say that a query begins with a '?' and ends where the URI ends or at a '#' while the OAI spec is more specific. I basically want to know whether in tooling for the OpenAPI specification, should we allow for mixing of delimiters or enforce constraints when exploding parameters? e.g. mixing pipeDelimited and spaceDelimited. I don't think this is practically possible, so maybe this should be mentioned this in the docs? |
@dekryptic I don't believe the original example you presented is actually possible with the current spec defintion. The PipeDelimiter and SpaceDelimiter styles only refer to the separator between values, not the delimiter (prefix) between key=value pairs. Therefore, if you have id with style PipeDelimiter and q with style Form you would get,
The Pipe and Space just replace the comma that would be used with style=form. It is probably worth adding a note to the spec to explain that setting explode=true wouldn't cause the pipe character to be used as prefix to the key=name pair. |
What about what's mentioned in the Swagger Docs? i.e.
Can you provide an example of mixing |
I hadn't seen those docs. In my opinion that example is wrong. One of the goals of the changes that were made with OAS 3.0 was to try and make the parameter serialization align as closely as possible with RFC6570 without breaking backward compatibility. The Style concept encapsulates two different things from 6570, the separator and the prefix. Characters like the dot, semi-colon and slash are prefixes and commas are separators in 6570. The explode operator (which is concept taken directly from 6570) causes the prefix and key= to be repeated for each value. It isn't related to the separator. So, when you mix styles with different prefixes, the serialization is fairly straightforward. Consider the template: where you would get:
Now only a subset of 6570 is supported currently in OAS, so you can't actual represent the above template yet. However, the serialization rules should attempt to follow 6570 where possible. Note that the ? prefix is special in that the first value gets a ? and subsequent ones get an &. You can also use the & prefix where every value gets the & prefix. For Pipe and Space delimiting, it should play the same role a comma plays in 6570. i.e. it should separate values when they are not exploded. I see no value in introducing more capability that is incompatible with 6570. Ideally, I would like tooling folks to be able to use existing off the shelf 6570 libraries. I see no reason for us to have to reinvent URL construction code. |
Thank you for the detailed explanation. Is the example for
incorrect? Instead of |
@dekryptic Now that is a mistake in the spec example. You only get .blue.black.brown with explode = true. I will create a PR to fix the spec. I find this dictionary useful for remembering the behavior of the different operators. |
|
|
|
that produces this output:
How would this be deserialized? |
@dekryptic
|
This was fixed for v3.1.1; see also OAI/OpenAPI-Specification#1508 (comment)
As far as I can tell this conversation was resolved - I know the bug in the spec example was fixed in a PR. I'm going to close this, but if I mentioned something anyone should feel free to comment and I can re-open it (or just feel free to file a new issue with a clear request for a spec change, which may be more likely to get looked at). |
Is it possible to have multiple different styles for query parameters under the same path/operation? This mostly relates to explode. For example, would something like this make sense:
/users?id=3|id=4|id=5&q=1
The text was updated successfully, but these errors were encountered: