-
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 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, |
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: