lad*_*net 8 kotlin swagger spring-boot openapi
我有一个项目(Spring Boot App + Kotlin),我希望有一个Open API 3.0规范(最好在YAML中)。Springfox库很好,但是它们生成Swagger 2.0 JSON。从控制器中的注释生成Open Api 3.0规范的最佳方法是什么?从头开始编写它是唯一的方法吗?
小智 12
我们在我们的 kotlin 项目中使用了 springdoc-openapi 库,它满足了我们使用 spring boot 项目自动化生成 API 文档的需求。
它会自动将 swagger-ui 部署到 spring-boot 应用程序
Swagger UI 页面应该在以下位置可用: - http://server:port/context-path/swagger-ui.html OpenAPI 描述将在以下 json 格式的 URL 中提供: - http://server:port /context-path/v3/api-docs
将库添加到您的项目依赖项列表中(无需额外配置)
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.2.32</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
您可以查看spring-restdocs和restdocs-api-spec。
spring-restdocs
对 API 文档采用测试驱动的方法,这比 spring-fox 使用的内省驱动的方法有很多优点。restdocs-api-spec
是 spring-restdocs 的扩展,添加了 API 规范支持。目前支持OpenAPI2、OpenAPI3和Postman。
归档时间: |
|
查看次数: |
6099 次 |
最近记录: |