0.1.3 • Published 1 year ago

fastify-swagger-generate v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

fastify-swagger-generate

Generate Swagger/OpenAPI definitions without running fastify app !

Install

npm i fastify-swagger-generate

Disclaimer

  • 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

Usage

  1. 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));
});
  1. 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

API

Options

Refer here for more