-
自动化生成swagger文档
使用hapi插件hapi-swagger,简单配置下插件,先修改下plugin_config.js文件:
//plugin_config.js const SwaggerOptions = { info: { 'title': 'hapi API Documentation', 'version': '1.0.0' } }; //module.exports = [ //{ // plugin: require('inert'), // options: { // } //}, { plugin: require('hapi-swagger'), options: SwaggerOptions }, //{ //plugin: require('vision'), //options: { //} //} //];
修改routes/login.js文件,代码如下:
//login.js //const Joi = require('joi'); //const controllers = require('../controllers'); //let login = { //method: 'get', //path: '/login', config: { auth: false, description: 'Routing with parameters', notes: 'login api', tags: ['api'], validate: { query: { name: Joi.required(), } }, id: 'login' }, //handler: controllers.user.login //}; //module.exports = login;
Joi是数据格式校验插件,可以改成Joi.mix(3).ewquired(),这里不做演示了。
输入地址:http://localhost:8090/documentation
ok,大功告成!
参考资料:https://segmentfault.com/a/1190000010143528#articleHeader0