英文:
How to initialize swagger from openapi resource file
问题
I'm using Kotlin Spring Boot Web MVC应用程序。我已创建了一个名为openapi.yml
的api-first文件,其中包含API描述。此外,我还添加了所需的依赖项,如:
- Gradle OpenAPI生成插件
id("org.openapi.generator") version "6.3.0"
- OpenAPI
implementation("org.springdoc:springdoc-openapi-ui:${libs.versions.openapi.get()}")
我已成功使用Gradle生成器从我的文件生成API /模型,但我需要将其制作成Swagger的模板。我已经查看了springdoc的所有设置,似乎只能使用springdoc.swagger-ui.url
属性转发生成的文档。
是否有一种方式可以手动从openapi.yml
文件初始化Swagger?
英文:
I'm using kotlin spring boot web mvc application. I've created an api-first file openapi.yml
that contains api description. Also I've added required dependencies, like:
- Gradle openapi generator plugin
id("org.openapi.generator") version "6.3.0"
- Openapi
implementation("org.springdoc:springdoc-openapi-ui:${libs.versions.openapi.get()}")
I've successfully generated apis / model with gradle generator from my file, but I need to make it as a template for swagger.
I've reviewed all the springfoc's settings and it seems, that I can only forward a generated documentation with a springdoc.swagger-ui.url
property.
Is there any way to initialized swagger from a openapi.yml
file manually?
答案1
得分: 1
I've managed to find how to resolve this issue.
For springdoc
, the right way is described here:
https://springdoc.org/faq.html#_how_can_use_custom_jsonyml_file_instead_of_generated_one
My steps:
- Add springdoc settings:
springdoc:
api-docs:
enabled: false
swagger-ui:
url: /openapi.yaml
- As it's written there - it's very important to place yaml file into proper location:
src/main/resources/static
- For multi-module projects, api docs can be placed at root projects and then copied into the mentioned above path with a custom gradle task, like:
register<Copy>("copyOpenApiDoc") {
from(rootProjectOpenapiFolder.resolve("openapi.yaml"))
into(buildDir.resolve("resources/main/static"))
}
Perhaps not a beautiful solution, but it works.
英文:
I've managed to find how to resolve this issue.
For springdoc
the right way is described here:
https://springdoc.org/faq.html#_how_can_use_custom_jsonyml_file_instead_of_generated_one
My steps:
- Add springdoc settings:
springdoc:
api-docs:
enabled: false
swagger-ui:
url: /openapi.yaml
- As it's written there - it's very important to place yaml file into proper location:
src/main/resources/static
- For multi-module projects api docs can be placed at root projects and then copied into mentioned above path with a custom gradle task, like:
register<Copy>("copyOpenApiDoc") {
from(rootProjectOpenapiFolder.resolve("openapi.yaml"))
into(buildDir.resolve("resources/main/static"))
}
Perhaps not a beautiful solution, but it works
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论