-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Are these OpenAPI 3 paths ambiguous? #2564
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
In case it may help, I've tested a few openapi-based server frameworks (Nodejs express-openapi, Python fastapi, Java Vert.x, Java Micronaut) and all of them seem to consider that those paths are not ambiguous. You can find the code here: The code is including a test suite that is running manually crafted (successful) tests and openapi-based (failing) tests. To be honest, at this point I'm wondering where the OpenAPI specification is drawing (and should be drawing) the line between what is defined in the specification, and what is left to the implementations (server frameworks). Maybe it is too late for the OpenAPI specification to become clearer on the subject since implementations have started making decisions on what is ambiguous and what is not: I've picked 4 frameworks that are within my programming skills, but there maybe exist other frameworks considering those paths are ambiguous. |
I believe the spirit of the original wording was that constant path segments that align with templated path segments are not ambiguous. Updates to the wording around that to make it more clear would be a good thing. We haven't attempted to make the wording more precise to date because we have been looking at alternative ways to allow more ambiguity but provide tooling with a deterministic way of identifying the best path to match. This was part of the ongoing conversation about enabling multi segment parameters and optional path segments. Unfortunately that conversation stalled a bit around the topic of what are the highest priority items that we should be working on. The irony. |
@darrelmiller Thanks for your comment. I agree it is not easy to find a good wording. You will find below some thoughts about it. First it might be worth defining the notion of identical paths:
because it seems confusing (see #2356) and I admit I can only guess the meaning (I have a good guess but that's only a guess). I guess the algorithm is: function identicalPaths(oapth1, oapath2) {
const pathParamRegex = /\{[^}]+\}/
return oapth1.replaceAll(pathParamRegex, "{}") == oapth2.replaceAll(pathParamRegex, "{}")
} A definition could be:
An example could be:
Second it might be worth defining the notions of path, parent path and direct parent path. A definition of path could be (inspired from https://en.wikipedia.org/wiki/URL): A path is a sequence of path segments separated by a slash (/) and starting with a slash (/). Some examples could be:
A definition of parent path could be (inspired from https://en.wiktionary.org/wiki/subpath):
Some examples could be: Third (and last) it might be possible to rephrase this:
Into:
|
I'm not sure that any of these definitions of path, path segment etc are relevant. Path placeholders can appear anywhere, not just between slashes, so an OpenAPI implementation that parses a request URI and tries to match it against a list of path specifications (the properties under
But this I like! 💯 |
@karenetheridge Thanks for your comment!
I agree: I pressed the Comment button with a feeling I missed the principle of parsimony objective. However if what I described above (awkwardly but accurately, right?) is true (the authors of the specification have to decide that) I think we need to define two things:
Now I understand I forgot taking into consideration:
I didn't know the spec allowed case [2]: that's quite a wild thing :). Do you confirm it is the case? I'd be curious to know how many libraries implement that. The one I'm using (Eclipse Vertx) does not :). |
I don't think your case [2] is allowed -- "The value for these path parameters MUST NOT contain any unescaped “generic syntax” characters described by [RFC3986]: forward slashes (/), question marks (?), or hashes (#)." in https://spec.openapis.org/oas/v3.1.0#path-templating. But perhaps the authors meant to say "the names for these path parameters"? Value (as in, populated from the actual request URI) sounds more like it, because If "value" is correct here, this is convenient for writing a path-matching algorithm, for one can split the list of possible path specifications by (Although personally I've found that replacing each templated |
As suggested by @MikeRalphson on Stackoverflow, I'm asking the question here as well.
Are those OpenAPI 3 paths ambiguous?
I want to answer no but, strictly reading the spec, I can't decide because they seem to fall into none of the 3 statements made by the spec:
"/shops/{}/pets/{}" != "/shops/{}/pets/_search"
)In addition to the question asked on Stackoverflow, let me ask two additional questions (below).
Should the OA3 spec be improved?
@MikeRalphson's reading of the spec: path are not ambiguous because one is more concrete than the other.
If paths are indeed not ambiguous, then the more concrete notion might need to be defined.
How could the OA3 spec be improved?
We might add an example like this:
Or we might only show minimalistic examples involving templated names, and say that they also apply in case of common and identical prefixes:
First statement (concrete vs template case):
Second statement (considered identical and invalid):
Third statement is left unchanged (ambiguous resolution):
Related excerpt of the OA3 spec
The "Paths object" paragraph of the OpenAPI 3 specification (https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#paths-object) is stating (3 sentences, 3 statements):
Those 3 statements are followed by 3 examples (and that's it):
The text was updated successfully, but these errors were encountered: