fastify / fastify-swagger

Swagger documentation generator for Fastify
MIT License
941 stars 209 forks source link

Generate complete swagger.json beforehand by knowing all added schemas. #673

Closed arthurfiorette closed 2 years ago

arthurfiorette commented 2 years ago

Prerequisites

Issue

Hey! I'm coding a generator that is using this awesome package.

It is generating fastify routes and, optionally, schemas through fastify.addSchema. This means that, before even running tsc to transpile the typescript code, the kita CLI knows every schema that will be added at runtime.

To give more context, this is an example of a group of generated schemas:

https://github.com/arthurfiorette/kita/blob/10175fedb015b28fdb9651caf0221d6d7dd78dd0/packages/test-package/src/routes.ts#L103-L151

With the above in mind, how can i fully generate a swagger.json file (the same as a /documentation/json response is), without even starting the server? Tried to understand a bit of this library code and couldn't find where all schemas are glued...

Thanks!

mcollina commented 2 years ago

This is not possible right now, you need to boot the server to know all the routes. You can do that by doing fastify.ready() (which does not listen to any port).