3

I've been a fan of ExpressJs for a long time but in a Youtube video I stumble upon Fastify and wanted to give it a try

I'm struggling in making the fastify-swagger plugin work as I assume it should work - dynamic setup to pick up the schema from each route, but I'm certainly missing something

here's my test repo that after running, none of my routes appear

my setup for the plugin is the default one

but all I see is

enter image description here

I've read in the read me that because of OpenAPI specs, some properties, like description are mandatory or will not pick up the route, but I've added in one route, and still does not pick up, I've also added tags wondering if that was also mandatory, but nothing...

does anyone know what am I missing? must be a simple thing, but got me puzzled this last few days

balexandre
  • 73,608
  • 45
  • 233
  • 342

3 Answers3

4

I ran into the same issue and ended up solving it by following the first Usage example line-by-line: https://github.com/fastify/fastify-swagger#usage

const fastify = require('fastify')()

(async () => {
  // set up swagger
  await fastify.register(require('@fastify/swagger'), {
    ...swagger config
  });

  // define all your routes

  // then call these
  await fastify.ready()
  fastify.swagger()
})();
Jazzy
  • 6,029
  • 11
  • 50
  • 74
2

Consider the order in which your plugins are loaded, the routes need to be registered before fastify swagger. If fastify swagger comes first, it doesn't detect any route.

Damilola
  • 191
  • 1
  • 9
0

I encountered this issue in my project. In my case, I solved it using fastify-plugin. Looking at the source code for fastify-swagger, it seems to rely on a hook listening for onRoute events to detect routes. I'm thinking maybe encapsulation can interfere with the plugin's ability to receive the events.

plumbn
  • 115
  • 2
  • 9