DebugRoutes

The routes of a tab, as DebugTab.routes declares them. From the declarations, the tab's default DebugTab.handle routes each request, answers 405 for a declared path with another method and 400 with field for a missing or wrong parameter, and calls the route's handler. The tab's default DebugTab.schema returns an OpenAPI document made from the same declarations, so GET /api/v1/_meta lists the tab and the server can name the query parameters that a route does not declare.

@OptIn(ExperimentalDebugRoutes::class)
override fun routes(routes: DebugRoutes) {
routes.version = "1.0"
routes.get("snapshot") {
summary = "Poll the flags with an opaque cursor."
val cursor = query.string("cursor") { description = "The cursor of the previous response." }
handle { call -> snapshot(call[cursor]) }
}
}

A route's path is relative to /api/v1/<tab id>/, such as snapshot or items/{id}: a segment in braces is a path parameter, which the route declares with DebugRoute.path. A literal segment wins over a parameter, so items/new and items/{id} can both exist. For the route's own method, a segment that its parameter does not take, such as items/x for an int {id}, matches no route, so the client gets 404. The router checks the method before the path parameters, so another method gets 405 with an Allow header: with only DELETE items/{id}, GET items/x gets Allow: DELETE. The path "" declares the route at the tab root, /api/v1/<tab id>, such as the list and the create of a collection. The router ignores one slash at the end of a request's path, so seed/ reaches the route seed.

A mistake in the declarations, such as two routes with the same method and path, a path parameter that the route does not declare, a JSON fragment that is not valid JSON, or a route without DebugRoute.handle, throws IllegalStateException from the first DebugTab.handle or DebugTab.schema call. A unit test that calls tab.schema() finds it.

The API is for Kotlin. Java is not a target: the declaration blocks are Kotlin function types with a receiver.

Types

Link copied to clipboard
object Companion

Helpers for the JSON fragments of a declaration.

Properties

Link copied to clipboard

The description of the tab's routes, for the OpenAPI document.

Link copied to clipboard

The title of the tab's OpenAPI document. Without it, "<tab title> debug tab".

Link copied to clipboard

The version of the tab's routes: the info.version of the OpenAPI document, which GET /api/v1/_meta lists for the tab. Change it when a route changes. Required when the tab declares a route.

Functions

Link copied to clipboard
fun component(name: String, schema: String)

Adds the JSON Schema schema to the OpenAPI document under components/schemas/<name>, so that a response or a parameter can refer to it with ref. ErrorEnvelope, the shared error envelope, is always there.

Link copied to clipboard
fun delete(path: String, declare: DebugRoute.() -> Unit)

Declares the DELETE route at path.

Link copied to clipboard
fun get(path: String, declare: DebugRoute.() -> Unit)

Declares the GET route at path.

Link copied to clipboard
fun patch(path: String, declare: DebugRoute.() -> Unit)

Declares the PATCH route at path.

Link copied to clipboard
fun post(path: String, declare: DebugRoute.() -> Unit)

Declares the POST route at path.

Link copied to clipboard
fun put(path: String, declare: DebugRoute.() -> Unit)

Declares the PUT route at path.