Getting Started
Add Dependency
To generate OpenAPI specifications, you need to include the ktor-openapi
artifact in the build script.
All artifacts are published to Maven Central.
implementation("io.github.smiley4:ktor-openapi:$version")
implementation 'io.github.smiley4:ktor-openapi:$version'
<dependency>
<groupId>io.github.smiley4</groupId>
<artifactId>ktor-openapi</artifactId>
<version>${version}</version>
</dependency>
Ktor Compatibility and Previous Versions
This project as been split into multiple projects starting with version 5.0.
Versions up to 5.0 are called ktor-swagger-ui
instead of ktor-openapi
.
Ktor | Plugin Version | Project Name |
---|---|---|
2.x | up to 3.x | ktor-swagger-ui |
3.x | 4.x | ktor-swagger-ui |
3.x | 5.x | ktor-openapi |
Install OpenAPI
install(OpenApi) {
//...
}
Exposing OpenAPI Specification
routing {
route("api.json") {
openApi()
}
}
Documenting Routes
import io.github.smiley4.ktoropenapi.get
get("hello", {
description = "A Hello-World route"
response {
HttpStatusCode.OK to {
description = "A success response"
body<String>()
}
}
//...
}) {
call.respondText("Hello World!")
}