如何为Dev、Qa和prod等不同环境生成swagger-ui和swagger.json文件带有快速型锻发生器
我在努力http://localhost:3000/v1对于swagger UI视图,但它给出错误为Cannot GET/v1。我正在使用正确的链接来检查swagger UI吗?是否。以及如何为不同的环境检索swagger.json
// my app.js file is
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.json());
const expressSwagger = require('express-swagger-generator')(app);
let options = {
swaggerDefinition : {
info : {
description : 'This is a sample server',
title : 'Swagger',
version : '1.0.0'
},
host : 'localhost:3000',
basePath : '/v1',
produces : [ 'application/json', 'application/xml' ],
schemes : [ 'http', 'https' ],
securityDefinitions : {
JWT : {
type : 'apiKey',
in : 'header',
name : 'Authorization',
description : ''
}
}
},
basedir : __dirname, //app absolute path
files : [ './swagger/swagger.js' ] //Path to the API handle folder
};
expressSwagger(options);
app.use(require('./routes/routes'));
app.listen(3000, () => {
console.log('running on', 3000);
});
// ./routes/routes file
const express = require('express');
const router = express.Router();
router.post('/swag', (req, res) => {
let email = req.body.email;
console.log(email);
res.json(email);
});
module.exports = router;
// ./swagger/swagger.js file
/**
* This function comment is parsed by doctrine
* @route POST /swag
* @group foo - Operations about user
* @param {string} email.body.required - username or email - eg: user@domain
* @returns {object} 200 - An array of user info
* @returns {Error} default - Unexpected error
*/
我使用了错误的swagger-ui视图链接正确的链接是http://localhost:3000/api-文档对于swagger.json链接http://localhost:3000/api-docs.json