SMILEY4 / ktor-swagger-ui

Kotlin Ktor plugin to generate OpenAPI and provide Swagger UI
Apache License 2.0
182 stars 33 forks source link

Is there any way to get the spec as json without calling doc/api.json? #119

Closed kkivan closed 4 months ago

SMILEY4 commented 4 months ago

Hi, you can get the json-string from ApiSpec.get(PluginConfigDsl.DEFAULT_SPEC_ID) after its built by its id. By default, i.e. if you are not using multiple specs and the default configuration, the id is always PluginConfigDsl.DEFAULT_SPEC_ID, otherwise the one you assigned. Another option is the "post-build"-hook in the plugin config that is called with the finished OpenAPI-object.

install(SwaggerUi) {
   postBuild = { openApiSpec ->
      // ...
   }
}