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

Unable to render this definition The provided definition does not specify a valid version field. #195

Open
2 tasks done
Yacj opened this issue Dec 15, 2024 · 0 comments
Open
2 tasks done

Comments

@Yacj
Copy link

Yacj commented Dec 15, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.2.0

Plugin version

5.2.0

Node.js version

v22.11.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

win10

Description

When running the project and accessing the Swagger route, for example, http://127.0.0.1:3000/docs, the Swagger page reported this error.

Unable to render this definition
The provided definition does not specify a valid version field.

Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.x.y (for example, openapi: 3.1.0).

const path = require('node:path')
const AutoLoad = require('@fastify/autoload')
const cors = require('@fastify/cors')
const responseHandler = require('./middleware/resHandler.js')

const options= {}
module.exports = async function (fastify, opts) {
  await fastify.register(require('@fastify/swagger'),{
    openapi: {
      info: {
        title: 'Test swagger',
        description: 'Testing the Fastify swagger API',
        version: '0.1.0'
      },
      externalDocs: {
        url: 'https://swagger.io',
        description: 'Find more info here'
      }
    },
  })

 await fastify.register(require('@fastify/swagger-ui'), {
    routePrefix: '/docs',
    uiConfig: {
      docExpansion: 'full',
      deepLinking: false
    }
  })

  await responseHandler(fastify)
  fastify.register(cors, {
    origin: '*',
    methods: ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS']
  })

  fastify.register(AutoLoad, {
    dir: path.join(__dirname, 'plugins'),
    options: Object.assign({}, opts)
  })

  fastify.register(AutoLoad, {
    dir: path.join(__dirname, 'routes'),
    options: Object.assign({}, opts)
  })

  fastify.register(require('./plugins/env'))
}

module.exports.options = options

Link to code that reproduces the bug

No response

Expected Behavior

No response

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

No branches or pull requests

1 participant