You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have multiple OpenAPI 3.0 API:s using some common types, such as some common schema types and common error responses. The responses also reference common schemas.
openapi: 3.0.2
components:
schemas:
# Import common schemas (including the ones used by common responses)
<< : {$ref: 'common.yml#/components/schemas'}
# Define local schemas
Foo:
type: string
responses:
# Import common responses (using common schemas)
<< : {$ref: 'common.yml#/components/responses'}
# Define local responses
FooResponse:
description: OK
content:
application/json:
schema: {$ref: '#/components/schemas/Foo'} # This fails unless schemas/Foo is defined in common.yml
paths:
/foo:
get:
summary: Foo
responses:
200: {$ref: '#/components/responses/FooResponse'}
400: {$ref: '#/components/responses/SomeErrorResponse'}
Most of this works:
Schemas are imported fine and merged with the local schemas. Paths can use both common and local schemas
Responses are also imported and merged.
However, even though #/components/schemas/Foo is now resolved fine from e.g. paths when calling dereference() the local response FooResponse fails to resolve the local schema #/components/schemas/Foo, because it attempts to look it up in common.yml#/components/schemas/Foo:
It seems that after an import using << :, all references to #/ within the same section (e.g. responses) will refer to that imported document, rather than the current document into which the imported document has been merged.
The effect of this is that I cannot define any local responses using local schemas. Obviously I don't want to pollute my common files with local schemas used for one particular API. I also want to avoid manually copy&paste of all common schemas and responses into every single API.
Is my document structure and the way I use imports incorrect per the specification or is there a bug in json-schema-ref-parser when it comes to resolving # references from a section which has used a << : merge directive?
The text was updated successfully, but these errors were encountered:
I have multiple OpenAPI 3.0 API:s using some common types, such as some common schema types and common error responses. The responses also reference common schemas.
A simple example setup:
common.yml:
api.yml:
Most of this works:
However, even though
#/components/schemas/Foo
is now resolved fine from e.g.paths
when callingdereference()
the local responseFooResponse
fails to resolve the local schema#/components/schemas/Foo
, because it attempts to look it up incommon.yml#/components/schemas/Foo
:SyntaxError: Error resolving $ref pointer "/<path>/common.yml#/components/schemas/Foo
It seems that after an import using
<< :
, all references to#/
within the same section (e.g.responses
) will refer to that imported document, rather than the current document into which the imported document has been merged.The effect of this is that I cannot define any local responses using local schemas. Obviously I don't want to pollute my common files with local schemas used for one particular API. I also want to avoid manually copy&paste of all common schemas and responses into every single API.
Is my document structure and the way I use imports incorrect per the specification or is there a bug in json-schema-ref-parser when it comes to resolving
#
references from a section which has used a<< :
merge directive?The text was updated successfully, but these errors were encountered: