swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
773 stars 526 forks source link

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

Open vfouqueron opened 6 months ago

vfouqueron commented 6 months ago
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