Swagger 2.0: Multiple Path objects with different paths but same request and response

家住魔仙堡 提交于 2019-11-29 14:21:10

Yes, you can have a path item reference another path item, like this:

paths:
  /ab:
    ...
  /a-b:
    $ref: '#/paths/~1ab'

Here, ~1ab is an escaped version of /ab.

In JSON pointers, there are two special characters that need to be escaped to be interpreted literally: ~ becomes ~0 and / becomes ~1:

  • /ab~1ab$ref: '#/paths/~1ab'
  • /foo/bar~1foo~1bar$ref: '#/paths/~1foo~1bar'
  • /ab~cd~1ab~0cd#/paths/~1ab~0cd
  • /ab/{c}/{d}~1ab~1{c}~1{d}#/paths/~1ab~1{c}~1{d}


One limitation of this approach is that you cannot have operationId in all operations of the referenced path item. This is because the copy of the path ends up with the same operationId values, but operationId must be unique.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!