问题
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