Prerequisites
Fastify version
5
Plugin version
5.1.0
Node.js version
22
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
latest
Description
I see an error TypeError: Cannot read properties of undefined (reading 'Success') at resolveSchemaReference (.../node_modules/@fastify/swagger/lib/util/resolve-schema-reference.js:13:39)
The error occurs because https://github.com/fastify/fastify-swagger/blob/master/lib/util/resolve-schema-reference.js#L7 which assumes that a $ref will have format '#/definitions/SchemaName'.
But all my $refs are '#/components/schemas/SchemaName', so this line always fails with the above error. I could not see how to register '#/definitions'
May I suggest the following change?
// const schemaId = resolvedReference?.$ref?.split('/', 3)[2]
if (!resolvedReference) return undefined;
const $ref = resolvedReference.$ref;
const schemaId = $ref.startsWith('#/components') ? $ref.split('/', 3)[3] : $ref.split('/', 3)[2]
which fixes the problem for me. It may also fix #799
Expected Behavior
No error when rendering openapi 3 with zod and a custom transformer
Prerequisites
Fastify version
5
Plugin version
5.1.0
Node.js version
22
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
latest
Description
I see an error TypeError: Cannot read properties of undefined (reading 'Success') at resolveSchemaReference (.../node_modules/@fastify/swagger/lib/util/resolve-schema-reference.js:13:39)
The error occurs because https://github.com/fastify/fastify-swagger/blob/master/lib/util/resolve-schema-reference.js#L7 which assumes that a $ref will have format '#/definitions/SchemaName'.
But all my $refs are '#/components/schemas/SchemaName', so this line always fails with the above error. I could not see how to register '#/definitions'
May I suggest the following change?
which fixes the problem for me. It may also fix #799
Expected Behavior
No error when rendering openapi 3 with zod and a custom transformer