使用Springdoc搭建openapi文档管理服务

1. Springdoc-openapi Modules

在这里插入图片描述
更多详情参考:Springdoc-openapi Modules

2. pom引入

  • 如果使用Spring-webmvc,本文以Spring-webmvc为例展开。
<dependency>
	<groupId>org.springdoc</groupId>
	<artifactId>springdoc-openapi-ui</artifactId>
	<version>1.5.9</version>
</dependency>
  • 如果使用Spring-webflux
<dependency>
   <groupId>org.springdoc</groupId>
   <artifactId>springdoc-openapi-webflux-ui</artifactId>
   <version>1.5.9</version>
</dependency>

3. 配置文件

springdoc:
  version: '@springdoc.version@'
  swagger-ui:
    display-request-duration: true
    operationsSorter: method
    disable-swagger-default-url: true
    use-root-path: false

如果springdoc.swagger-ui.use-root-path = true,则访问应用的根目录既可以打开swagger-ui的首页,如 http://localhost:8080;
如果配置了springdoc.swagger-ui.path,如(springdoc.swagger-ui.path = /swagger-ui),则需要访问 http://localhost:8080/swagger-ui访问swagger首页。

4. Swagger Configuration

4.1 How to configure

Swagger UI accepts configuration parameters in four locations.

From lowest to highest precedence:

  • The swagger-config.yaml in the project root directory, if it exists, is baked into the application
  • configuration object passed as an argument to Swagger UI (SwaggerUI({ … }))
  • configuration document fetched from a specified configUrl
  • configuration items passed as key/value pairs in the URL query string

更多配置信息参考:Swagger UI Configuration

5. Swagger UI 加载流程

在这里插入图片描述

5.1 access swagger ui path

  • controller
    在这里插入图片描述
  • build redirect url, set response location and return.
    在这里插入图片描述

5.2 redirect to swagger config url

在这里插入图片描述

5.3 access api docs url

在这里插入图片描述

参考

Springdoc-openapi Modules
OpenAPI Specification
Swagger UI Configuration

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值