Skip to content

Getting Started

Add Dependency

To serve Swagger UI, you need to include the ktor-swagger-ui artifact in the build script. All artifacts are published to Maven Central.

implementation("io.github.smiley4:ktor-swagger-ui:$version")
implementation 'io.github.smiley4:ktor-swagger-ui:$version'
<dependency>
    <groupId>io.github.smiley4</groupId>
    <artifactId>ktor-swagger-ui</artifactId>
    <version>${version}</version>
</dependency>

Usage

routing {

    route("swagger") { //(1)!
        swaggerUI("/api.json") { //(2)!
            //...(3)
        }
    }

}
  1. Specify route to serve Swagger UI at /swagger.
  2. Expose Swagger UI showing OpenAPI specification at /api.json. The url can be relative pointing to specification provided by this application or absolute pointing to an external resource. Specify a map of urls to interact with multiple different specifications in the same Swagger UI "instance".
  3. Add configuration for this Swagger UI "instance" here.
Using Swagger UI with auto-generated OpenAPI specification
routing {

    route("api.json") {
        openApi() //(1)!
    }
    route("swagger") {
        swaggerUI("/api.json") //(2)!
    }

}
  1. Serve auto-generated OpenAPI specification at /api.json.
  2. Expose Swagger UI using auto-generated specification at /api.json.
Configuration Options

For more information on available configuration options, please see the api reference.