fastify / fastify-swagger-ui

Serve Swagger-UI for Fastify
MIT License
137 stars 40 forks source link

docs: advice about @fastify/swagger version support in the README.md #120

Closed RodrigoDornelles closed 8 months ago

RodrigoDornelles commented 8 months ago

Prerequisites

Fastify version

4.25.2

Plugin version

2.1.0

Node.js version

20.1

Operating system

Linux

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

Linux 8a34e6999b2a 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 Linux

Description

FastifyError [Error]: The decorator 'swaggerCSP' has already been added!
    at decorate (/app/node_modules/fastify/lib/decorate.js:23:11)
    at Object.decorateFastify [as decorate] (/app/node_modules/fastify/lib/decorate.js:67:3)
    at fastifySwaggerUi (/app/node_modules/@fastify/swagger-ui/index.js:11:11) {
  code: 'FST_ERR_DEC_ALREADY_PRESENT',
  statusCode: 500
}

Steps to Reproduce

import fastify from 'fastify';
import fastifySwagger from '@fastify/swagger';
import fastifySwaggerUI from '@fastify/swagger-ui';

const app = fastify();

app.register(fastifySwagger)
app.register(fastifySwaggerUI, {
  routePrefix: '/docs',
});

app.get('/', async (request, reply) => {
  return { hello: 'world!' };
});

app.ready()

Expected Behavior

work without errors

Uzlopak commented 8 months ago

Maybe you use an old @fastify/swagger version. Can you provide a repo with an example project please?

RodrigoDornelles commented 8 months ago

That's right, it works with version 8 and there is a problem with version 7!

@Uzlopak a suggestion before closing my issue would be a friendly error message, if the lifecycle allows it.

Uzlopak commented 8 months ago

That error message comes from fastify core. Maybe the solution is to write that we this plugin needs atleast fastify swagger v. x

RodrigoDornelles commented 8 months ago

That error message comes from fastify core. Maybe the solution is to write that we this plugin needs atleast fastify swagger v. x

advice in the repository's README.md is perfect!

Uzlopak commented 8 months ago

Reopening as we did not solve this documentation issue, yet ;)