spring-boot - Swagger UI - 加载自定义 file.yaml/json 而不是默认配置
问题描述
我正在开发一个运行完美的 SpringBoot REST 项目。我正在尝试在项目中实现OpenApi-ui。默认情况下它工作正常,但我想使用我自己的yaml/json信息文件而不是默认信息。
我一直在关注常见问题解答 SpringDoc文档,但没有什么对我有用。它在 UI 中抛出FAILED TO LOAD API DEFINITION : Fetch error undefined /open-api.yaml。我的配置中是否缺少某些内容?提前致谢。
执行
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.5.9'
应用配置(路由 yaml = src/main/resources)
springdoc:api-docs:enabled: false
swagger-ui:url: /open-api.yaml
配置
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.components(new Components().addSecuritySchemes("basicScheme",
new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
.info(new Info().title("MyApp").version("1.0")
.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
@Bean
public SpringDocConfiguration springDocConfiguration(){
return new SpringDocConfiguration();
}
@Bean
public SpringDocConfigProperties springDocConfigProperties() {
return new SpringDocConfigProperties();
}
yaml 文件
openapi: 3.0.3
info:
title: MyApp
description: MyApp Description
version: 1.0.0
servers:
- url: http://localhost:8080
description: Local server
{...more}
访问 OpenApi UI 的 URL http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config
解决方案
如果有人在寻找类似的东西,我们最终创建了一个新类,扩展SwaggerIndexPageTransformer并由SwaggerIndexTransformer实现,这导致我们使用 @override 方法来更改 url。
您可以关注 > https://github.com/springdoc/springdoc-openapi/issues/763
推荐阅读
- kubernetes - Azure Kubernetes - 无法为 MongoDb 附加或装载卷
- php - 为什么在 Laravel 中使用 Sortable 包时会出现“尝试获取非对象的属性”错误?
- javascript - 如何从谷歌表中的导入范围设置日期 onEdit()
- haskell - 为什么 Hackage 上对的 Monad 实例没有返回实现?
- javascript - 如何在棋盘的方格上画圆圈以使其看起来像真正的棋盘?
- javascript - 不呈现动态根
- python - 在 mac 中执行 python3 时权限被拒绝
- wordpress - 是否可以在 GCP 中使用带有灯 + wordpress 堆栈的启动启动脚本创建实例模板?
- php - Laravel 的 Throttling 是如何在不同的路由上工作的?
- jquery - 使用 jQuery 和 AJAX 加载页面时设置默认值