egg-ez-swagger

1.0.8 • Public • Published

egg-ez-swagger

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-ez-swagger --save

Usage

// {app_root}/config/plugin.js
exports.swagger = {
  enable: true,
  package: 'egg-ez-swagger',
};
// {app_root}/config/config.default.js
exports.swagger = {
  host: '127.0.0.1:7001',
}

Example

// {app_root}/app/router.js
module.exports = app => {
 const {
    createSwagger 
  } = app.swaggerHelper;
 
  const gps = require('./routes/gps')(app);
  const routes = Object.assign(gps);
 
  createSwagger(routes, app.config.swagger);
};
 

create new folder routes

 
// {app_root}/app/routes/gps/js
const tagName = 'Gps模块';
module.exports = app => {
  const {
    eggPropTypes 
  } = app.swaggerHelper;
  const route = {
    '/Api/gps/getData': {
      summary: '获取数据',
      description: '',
      tag: tagName,
      method: 'post',
      action: app.controller.gpsController.getData,
      model: {
        data: eggPropTypes.stringArray,
      },
    },
  };
  return route;
};

run process then you can access swagger by 127.0.0.7001/public/swagger/index.html

License

MIT

Package Sidebar

Install

npm i egg-ez-swagger

Weekly Downloads

10

Version

1.0.8

License

MIT

Unpacked Size

18 MB

Total Files

21

Last publish

Collaborators

  • tao_w