How to use $ref to reference a path from another OpenAPI file?

空扰寡人 提交于 2020-11-29 15:00:23

问题


Here it says I could refer to the definition in another file for an individual path, but the example seems to refer to a whole file, instead of a single path definition under the paths object. How to assign an individual path in another file's paths object?

For example, I have Anotherfile.yaml that contains the /a/b path:

paths:
  /a/b:
    post:

In another file, I use $ref to reference the /a/b path as follows:

paths:
  /c/d:
    $ref: 'Anotherfile.yaml#/paths/a/b'

but this gives an error:

Could not find paths/a/b in contents of ./Anotherfile.yaml


回答1:


When referencing paths, you need to escape the path name by replacing / with ~1, so that /a/b becomes ~1a~1b. Note that you escape just the path name and not the #/paths/ prefix.

$ref: 'Anotherfile.yaml#/paths/~1a~1b'


来源:https://stackoverflow.com/questions/58909124/how-to-use-ref-to-reference-a-path-from-another-openapi-file

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