Skip to content

Latest commit

 

History

History
50 lines (40 loc) · 1.28 KB

README.md

File metadata and controls

50 lines (40 loc) · 1.28 KB

OpenAPI documentation generation

Installation

implementation("io.github.turchenkoalex:kotlet-openapi:1.0.0")

Configuration

Before configuration OpenAPI routing, you need to configure application routing as usual and provide it to documentedRoutings property.

Example:

    data class HelloResponse(val message: String)

    val applicationRouter = Kotlet.routing {
        get("/hello", { call ->
            call.respondText("Hello, World!")
        }) {
            openapi {
                summary("Hello world")
                responses {
                    jsonResponse<HelloResponse>("Simple response")
                }
            }
        }
    }

    val auxRouter = Kotlet.routing {
        installOpenAPI {
            path = "/swagger/openapi.json"
            documentedRoutings = listOf(applicationRouter)
            prettyPrint = true
            openAPI {
                info {
                    title = "Sample API"
                    version = "1.0"
                }
            }
        }
    }

    val kotlet = Kotlet.servlet(
        routings = listOf(applicationRouter, auxRouter)
    )

This feature works better with the kotlet-swagger-ui library. You can use it to visualize the OpenAPI documentation.