A Ktor plugin for validating HTTP requests and responses against an OpenAPI specification.
dependencies {
testImplementation("io.github.lexa-diky:ktor-openapi-validator:0.5.0")
}This plugin is intended for test only, please avoid using it in production code.
Install OpenApiValidator client plugin and specify specificationUrl and it will do the rest automatically.
val client = HttpClient {
// ... rest of your configuration
install(OpenApiValidator) {
specificationUrl = "openapi.yaml"
}
}You can whitelist specific requests or responses by providing a list of paths and methods that should be ignored during validation.
install(OpenApiValidator) {
specificationUrl = "openapi.yaml"
// Whitelist any response with error status code
whitelist("Allow any error") {
response.code?.isSuccess() == false
}
}You can provide a custom reporter to handle validation errors. The default reporter will use Junit5 assertions to report errors.
install(OpenApiValidator) {
specificationUrl = "openapi.yaml"
reporter = TextReporter { messages ->
messages.forEach { message ->
println("OpenAPI validation error: $message")
}
}
}Library integrates with Junit5 via compile time dependency. Please provide appropriate implementation on classpath if you are using default reporter.
dependencies {
testImplementation("io.github.lexa-diky:ktor-openapi-validator:<latest-version>")
testImplementation("org.junit.jupiter:junit-jupiter-api:<your-junit-version>")
}Library integrates with Ktor Client via compile time dependency. It is compiled explicitly against Ktor 2.x, but works fine with Ktor 3.x as well. Please provide appropriate implementation on classpath.
dependencies {
testImplementation("io.github.lexa-diky:ktor-openapi-validator:<latest-version>")
testImplementation("io.ktor:ktor-client-core:<your-ktor-version>")
}