Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-swagger

Package Overview
Dependencies
Maintainers
6
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-swagger

Generate Swagger files automatically for Fastify.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
77K
increased by12.91%
Maintainers
6
Weekly downloads
 
Created
Source

fastify-swagger

js-standard-style Build Status

Swagger documentation generator for Fastify.
It uses the schemas you declare in your routes to generate a swagger compliant doc.

Install

npm i fastify-swagger --save

Usage

Add it to your project with register and pass it some basic options, then call the swagger api and you are done!

const fastify = require('fastify')()

fastify.register(require('fastify-swagger'), {
  swagger: {
    info: {
      title: 'Test swagger',
      description: 'testing the fastify swagger api',
      version: '0.1.0'
    },
    host: 'localhost',
    schemes: ['http'],
    consumes: ['application/json'],
    produces: ['application/json']
  }
})

fastify.post('/some-route', {
  schema: {
    description: 'post some data',
    tags: ['user', 'code'],
    summary: 'qwerty',
    payload: {
      type: 'object',
      properties: {
        hello: { type: 'string' },
        obj: {
          type: 'object',
          properties: {
            some: { type: 'string' }
          }
        }
      }
    },
    out: {
      description: 'Succesful response',
      code: 201,
      type: 'object',
      properties: {
        hello: { type: 'string' }
      }
    }
  }
}, (req, reply) => {})

fastify.ready(err => {
  if (err) throw err
  fastify.swagger()
})

API

register options
{
  swagger: {
    info: {
      title: String,
      description: String,
      version: String
    },
    host: String,
    schemes: [ String ],
    consumes: [ String ],
    produces: [ String ]
  }
}

All the above parameters are optional.
You can use all the properties of the swagger specification, if you find anything missing, please open an issue or a pr!

swagger options

Calling fastify.swagger will return to you a JSON object representing your api, if you pass { yaml: true } to fastify.swagger, it will return you a yaml string.

If you pass { exposeRoute: true } the plugin will expose the documentation with the following apis:

urldescription
'/documentation/json'the json object representing the api
'/documentation/yaml'the yaml object representing the api
'/documentation'the swagger ui

Hide a route

Sometimes you may need to hide a certain route from the documentation, just pass { hide: true } to the schema object inside the route declaration.

Acknowledgements

This project is kindly sponsored by:

License

Licensed under MIT.

Keywords

FAQs

Package last updated on 03 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc