-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Support for semantic path templating #576
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
Can you share more details on the actual parameters? As @fehguy mentioned on SO they are identical path-wise, and without the details on the parameters it's unclear how you differentiate them. It could be different type for the path parameter, but it could be that you depend on other parameters. |
For example a I don't have the code with me ATM, I'll post it later. |
But both of them have a |
Here is the code. I removed the descriptions to make it a bit shorter.
I want to view a request to /path/to/id as something like edge --> edge --> node (or branch --> branch --> leaf). If the last part of the URI is a node (i.e. a Member in Atom's case) it's a From @fehguy 's answer on SO I figure this is not (easily?) doable? |
Unfortunately, this doesn't explain how to differentiate the two "different" paths that are semantically the same. (They are semantically the same because they describe a path with a single path segment that itself is a variable.) There has to be something in the path definition that makes that definition unique and your two path definitions do not do that. If you run that through So without something concrete in your path definition, it will be impossible for any smart validator to differentiate between the path patterns because the are semantically the same. (Feel free to |
So you have an API with a a URI that is identical for two different operations (all the parameter definitions are identical as well including header, path and query parameters), and based on the path parameter the client will get one of two results but the client has no real way of knowing that when calling the API? |
Unfortunately this is supported in different server frameworks by routing the request based on regexes on the path parameters. I am not saying we should support it but it is somewhat common. Declaring the regex in the path parameter in the path makes this more tolerable but you still have to deal with the order of the routing, etc |
I know there is regex support in routers and such but the blanket "This API matches anything after the slash" just isn't very beneficial. And while you could assume that this is backed by some regex matching router, which could very well be the case since that is a common feature in routers, even then there is a chance that there is more of a pattern that could be put into the path definition than what is there now. |
But @trilean never mentioned that the path parameter is differentiated by a regex. Who says a given 'name' can't be used for both a member and a collection? He could just be checking it in the BE, checking out one and falling back to the other if it doesn't exist. |
That's why I said "while you could assume this is backed by some regex". ;) But yes, you're right that this could a the case where the only one differentiating this is on the backend. |
But I was replying to @fehguy. Not everything is about you, @whitlockjc. |
Blame the async responses @webron, not my theorized ego. |
Mommy and daddy are fighting again. |
👍 |
Thank you for your answers! Sorry for not having been more specific on this. It seems we're talking about two somewhat seperate issues here:
Actually I want to use a graph but it's easier to imagine with trees. Also, there is no fixed number of path segments (depth of the tree). Can wildcards handle this?
To me that feels like a workaround. It's 2016 and I really really want my URIs to represent my data and not some implementation details / issues.
Exactly. |
In that case, this is pretty much a duplicate of #291. |
What about 2016 means URIs can't have meaningful, differentiating details in them? I know when I design my APIs, it's very clear to tell what resource is being interacted with using a simple name, like |
At the end of the day it shouldn't matter which 'style' you prefer. IMO the fact that Swagger doesn't allow me to specify what I want to is a limitation. I would welcome it if you considered this in the next version. Nevertheless thank you for your time and answers! |
Thanks, I'm kinda new to this. Reopened for better visibility when looking through those requests 😉 |
I believe I understand what @trilean is trying to do, because I've tried to do something similar myself. I was able to express what I wanted using some 'x-' extensions, but of course that is not satisfactory, because no-one but me understands them. Here is an explanation of the problem and what I did to get around it. OpenAPI lets you say something like: paths:
/widget/{widget-id}:
parameters:
- name: widget-id
...
get:
...
put:
... If you like doing hypermedia, you really want to split this information into two parts:
The reason you want this separation is that there may be widgets at other URLs, not just at URLs of the form x-interfaces:
Widget: &Widget
get:
...
put:
...
paths:
/widget/{widget-id}:
parameters:
- name: widget-id
...
<<: *Widget This use of the YAML merge operator allows you to separate the interface implemented by all widgets from a path that describes specific URLs for some of them. Correctly-written OpenAPI tools will still correctly interpret these paths. I believe that @trilean may have been trying to express the same idea as my 'interface' concept when he wrote: paths:
/{CollectionURI}:
get: Once you have separated out an interface in this way, you can reference it in the definition of a hyperlink. The simplest form of hyperlink might look like this: definitions:
Doohickey:
properties:
widget:
description: hyperlink to a Widget
format: uri
type: string
x-interface:
$ref: '#/x-interfaces/Widget' If you are one of those folks who likes to represent your hyperlinks XML-style, nested under a 'links' property, it's a bit more complex, but not too much. You might challenge the desirability of the x-interface extension. It is fairly common to have APIs where more than one type of resource can be referenced by a hyperlink. In that case you are going to have to retrieve the resource and examine its type to see what you can do with it, in which case the x-interface value isn't really helping. And since it doesn't help in all cases, maybe its better not to have it at all. In summary, by inventing 'x-interfaces' and 'x-interface' I was able to express what I wanted in a way that allows OpenAPI tools to still understand my paths, while expressing the extra information I needed for hypermedia. The limitation is that my x- extensions are currently known only to me. Another limitation is that the YAML merge operator doesn't understand URLs, so you can't reference interfaces in other documents. Apologies to @trilean if this is not in fact what he meant. |
I might add that I had to invent a third x- extension that is closer to the example shown by @trilean. Extending the example above, consider these OpenAPI paths: paths:
/doohickies/{doohickey-id}:
...
/doohickies/{doohickey-id}/widget:
... What this tells you is that, if you have a Doohickey URL of the form x-templates:
{Doohickey}/widget:
$ref: '#/x-interfaces/Widget' There is no |
@mpnally, thank you for your comment. I think this is the closest I can come with Swagger to what I want to write down, though I'm not quite sure I understood everything you meant. Let me try and implement your suggestions with my spec -- I'll post back here if there are any issues 😉 |
Parent issue #574 |
I definitely would like to see this work. My example is something like this that I run into; /team/{id}/people/{modified}: Those are two very distinct paths, differentiated by the type of call (GET vs. DELETE) but that last parameter name is a distinctly different argument type. |
See #804 |
Still seems to be a problem in 2022... Servers can route different data types very nicely, |
Hi,
I recently ran into the following issue: I have two different types of URIs which support different requests (verbs) and return different values. I tried to write them down as:
...which does show up fine in Swagger-UI but is not officially supported. Swagger-Editor doesn't like it and shows an error.
I asked that question on SO: https://stackoverflow.com/questions/35478531/swagger-equivalent-path-already-exists-despite-different-parameters
Please add support for this kind of path templating in the next version.
Thanks!
The text was updated successfully, but these errors were encountered: