Using OpenAPI 3+ and Redoc, and having issues with references not working once I go more than one level deep, is there something i'm doing wrong or missing here?
openapi.yaml
components:
schemas:
$ref: components/schemas/_index.yaml
components/schemas/_index.yaml
AdminParticipants:
$ref: ./admin/Participants.yaml
admin:
$ref: "./admin/_index.yaml"
components/schemas/admin/_index.yaml
Participants:
$ref: ./Participants.yaml
When trying to access the schema model using below reference it does not work (get Invalid reference token: Participants error)
$ref: "#/components/schemas/admin/Participants"
However this does work:
$ref: "#/components/schemas/AdminParticipants"
Is it not possible to create nested references more than one level deep for schemas or any other components?
OpenAPI does not actually support
$refdirectly under thecomponents.schemasnode. You can only$refindividual schemas or schema properties. Some tools might accept $refs in arbitrary places, but the behavior may vary.Here's the version that will work with any OpenAPI-compliant tools:
You'll can then reference these schemas as:
The following will NOT work - not only because of non-standard
$refplacement inopenapi.yaml, but also because it would result in a wrong structure of theschemassection.After dereferencing, the snippets above become:
which has an extra key between the schema name and schema contents, so it's not valid OpenAPI.