egg-swagger-view

0.1.2 • Public • Published

egg-swagger-view

swagger-ui plugin for egg, based on swagger-ui-dist@2.x, which display your swagger output in browser and start with egg server that already runs.

Usage

First, install it:

npm i egg-swagger-view -S

Import it via config/plugin.js:

module.exports = {
  ...
  swaggerUi: {
    enable: true,
    package: 'egg-swagger-view'
  }
  ...
}

Configure it via config/config.<env>.js:

const { getAbsoluteFSPath } = require('egg-swagger-view')
module.export = {
  swaggerUi: {
    // swagger output file path, absolute path based on project dir
    // default as '/docs/swagger.json'
    swaggerPath: '/path/to/swaggerFile'
  },
  static: {
    dir: [
      // config swagger ui dir as static resource
      { dir: getAbsoluteFSPath(), prefix: '/' },
      // config the swagger output file as static resource
      // make sure dir name equal to prefix based on swaggerPath
      { dir: './docs', prefix: '/docs' },
    ],
  },
}

Default value:

  • swaggerPath: /docs/swagger.json

Browse

browse http://{ip}:{port}/swagger.html to view your api docs!

(ip & port are already config in your egg project, no need to start any web server.)

Package Sidebar

Install

npm i egg-swagger-view

Weekly Downloads

2

Version

0.1.2

License

ISC

Unpacked Size

5.54 MB

Total Files

52

Last publish

Collaborators

  • dobility