README
Comment your code for
- Route gerenerate.
- Create Swagger2 Doc.
- Tell you team what the code do.
npm install express-route-by-jsdoc
Option
options = {
route: { url: '/test/docs', docs: '/test/api-docs.json' },
swaggerDefinition: {
info: {
description: 'description support [Markdown Syntax](https://www.markdownguide.org/)',
title: 'test npm',
version: '1.0.0'
},
host: 'localhost:3100',
basePath: '/test/v1',
produces: [
'application/json'
],
schemes: ['http']
},
basedir: __dirname, // app absolute path
files: ['./src/a1/*.js'] // Path to the API handle folder
}
Example
const express = require('express')
const app = express()
const erRouterGen = require('express-route-by-jsdoc')
const options = {
swaggerDefinition: {
info: {
description: 'project description',
title: 'test npm',
version: '1.0.0'
},
host: 'localhost:3100',
basePath: '/test/v1',
produces: [
'application/json'
],
schemes: ['http','https']
},
route: { url: '/test/docs', docs: '/test/api-docs.json' }, //swagger doc will show on http://localhost:3100/test/docs
basedir: __dirname, // app absolute path
files: ['./src/a1/*.js'] // Path to the API handle folder
}
/* app.use(some middleware) */
erRouterGen(app, options)
app.listen(3100)
With above code
Define Express Router with code comments
//**
* This function comment is parsed by doctrine
* @route GET /api/get/userinfo/{userid}
* @group foo - Operations about user
* @param {string} userid.path.required - userid - eg: wisit
* @returns {object} 200 - object of user info
* @returns {Error} default - Unexpected error
*/
function customeMiddelware (req, res, next) {
// logic
// or res.send(...)
res.json(req.params)
}
module.exports = customeMiddelware
Inspiration express-swagger-generator