-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: token "definitions" does not exist #524
Comments
Would you like to PR a fix? |
I can certainly have a go! |
Seems that use of definitions was not tested with #472. Adding the example schema from the Validation and Serialization page of the Fastify docs to the schema shows this a bit more clearly than my initial example: instance.addSchema({
$id: 'http://foo/common.json',
type: 'object',
definitions: {
foo: {
$id: '#address',
type: 'object',
properties: {
city: { type: 'string' }
}
}
}
}) Resulting OpenAPI spec generated: {
"def-0": { "type": "object", "title": "http://foo/common.json" },
"def-1": {
"type": "object",
"properties": { "city": { "type": "string" } },
"title": "#address"
}
} Expected result: {
"def-0": {
"type": "object",
"title": "http://foo/common.json",
"definitions": {
"foo": {
"type": "object",
"properties": { "city": { "type": "string" } },
"title": "#address"
}
}
}
} |
ouch. Could you revert the offending change or send a PR to fix it? |
I TIHNK i am running into this exact issue, hwoever im rather confused that this is still an issue considering there has been a major version release since this was raised? |
Wrote the wrong major version, have updated the original issue |
OK that makes much more sense as to why this is still a known issue |
This comment was marked as off-topic.
This comment was marked as off-topic.
As a workaround, use instance.addSchema({
$id: 'http://foo/common.json',
type: 'object',
properties: {
foo: {
title: 'address',
type: 'object',
properties: {
city: { type: 'string' },
},
},
},
}); Resulting OpenAPI spec generated: {
"def-0": {
"type": "object",
"title": "http://foo/common.json",
"properties": {
"foo": {
"type": "object",
"properties": { "city": { "type": "string" } },
"title": "address"
}
}
}
} Then in your routes, when referring just point to properties instead: {
"home": { "$ref": "http://foo/common.json#/properties/foo" }
} |
Love that there's a workaround. Any idea if the underlying issue with |
Prerequisites
Fastify version
3.25.3
Plugin version
4.12.1
Node.js version
16.13.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
10
Description
Upon upgrading from 4.12.0 to ^4.12.1,
components.schemas.def-0
is no longer populated with shared schemas/definitions.This is leading to
Invalid reference token: definitions
being thrown by Redoc, ortoken "definitions" does not exist
by other validators, when attempting to load the schema.Steps to Reproduce
This issue is present in Fdawgs/ydh-myydh-crud-api.
The shared schemas are held in a plugin.
4.12.0 example
In v4.12.0
components.schemas.def-0
looks like so:^4.12.1 example
When launching the API with any version of fastify-swagger ^4.12.1,
components.schemas
looks like so:As you can see above, it seems the definitions have moved outside of the original def-0 object.
The route schemas still refer to non-existent definitions at def-0:
Expected Behavior
$refs to refer to correct definitions, either by adding them back to def-0 or by referring to def-*
The text was updated successfully, but these errors were encountered: