1.0.13 • Published 5 years ago

salak-swagger v1.0.13

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

salak-swagger

NPM version build status David deps NPM download

For generating Swagger 2.0 JSON from router

API

generateSwaggerSpec (router, baseSpec, options)

router config:

  • prefix: the api path
  • modules

baseSpec: Swagger base info

  • info: like title, version, description, contact...
  • tags: array

options:

  • defaultResponses

Install

npm install --save salak-swagger

Usage

const { generateSwaggerSpec } = require('salak-swagger')
const Joi = require('joi')

const swagger = generateSwaggerSpec({
  prefix: '/api',
  modules: [
    {
      name: 'blog',
      routes: [
        {
          path: '/:id',
          method: ['GET'],
          meta: {
            summary: '',
            description: '',
            tags: ['文章']
          },
          validate: {
            header: Joi.object().keys({
              Authorization: Joi.string().required()
            }),
            params: {
              id: Joi.string().required().description('Article id')
            },
            query: {
              id: Joi.string().required()
            },
            responses: {
              200: {
                body: Joi.object().keys({
                  code: Joi.number(),
                  msg: Joi.string()
                }),
                headers: Joi.object().keys({
                  authorization: Joi.string().required()
                }).options({
                  allowUnknown: true
                })
              }
            }
          }
        }
      ]
    }
  ]
}, {
  info: {
    description: 'Blog api',
    version: '1.0.0',
    title: 'Blog Swagger',
    contact: {
      name: 'wengeek',
      email: 'xxx.xxx@xxx.com'
    }
  }
})

console.log(swagger)

LICENSE

MIT

1.0.13

5 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago