DebugTab

abstract class DebugTab

The single public extension point for adding a tab to the Lustro debug UI.

Subclass and register a DebugTab to expose JSON routes and, optionally, an HTML view (via renderContent, renderScript, renderStyles). API-only tabs are valid: leave the render methods at their empty defaults.

A tab declares its routes in routes, and gets the routing, the parameter checks, and its OpenAPI document from the declarations. A tab can also route by hand in handle and give its own document in schema.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
abstract val icon: String

The tab icon, shown before the title in the tab bar. HTML-escaped by the server before render. Nothing shows the icon of a headless tab (see showInTabBar), so such a tab can set any value, such as "".

Link copied to clipboard
abstract val id: String

The stable tab id. Must match the regex [a-z][a-z0-9-]{0,30}; this is validated at registration. Used in route paths under /api/v1/<id>/.

Link copied to clipboard
open val order: Int = 100

Sort order; lower comes first. Ties are broken alphabetically by id.

Link copied to clipboard
open val showInTabBar: Boolean = true

Whether the tab appears in the tab bar. When false the tab is headless: its routes work and _meta lists it when it has an OpenAPI document, but it has no link in the tab bar and no page: /tab/<id> answers 404, as for an unknown tab.

Link copied to clipboard
abstract val title: String

The human-readable tab title, shown in the tab bar and listed for the tab in GET /api/v1/_meta. HTML-escaped by the server before render. A headless tab (see showInTabBar) must still set it: _meta lists it.

Functions

Link copied to clipboard
open fun handle(request: DebugRequest): DebugResponse?

Handles a debug API request. Return null for a route that the tab does not have, also for a method that a route does not take: the client gets an enveloped 404, or a 405 with an Allow header when the tab's OpenAPI document declares the path with other methods. For that check, one slash at the end of the path does not count, as for the declared routes, so a tab that routes by hand treats items/ as items. Throwing anything, including an Error such as TODO(), produces an enveloped 500. Throwing a DebugResponseException produces its response.

Link copied to clipboard
open fun onStart()

Called once when the debug server starts. Anything it throws is logged and ignored.

Link copied to clipboard
open fun onStop()

Called once when the debug server stops. Anything it throws is logged and ignored.

Link copied to clipboard
open fun renderContent(): String

Returns the tab's HTML body. Empty by default (API-only tabs).

Link copied to clipboard
open fun renderScript(): String

Returns the tab's JavaScript. When non-empty it is served at /_view.js; otherwise the static asset is used.

Link copied to clipboard
open fun renderStyles(): String

Returns the tab's CSS. When non-empty it is served at /_view.css; otherwise the static asset is used.

Link copied to clipboard
open fun schema(): String?

Returns a dynamic OpenAPI schema document, or null to use the static assets/lustro/<id>.openapi.json.