problemResponses
fun Route.problemResponses(catalog: ProblemDetailsCatalog, configure: Response.Builder.() -> Unit = {}): Route(source)
Documents catalog's universally-applicable responses on this route and everything below it.
Ktor merges route metadata from the routing root downwards, so a call inside routing { } covers every endpoint in the application, and a call on a route("/api") covers that subtree. Metadata added deeper merges with this rather than replacing it. To document several subtrees with one catalog, call this once on their common parent instead of on each of them.
Which responses those are, and why domain types are excluded, is problemsFrom's business.
This wraps Route.describe, which Ktor marks experimental. Callers opt in through ExperimentalProblemDetailsOpenApi because the underlying API may change within a 3.x release.
Return
this route, for chaining.
Samples
val catalog = problemCatalog { standardStatusCodes() }
install(StatusPages) { problemDetails(catalog) }
routing {
// One call at the root: every endpoint below now documents the catch-all and the catalog's
// status codes, without a line per route.
problemResponses(catalog)
get("/orders/{id}") {
call.respondText("an order")
}.describe {
responses { problemResponse(OutOfCredit) }
}
}Content copied to clipboard