feat: Added SwaggerUI KTor Plugin (#215)
This commit is contained in:

committed by
GitHub

parent
1355d4dd75
commit
bae3a16e30
@ -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
|
||||
```
|
Reference in New Issue
Block a user