Endpoint that accepts either of two path parameters

已查看 27 次
跳至第一个未读帖子

Joshua Hunter

未读,
2015年2月23日 11:55:422015/2/23
收件人 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

未读,
2015年2月23日 12:03:432015/2/23
收件人 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
-----------------------------------------
回复全部
回复作者
转发
0 个新帖子