node配置swagger出现浏览器出现纯文本html但页面不渲染

一.出现的问题情况

二、我配置的代码

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也出现过这个问题,也是版本不行了。。。

  • 8
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值