Generate Swagger/OpenAPI definitions without running fastify app !
npm i fastify-swagger-generate
- Only supports configuration based routes, i.e collection of route definitions
- This library has no new content added
- This library has just tweaked the original fastify-swagger
- Create a
generate.js
file which looks like
const fastifySwagGen = require("fastify-swagger-generate");
const Routes = require("./routes");
const opts = {};
// generate swagger definitions
fastifySwagGen(opts, Routes, (err, definitions) => {
// Write to a file
require("fs")
.createWriteStream("./app.swag.json")
.write(JSON.stringify(definitions));
});
- Let's say you have routes defined in
routes.js
const routes = [
{
url: "/users/:id",
method: "GET",
schema: {
params: {
type: "object",
properties: {
id: {
type: "number",
},
},
},
},
},
];
module.exports = routes; // should be an iterable routes