-
Notifications
You must be signed in to change notification settings - Fork 9.1k
3.1 Request - allowReserved in path #1840
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
Comments
It is specifically disallowed on path parameters for the same reason we don't allow optional path parameters, e.g. {/foo} By having variable path segments it become difficult to resolve a URL to an operation. There can be a situation where an URL might map to many operations. We are considering introducing a priority property to help routing tools determine which operation to match. This is a conversation that will likely come up in one of our TSC meetings in the next few weeks. |
Any updates? |
Note: There is a lot of relevant prior art here. RFC 6570: URI Template Section 1.2 defines levels for template capabilities. Level 1 is very basic.
An example:
The Github REST API is a notable example of an API that uses this capability for accessing files in repositories. The Hypermedia section of their REST API documentation references RFC 6570. Here it is in action in an excerpt from one of their API responses: That RFC is of course intended for URI expansion, not matching. But Github must have implemented matching internally. My server background is primarily in Java, so I’ll speak briefly to that ecosystem. I’m confident that my observations generalize to libraries and frameworks in other languages. The two most popular ways to define REST APIs in Java, I think, are using 1) JAX-RS annotations or 2) Spring Web MVC annotations. JAX-RS 2.1 supports matching multiple path segments per path variable using a regular expression such as this example from Section 3.4 URI Template of the spec:
Section 3.7 Matching Requests to Resource Methods details the somewhat technical but logical matching algorithm used to avoid the need for API authors to manually prioritize API operations. JAX-RS 2.1 has many implementations, including ones by Oracle, IBM, Google, and the Apache Foundation. Spring Web MVC and Spring Web Flux (the newer async alternative to Web MVC) support I hope this capability can make it into OpenAPI specifications. Limiting the capability to the end of a path would probably be much easier to achieve and would suffice for >90% of use cases, I imagine. |
any updates on this? |
Any updates on this? |
This has been rolled up into #2653, which in turn will almost certainly be moved over to the Moonwalk (OAS 4) project, which as currently proposed supports full RFC 6570 URI Templates. |
I have a use case where I have some type of "file system", the api works the following way:
/api/user/{id}/{+path_to_file}
where path_to_file is the actual path to the file.
The problem is that there is no current way to describe this with OpenAPI 3.0.
There is an option called
allowReserved
that would allow this but only work on query parameters. Why limit the option?It is easy to see how it would work for the last path parameter, but I think it could work for any of them, it would match any character until the path matches the next part of the template.
The text was updated successfully, but these errors were encountered: