-
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
Optional path parameters #93
Comments
Hi, in the 2.0 spec, no we are not planning on supporting that. Does that syntax follow a framework or is that your custom design? |
Ok thank you for that information. It's a custom design, not a framework. |
@fabi-o, imho I recommend sticking with standards when designing your api. Is there anyway to change to params instead of path for those? If I was consuming your api, the use of :key=value would be confusing and I would much rather use ?key0=value&key1=value. |
closing as not supported in 2.0 |
I'm the author of #935 above. In our API we have several paths that end in some optional path segments, and are using There are quite a few libraries for RFC 6570 URL templates, so the implementation should not be much more work than picking one of those. Related API spec work like JSON schema hypermedia uses RFC 6570 as well. To me it seems that there are few downsides in adopting the full standard in Swagger 2.1. |
@webron, should this task be reopened so that it shows up in https://github.com/swagger-api/swagger-spec/labels/Swagger.Next%20Proposal? |
It does show up if you look at the opened and closed issues. Anything that's labeled I'll reiterate over whether to keep issues as opened or closed and why once I finish my current work on the spec (should be done in a few days), but rest assured that anything that's labeled with |
There's no possibility for optional route parameters? How would I generate a spec for just about every express.js app which has routes like |
@tjwebb - you won't, at least not with the current version. |
@fabi-o - if you'd use semicolon instead of colon, you'd be using completely standard matrix parameters ;-) |
Parent: #574 |
Net core web api supports optional path (route) parameters. I have routes like: /api/chapter/{storyId}/{chapterId?} where if the chapterId is not specified, the first chapter is returned (or all chapters are returned) I read somwhere that optional path parameters can't be a thing (due to resource resolution?)- I don't get it. It's a parameter, My implementation can decide if it's required or not, I don't see the need for the specification to dictate it as required always. Sugar: optional path parameters allow for nicer looking urls (also, other routing schemes work like this.) |
This feature is really necessary. A lot of frameworks allow optional path-parameters. This is a natural thing, not some hacky trick. So sadly currently I have to just leave everything as-is and say in |
Any chance this will be addressed? I agree with the prior two commenters, optional path parameters are a natural element of REST APIs, should be supported! |
@bryan5989 @Stalinko @dougbergh AFAIK this won't be supported due to this:
I'm not entirely sure on the non-deterministic argument and would love to understand it better, but in general I agree that we should avoid optional path parameters in APIs. I've landed in a few places that used them and it was a mess. I've never seen a case that couldn't be improved with query strings. Also, there are semantic problems with it to the point that new paths are either just new resources (therefore should be documented separately) or filters on the same resource (in which case query strings will do). If you really want it then maybe you should write a proposal that solves these problems. |
see my rebuttal: #622 (comment) @kurko there's not much to propose: make |
7 years and counting ... |
Was this issue even acknowledged during recent updates, or do devs just refuse to add optional path parameter support? I'm experimenting with generating API input validation based on openapi3 spec, which is currently impossible for optional parameter endpoints. |
And now it's nearly the end of 2021... |
all I have to say to this is wow... |
2 years later, I've realized that I misused the term resource in my final thought above (#622 (comment)). That said, I restate my point that an OAS pathspec does not determine whether you'll get a resource or something else (not a resource) at that path. That's for I the implementer to decide. Which is the whole point of documenting an API in the first place and the reason why OAS should allow me to decide whether a path segment is optional or not. Generator implementors can add switches to honor/ignore that preference. |
Optional path strings are not a part of the OpenAPI spec but have been a long-running request. OAI/OpenAPI-Specification#93 So we tell a small fib in the spec and say these paths are required, (because they *have* to be required in the spec) but then have a comment pointing out that /atom.xml etc are valid paths. Additionally we add some scripts to install an OpenAPI validator and to validate the two YAML documents. There is documentation for doing this with pre-commit but I couldn't get that to work.
i just end up creating a new path for each. couldnt find a workaround not sure if this would be solved tho with the above proposal. i got here cause i hate making 2 parameters (headers) for each item i want.. 1 is required the other not (when using $ref) which is totaly off topic to this thread i know. but im still looking... |
For OAS 4.0 (Moonwalk), we plan to use proper URI Templates, which allow path variable expansion. I believe that will address this use case. If not, please open a discussion in the Moonwalk repository. I don't think this could be done in 3.x even if we wanted to, due to compatibility and tooling support issues. Therefore I'll close this in favor of the existing Moonwalk proposal. |
Hello,
like described here (swagger-api/swagger-ui#380), path parameters are required and can't be optional.
I use optional path parameters in a REST API for filtering, sorting etc.
Example:
www.example.com/users
www.example.com/users:filter=active
www.example.com/users:sort=name
www.example.com/users:filter=active:sort=name
Are there any plans to allow optional parameters in the swagger specifications?
The text was updated successfully, but these errors were encountered: