egg-ez-swagger
v1.0.8
Published
[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![David deps][david-image]][david-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][down
Downloads
13
Readme
egg-ez-swagger
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