fastify / fastify/fastify-swagger

properties keyword inside oneOf keyword in query causes Fastify to crash

Open
#633 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
1.1k
Forks
219
Avg merge
4h 24m
Merged PRs (30d)
2

Description

### 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 ()\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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.