fastify-swagger
fastify-swagger copied to clipboard
properties keyword inside oneOf keyword in query causes Fastify to crash
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.2.1
Plugin version
7.4.1
Node.js version
16.14.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
20.04.3
Description
properties keyword inside oneOf keyword in query causes Fastify to crash
TypeError: Cannot read properties of undefined (reading 'split')\n
at resolveLocalRef (/home/ubuntu/bo-user/.yarn/cache/@fastify-swagger-npm-7.4.1-1ef61e1d46-b69fc1990d.zip/node_modules/@fastify/swagger/lib/util/common.js:190:36)\n
at /home/ubuntu/bo-user/.yarn/cache/@fastify-swagger-npm-7.4.1-1ef61e1d46-b69fc1990d.zip/node_modules/@fastify/swagger/lib/util/common.js:184:20\n
at Array.reduce (<anonymous>)\n
at resolveLocalRef (/home/ubuntu/bo-user/.yarn/cache/@fastify-swagger-npm-7.4.1-1ef61e1d46-b69fc1990d.zip/node_modules/@fastify/swagger/lib/util/common.js:183:20)\n
at plainJsonObjectToOpenapi3 (/home/ubuntu/bo-user/.yarn/cache/@fastify-swagger-npm-7.4.1-1ef61e1d46-b69fc1990d.zip/node_modules/@fastify/swagger/lib/spec/openapi/utils.js:133:41)\n
at resolveCommonParams (/home/ubuntu/bo-user/.yarn/cache/@fastify-swagger-npm-7.4.1-1ef61e1d46-b69fc1990d.zip/node_modules/@fastify/swagger/lib/spec/openapi/utils.js:273:15)\n
at prepareOpenapiMethod (/home/ubuntu/bo-user/.yarn/cache/@fastify-swagger-npm-7.4.1-1ef61e1d46-b69fc1990d.zip/node_modules/@fastify/swagger/lib/spec/openapi/utils.js:375:29)\n
at Object.swagger (/home/ubuntu/bo-user/.yarn/cache/@fastify-swagger-npm-7.4.1-1ef61e1d46-b69fc1990d.zip/node_modules/@fastify/swagger/lib/spec/openapi/index.js:46:29)\n
at /home/ubuntu/bo-user/src/utils/generateDocs.js:63:30\n
at processTicksAndRejections (node:internal/process/task_queues:96:5)"},"msg":"Cannot read properties of undefined (reading 'split')"}
Steps to Reproduce
const fastify = require('fastify')()
;(async () => {
await fastify.register(require('@fastify/swagger'), {
exposeRoute: true,
routePrefix: '/docs',
openapi: {
info: { title: 'Test OpenAPI', version: '1.0.0' }
}
})
fastify.get('/test-route', {
schema: {
query: {
type: 'object',
oneOf: [
{
properties: {
bar: { type: 'number' }
}
},
{
properties: {
foo: { type: 'string' }
}
}
]
},
response: {
200: {
type: 'object',
properties: {
result: { type: 'string' }
}
}
}
}
}, (req, reply) => ({ result: 'OK' }))
await fastify.ready()
fastify.swagger()
})()
Expected Behavior
No error expected
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.