swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

$ref using '{' and '}' characters are creating wrong path to resolve Headers

Open vfouqueron opened this issue 2 years ago • 0 comments

openapi: 3.0.3
info:
  title: My Title
  description: Mydescription
  version: 0.0.1
paths:
  /nodes/{uuid}/rights:
    $ref: "traceability/nodes.yaml#/paths/~1nodes~1{uuid}~1rights"
openapi: 3.0.3
info:
  title: nodes.yaml
  version: 0.0.1
paths:
   /nodes/{uuid}/rights:
    get:
      operationId: listNodeRights
      tags:
        - Nodes

      responses:
        206:
          description: Partial
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "../rights.yaml#/components/schemas/NodeRightDto"
          headers:
            Content-Range:
              $ref: "../common-spec-openapi.yaml#/components/headers/Content-Range"
openapi: 3.0.3
info:
  title: common-spec-openapi.yaml
  version: 0.0.1
components:
  headers:
    Content-Range:
      schema:
        pattern: \d+-\d+\/\d+
        type: string
paths: {}

When in ExternalRefProcessor, in method processRefHeader, we call the join function. This function calls a new URI with "traceability/nodes.yaml#/paths/~1nodes~1{uuid}~1rights", the URI method throws an Exception as { is an invalid URI character, resulting into being caught and returning the source value, "traceability/nodes.yaml#/paths/~1nodes~1{uuid}~1rights" instead of ./common-spec-openapi.yaml#/components/headers/Content-Range

vfouqueron avatar Jan 05 '24 17:01 vfouqueron