swagger2.0升级到3.0小结

项目采用的Spring boot 2.2.8 在此基础上进行的整合。
另外使用

pom文件对比

swagger 2.0 pom文件:

<dependency>-->
     <groupId>io.springfox</groupId>
     <artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
     <groupId>io.springfox</groupId>
     <artifactId>springfox-swagger-ui</artifactId>
</dependency>

swagger3.0pom文件:

 <dependency>
     <groupId>io.swagger.core.v3</groupId>
     <artifactId>swagger-core</artifactId>
     <version>2.0.8</version>
 </dependency>
 <dependency>
     <groupId>io.swagger.core.v3</groupId>
     <artifactId>swagger-annotations</artifactId>
     <version>2.0.8</version>
 </dependency>

需要注意的是:

 <dependency
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
npm提供了许多方便的工具和库来生成Swagger 2.0文档。其中一个流行的工具是swagger-jsdoc。通过结合使用JSDoc注释和swagger-jsdoc库,我们可以在JavaScript文件中定义API接口和相应的Swagger文档信息。 首先,在项目中安装npm包swagger-jsdoc。可以使用以下命令: ``` npm install swagger-jsdoc --save ``` 接下来,在项目的入口文件或者需要生成Swagger文档的文件中,引入swagger-jsdoc并配置Swagger文档的相关内容。例如: ```javascript /** * @swagger * definitions: * Pet: * properties: * name: * type: string * age: * type: integer * * @swagger * /pets: * get: * description: 获取所有宠物 * responses: * 200: * description: 成功获取宠物列表 * post: * description: 创建新宠物 * parameters: * - name: pet * description: 宠物对象 * in: body * required: true * schema: * $ref: '#/definitions/Pet' */ // 引入swagger-jsdoc const swaggerJSDoc = require("swagger-jsdoc"); const express = require("express"); const app = express(); // 配置Swagger文档 const swaggerSpec = swaggerJSDoc({ definition: { openapi: "3.0.0", // 使用Swagger版本2.0 info: { title: "宠物商店API文档", version: "1.0.0", description: "这里是宠物商店的API文档" } }, apis: ["./routes/**/*.js"], // 定义API接口的文件路径 }); // 在需要展示Swagger文档的路由上,使用swagger-ui-express库 app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec)); // 其他路由及中间件... // 启动Express服务器... ``` 此外,还可以使用swagger-jsdoc提供的其他功能,例如支持路由的解析、文件导出等。更多的配置和用法可以查看swagger-jsdoc的官方文档。 通过以上步骤,我们就可以使用npm生成Swagger 2.0文档来描述我们的API接口及其相关信息。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值