0

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:

  1. Gradle openapi generator plugin id("org.openapi.generator") version "6.3.0"
  2. 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?

darth jemico
  • 605
  • 2
  • 9
  • 18
  • Does this answer your question -- [How to point Springdoc Swagger UI to my own YAML file instead of the auto-generated one?](https://stackoverflow.com/q/65612026/113116) – Helen Apr 10 '23 at 13:49
  • Not really so. I'm using springdoc, so it's a little different thing. – darth jemico Apr 11 '23 at 09:56

1 Answers1

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:

  1. Add springdoc settings:
springdoc:
  api-docs:
    enabled: false
  swagger-ui:
    url: /openapi.yaml
  1. As it's written there - it's very important to place yaml file into proper location: src/main/resources/static
  2. 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

darth jemico
  • 605
  • 2
  • 9
  • 18