Skip to content

Generate Swagger or OpenAPI Specification (JSON/YML) for Fastify server routes without running the server

License

Notifications You must be signed in to change notification settings

manju4ever/fastity-swagger-generate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Generate Swagger or OpenAPI Specification (JSON/YML) for Fastify server routes without running the server

Topics

Resources

License

Stars

Watchers

Forks