一.出现的问题情况
二、我配置的代码
const expressSwagger = require('express-swagger-generator');
// 设置 Swagger UI
const swaggerOptions = {
swaggerDefinition: {
info: {
title: 'API文档',
version: '1.0.0',
description: 'API文档描述',
},
basePath: '/',
produces: ['application/json'],
schemes: ['http'],
},
route: {
url: '/swagger',
docs: '/swagger.json'
},
basedir: __dirname,
files: ['../router/*.js'],
};
module.exports=function EXSwagger(app){
expressSwagger(app)(swaggerOptions)
}
三、可能出现的问题
四、发现最后的问题
是这个版本低了,太老了(。。。。)
五、解决的新方案代码
const expressJSDocSwagger = require('express-jsdoc-swagger');
// 设置 Swagger UI
const options = {
info: {
version: '1.0.0',
title: 'Albums store',
license: {
name: 'MIT',
},
},
security: {
BasicAuth: {
type: 'http',
scheme: 'basic',
},
},
baseDir: __dirname,
filesPattern: '../router/*.js',
swaggerUIPath: '/api-docs',
exposeSwaggerUI: true,
exposeApiDocs: false,
apiDocsPath: '/v3/api-docs',
notRequiredAsNullable: false,
swaggerUiOptions: {},
multiple: true,
};
module.exports=function EXSwagger(app){
expressJSDocSwagger(app)(options)
}
六、收获
为什么要写这个笔记,因为之前配置spring boot和swagger也出现过这个问题,也是版本不行了。。。