fastify-resty icon indicating copy to clipboard operation
fastify-resty copied to clipboard

Question - How to generate docs?

Open IrvingArmenta opened this issue 4 years ago • 1 comments

I'm thinking in using this as my backend, but I need a way to generate documentation, swagger/open-api should be fine.

I tried using fastify-swagger but It didn't work as expected, is there some kind of integration I can use?

IrvingArmenta avatar Apr 28 '21 00:04 IrvingArmenta

Hello, @IrvingArmenta, thanks for your question!

You should take a look at the fastify-oas plugin. For me, it works better rather than fastify-swagger.

Attaching the working FastifyResty server configuration with fastify-oas setup. Make sure that you register that before the controllers bootstrapping. All the endpoints/controllers registered before the fastify-oas or fastify-swagger will not be used for Swagger definitions.

export const createFastifyServer = async (): Promise<FastifyInstance> => {
  const server = fastify({ logger: true });

  const connection = await createConnection(config.typeormConnection);
  server.register(typeorm, { connection });

  server.register(oas, {
    routePrefix: '/documentation',
    swagger: {
      info: {
        title: 'Test openapi',
        description: 'testing the fastify swagger api',
        version: '0.1.0',
      }
    },
    exposeRoute: true
  });

  server.register(bootstrap, {
    entry: path.join(__dirname, 'api')
  });

  return server;
};

DanilaFadeev avatar May 03 '21 20:05 DanilaFadeev