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

Command to generate swagger/openapi schema from @fastify/swagger #563

Closed
2 tasks done
segevfiner opened this issue Oct 30, 2022 · 5 comments · Fixed by #567
Closed
2 tasks done

Command to generate swagger/openapi schema from @fastify/swagger #563

segevfiner opened this issue Oct 30, 2022 · 5 comments · Fixed by #567

Comments

@segevfiner
Copy link
Contributor

Prerequisites

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

🚀 Feature Proposal

It would be cool to have a CLI command to generate the swagger/openapi schema that @fastify/swagger generates to a file.

Motivation

So that I won't have to start the server or eject and write a custom script to achieve this.

(Could make sense as a plugin for fastify-cli itself, but I don't think fastify-cli supports plugins supplying custom commands)

Example

fastify generate-swagger server.js > openapi.json

Which will essentially call fastify.swagger() and print it out. Of course, output file flags, flag to generate yaml, etc. Are also welcome.

@mcollina
Copy link
Member

mcollina commented Nov 2, 2022

We have some code for doing this in Platformatic: https://github.com/platformatic/platformatic/blob/main/packages/db/lib/gen-schema.mjs

I don't think this should be part of fastify-cli as having an OpenAPI definition is likely too opinionated.

@segevfiner
Copy link
Contributor Author

As just a subcommand, or as a plugin to fastify-cli itself? Or an external command that uses some the same code that fastify-cli uses to import the app (Which might not be exported ATM)?

@mcollina
Copy link
Member

mcollina commented Nov 2, 2022

The problem is that this does not bundle @fastify/swagger, so how would you add this plugin to the CLI?

@segevfiner
Copy link
Contributor Author

segevfiner commented Nov 2, 2022

Conditionally at runtime, the user will have to install it in his app, we will only check if it exists on the app instance rather than try to use our own copy.

@mcollina
Copy link
Member

mcollina commented Nov 2, 2022

I would love to see how you'd implement this. However I'm not sure this would land.

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

Successfully merging a pull request may close this issue.

2 participants