-
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
Formally define (ABNF) 3.x URL templating behavior #3256
Comments
`Server.url` and `Link.operationRef` both allow variable substitution with {brackets}, which means they're not always valid URI references. For example, the [current specification][0] shows `https://{username}.gigantic-server.com:{port}/{basePath}` as a Server Object `url`, but it's not a valid URI reference because the host includes curly brackets. [`operationRef`][1] similarly includes `https://na2.gigantic-server.com/#/paths/~12.0~1repositories~1{username}/get` as an example that isn't valid using the `uri-reference` format. I looked into the other uses of `uri-reference` and they seemed ok. Related: - OAI#2586 - OAI#3235 - OAI#3256 - davishmcclurg/json_schemer#158 [0]: https://spec.openapis.org/oas/v3.1.0#server-object-example [1]: https://spec.openapis.org/oas/v3.1.0#operationref-examples
Issue #2119 brings up a lot of points relevant to this. |
@handrews I created a implementation with formal ANBF grammar in https://github.com/char0n/openapi-path-templating. I did a couple of assumption, because of the fact that the templating is not defined very precisely. Hope it helps a bit.
IMHO the restriction would be to now allow template expressions in URL query (searchParams) and URL fragment |
@char0n thank you! I don't know if we're going to get to this in the current patch releases or not (I'm unassigning it for onw as I have too many things in my backlog), but this will help when we do get there! |
@char0n I took a look at your ABNF- it looks like it restricts path template variables to whole segments. This issue got filed because in a discussion with TSC folks on slack, it was decided that template variables are not restricted to whole segments. You can have a template like |
@handrews I've created implementation with formal ABNF grammar for Server URL Templating in https://github.com/char0n/openapi-server-url-templating. It's distinct from https://github.com/char0n/openapi-path-templating, as the Server URL Templating is based on RFC 6570, but Path Templating is more based on RFC 3986. |
The grammar is not restricted to the whole segments: path-segment = 1*( path-literal / template-expression )
This path template [
[ 'path-template', '/foo{bar}/whatever' ],
[ 'path', '/foo{bar}/whatever' ],
[ 'slash', '/' ],
[ 'path-literal', 'foo' ],
[ 'template-expression', '{bar}' ],
[ 'template-expression-param-name', 'bar' ],
[ 'slash', '/' ],
[ 'path-literal', 'whatever' ]
] NOTE: there is a test that guarantee this works as expected in https://github.com/char0n/openapi-path-templating/blob/bea2682e889a6bc06da95596b303dcc77304402f/test/parse.js#L45 |
There is one un-clarity related to This also means that the path template will need to be defined as It's just another example how OpenAPI Path Templating differs from RFC 6570. @handrews taking into account the above, |
The key point here is that RFC is defining a way to represent template in OAS leveraging parameter with a type and a format allows munch more complex definition but the ambigious pattern policy is not fully defined, especially this one /pets/{petId} vs /pets/{name} mentioned as invalid ; where there is nothing defined toward type of format in the other hands some large framework has implemented that path templating can support either type , like in Python on Flask
or in Java where you URI are always considered as a string BUT allowing regular expression for matching
changing to the RFC 'like' meaning path as string with low format capability , could be seen as a breaking change , and would requires to a significant change in OAS spec to be precise (like not leveraging parameter object for instance) using the full OAS capability as defines here need just more sample about ambiguous path notice that if /a/{b} vs /a/c is declared as non ambigious , looks on URI evaluation to me /{b}/a and /a/{b} should be same level taking the same principle but applying segment per segment from left to right |
So is it safe to assume that name = varchar *( ["."] varchar )
varchar = ALPHA / DIGIT / "_" / pct-encoded My current implementation assume (probably incorrectly): name = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "=" |
here i do not want to open a pandora box , may be better to add a sample mentioning it @char0n , i am not even sure that is safe , as i am not sure of the support of the complexity of such pattern by most of framework {/list*,path:4} or i am wondering if this should not be limited to something simplistic (that still need to be defined) |
@char0n I don't think there's anything safe to assume here. I have no idea what tools do in such cases, and we do not place syntactic restrictions on our URL Template variables. I think it would be equally valid (based on the current text) to say you can use whatever name you want, but before you pass it to an RFC6570 library you need to encode it. That's essentially how the new Appendix C says to treat |
@OAI/tsc review request: Does anyone have the bandwidth to sort this out for 3.0.4 and 3.1.1? If not, let's change the milestone to 3.2.0. It does not seem to be something that is causing problems in practice and I need to focus more on Moonwalk now and don't have the time to research this. |
My naive interpretation of the current specification text:
Not sure what we could add here. |
Hey everyone, Like we've done in 3.1.1 I believe we're going to be able to make more progress here by scoping things out a bit more. Ideally (IMHO) we'd be leveraging RFC6570 URI templates as it improves reusability, and even unlocks scenarios like /foo/bar?query=baz accepts on schema for the POST request body and /foo/bar?query=baz&query2=zag another (arguably a bad design, but not even possible today). Working backwards from that, there are two confusions I often see in specifications:
I hope this helps. Happy to expand if I wasn't clear on some aspects here. |
@baywet This issue is just for describing the existing system with a formal ABNF, not for changing how it works. For improvements on what templates are ambiguous, there are several |
How to handle characters outside of the defnitely-OK range is addressed in Appendix C "Using RFC6570-based serialization" §C.4.4 Illegal variable names as parameter names. |
Thank you for the additional information.
To me, it's not obvious that OAS path template variable names MUST follow the naming pattern of variables in RFC 6570. Not only the appendix says "MAY", but also:
To be clear, I'm not debating what convention should the variable names follow, I'm simply trying to point out that discovering such convention in the current form of the document is difficult. |
Discussed in TDC and agreed that we can better signpost the existing content in Appendix C, and also make it clearer how flexible these sections are or could be. We discussed examples that include URLs like Next steps are for @baywet to put together some proposed changes and @handrews to review. |
@char0n thanks for starting such great work here! While reviewing those, I was wondering what lead you to the conclusion that Server URL templating supports RFC6570 since
Or maybe I missed something? |
@handrews I've added a bunch of test cases to the excellent work @char0n started here. This is meant to be a base for discussion, please have a look at it when you have a couple minutes. swaggerexpert/openapi-path-templating#145 |
From what I remember: Server URL templating doesn't refer to any RFC explicitly, I've inferred (from the information available within the OpenAPI spec) that the closest thing to this is subset of RFC 6570: URI Template. Because Server Variable can be substituted in any part of the URI, Hence - the Server URL templating uses ABNF non-terminals from RFC 6570: URI Template, and Path templating uses ABNF non-terminals from RFC3986 section 3.3. to parse literals around template expressions and server variables. Both openapi-path-templating and openapi-server-url-templating uses the same same value for the ABNF non-terminal describing what's allowed as the value between
Hope it clears things up a bit. |
Thank you for the additional information. The specification aspect of that brings so many questions:
I'd suggest that we focus on locking down path templating first, and come back to this one later to avoid loosing focus. Plus the answers from path templating should help us with server templating, and the relationship to one another. Thoughts? |
The tooling that I work on, resolve the server URL and path template separately and then concatenate them.
Because of above answer, this is a non issue.
AFAICT, from spec itself and how people use it, the variable can be wherever you want it to be. One of the more exotic usecase I've seen is
More are described here: https://swagger.io/docs/specification/v3_0/api-host-and-base-path/ |
`Server.url` and `Link.operationRef` both allow variable substitution with {brackets}, which means they're not always valid URI references. For example, the [current specification][0] shows `https://{username}.gigantic-server.com:{port}/{basePath}` as a Server Object `url`, but it's not a valid URI reference because the host includes curly brackets. [`operationRef`][1] similarly includes `https://na2.gigantic-server.com/#/paths/~12.0~1repositories~1{username}/get` as an example that isn't valid using the `uri-reference` format. I looked into the other uses of `uri-reference` and they seemed ok. Related: - OAI/OpenAPI-Specification#2586 - OAI/OpenAPI-Specification#3235 - OAI/OpenAPI-Specification#3256 - davishmcclurg/json_schemer#158 [0]: https://spec.openapis.org/oas/v3.1.0#server-object-example [1]: https://spec.openapis.org/oas/v3.1.0#operationref-examples (cherry picked from commit 5f765f29e3c12dcab370f5155fe21c6895a8ac5e)
From the TDC discussions: there's a preference to start a pull request from what we have today rather than tweaking the tests suite from the library. @baywet to put a pull request together for the path templates and we'll iterate from there. |
@handrews @mikekistler just put together #4244 as a starting point for discussion. Let me know what you think! |
As noted in Slack discussions, there is no formal specification for where variables can appear in server URL templates and path templates. There does not seem to be any reason to place restrictions on it.
Ideally, we could leverage the ABNF of RFC 6570 URI Templates even though OAS 3.x templating is not the same as RFC 6570 in general. (@darrelmiller @webron @MikeRalphson any concerns here?)
The text was updated successfully, but these errors were encountered: