kin-openapi
kin-openapi copied to clipboard
External reference is invalid when it appears in object properties
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.
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
It seems that #478 will resolve this issue.