Endpoint that accepts either of two path parameters

27 views
Skip to first unread message

Joshua Hunter

unread,
Feb 23, 2015, 11:55:42 AM2/23/15
to swagger-sw...@googlegroups.com
I'm manually implementing Swagger (2.x) to be used with the Swagger-UI. I have an endpoint for resetting passwords that takes the form:

../users/{id}/password
-OR-
../users/{userName}/password

Other than treating these as separate endpoints in Swagger (which is what I've done so far), is there a way to model this duality? How can I say, it takes either x or y? The id is an integer, the username a string. The return response is the same in each case.

Thanks,
Joshua

Ron Ratovsky

unread,
Feb 23, 2015, 12:03:43 PM2/23/15
to swagger-sw...@googlegroups.com
In the pure sense, /users/{id}/password and /users/{userName}/password are identical, unless you define a regex that asserts uniqueness between the two.
I don't know what are your user name restrictions, but if someone can use "123456" as a user name (which is a string), and that's also a possible id, you have a problem because there's ambiguity.

So, you can either define those two as two endpoints, each having its own distinctive "pattern" (regex) to properly isolate the instances, or have a single endpoint with a "pattern" accepting either/or options.

Keep in mind that some tools, such as swagger-tools, may give you a warning that these two endpoints are identical.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------
Reply all
Reply to author
Forward
0 new messages