Example 2 - Escaping paths example
This example shows how the value of the $xref key can contain multiple # characters.
Each time the # character appears, it toggles between / characters representing paths in the JSON-Pointer reference, and literal / characters appearing in the JSON-Pointer key
(This example is identical to Example 1 but uses additional '#' characters in the $xref value)
Input
input.yaml
paths: /thing: get: # hashes in the path toggle between '/'-as-JSON-Pointer separators # and '/' as characters in the key $xref: 'paths.yaml#/paths/#/thing#/get' post: $xref: 'paths-v2.yaml#/paths/#/thing#/post'
paths.yaml
paths: /thing: get: operationId: getThings description: get all the things parameters: responses: 200: schema: type: object title: getThingsOKResponse properties: status: description: OK type: string thing: type: array items: $ref: 'objects.yaml#/definitions/ThingObject'
paths-v2.yaml
paths: /thing: post: operationId: addThing description: | Adds a new `Thing`. * Things must be uniquely identifiable by `name`. * The `id` of the thing must be empty; the newly created `id` will be returned in the response object. parameters: thing: $ref: 'objects.yaml#/definitions/ThingObject' responses: 200: schema: type: object title: getThingsOKResponse properties: status: description: OK type: string thing: type: array items: $ref: 'objects.yaml#/definitions/ThingObject'
Output
--- paths: /thing: post: operationId: addThing description: | Adds a new `Thing`. * Things must be uniquely identifiable by `name`. * The `id` of the thing must be empty; the newly created `id` will be returned in the response object. responses: 200: null schema: type: object title: getThingsOKResponse properties: thing: type: array items: $ref: objects.yaml#/definitions/ThingObject status: type: string description: OK parameters: thing: $ref: objects.yaml#/definitions/ThingObject get: operationId: getThings description: get all the things responses: 200: null schema: type: object title: getThingsOKResponse properties: thing: type: array items: $ref: objects.yaml#/definitions/ThingObject status: type: string description: OK parameters: null