kin-openapi icon indicating copy to clipboard operation
kin-openapi copied to clipboard

External reference is invalid when it appears in object properties

Open lusingander opened this issue 3 years ago • 2 comments

Error occurs while loading spec file when references internal object definitions(defined in same file), and references external schema definitions in its properties.

some/dir/openapi.yml

openapi: 3.0.0
info:
  title: 'spec'
  version: 1.2.3

paths:
  /foo:
    get:
      summary: get foo
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Foo"

components:
  schemas:
    Foo:
      type: object
      properties:
        id:
          $ref: "./common/foo.yml"

some/dir/common/foo.yml

type: string

In this case, following errors occurs:

open some/common/foo.yml: no such file or directory

It seems that file paths is joined incorrectly.

lusingander avatar Feb 28 '22 23:02 lusingander

In the following patterns, everything works correctly.

paths:
  /foo:
    get:
      summary: get foo
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    $ref: "./common/foo.yml"
paths:
  /foo:
    get:
      summary: get foo
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Foo"

components:
  schemas:
    Foo:
      $ref: "./common/foo.yml"
paths:
  /foo:
    get:
      summary: get foo
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Foo"

components:
  schemas:
    Foo:
      type: object
      properties:
        id:
          $ref: "#/components/schemas/Bar"
    Bar:
      type: string

lusingander avatar Feb 28 '22 23:02 lusingander

It seems that #478 will resolve this issue.

lusingander avatar Feb 28 '22 23:02 lusingander