feat: Added SwaggerUI KTor Plugin (#215)

This commit is contained in:
Jevgeni Goloborodko
2022-03-01 19:47:51 +02:00
committed by GitHub
parent 1355d4dd75
commit bae3a16e30
10 changed files with 241 additions and 18 deletions

View File

@ -1,3 +1,52 @@
# Module kompendium-swagger-ui
Contains the code necessary to launch `swagger` as your documentation frontend.
This module is responsible for frontend part of `SwaggerUI` built on top on WebJar.
Solution is wrapped into KTor plugin that may be tuned with configuration properties according to
Swagger UI official documentation (`JsConfig` is responsible for that):
https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/
Current implementation covers only most important part of specification properties (we'll be adding more time to time)
# Module configuration
Minimal SwaggerUI plugin configuration:
```kotlin
import io.bkbn.kompendium.swagger.JsConfig
import io.bkbn.kompendium.swagger.SwaggerUI
import io.ktor.application.install
install(SwaggerUI) {
swaggerUrl = "/swagger-ui"
jsConfig = JsConfig(
specs = mapOf(
"Your API name" to URI("/openapi.json")
)
)
}
```
Additionally, there is a way to add additional initialization code in SwaggerUI JS.
`JsConfig.jsInit` is responsible for that:
```kotlin
JsConfig(
//...
jsInit = {
"""
ui.initOAuth(...)
"""
}
)
```
# Playground example
There is an example that demonstrates how this plugin is working in `kompendium-playground` module:
```
io.bkbn.kompendium.playground.SwaggerPlayground.kt
```