Skip to content
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

properties keyword inside oneOf keyword in query causes Fastify to crash #633

Open
2 tasks done
varuna-aample opened this issue Jul 12, 2022 · 1 comment
Open
2 tasks done
Labels
bug Confirmed bug

Comments

@varuna-aample
Copy link

Prerequisites

  • I have written a descriptive issue title
  • 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

@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

2 participants