{# The shapes this page repeats: an operation's method, its identity line, its entry in the navigation, and one parameter's input. Macros rather than includes: two of them run once per operation, and an API with two hundred routes renders the navigation two hundred times per page load — the case `{% include %}` in a loop is wrong for. #} {% from "ui/data.html" import badge, caption, code_block, description_item, description_list, kbd, link %} {% from "ui/form.html" import select_field, text_field %} {% from "ui/layout.html" import row, stack %} {% from "ui/sidebar.html" import sidebar_item %} {% from "ui/table.html" import cell, table %} {% from "ui/tabs.html" import tab_panel, tabs %} {# Closed lookup, never interpolation. `badge(variant=method|lower)` would emit `data-variant="get"`, which the stylesheet has no rule for, and the badge would lose its colour with nothing to say why. The pairing is the one every API tool has settled on and is worth keeping: green creates, red destroys. HEAD and OPTIONS take the neutral variant, because nobody scans a list for them. #} {% set METHOD_VARIANT = { "GET": "info", "POST": "success", "PUT": "warning", "PATCH": "warning", "DELETE": "destructive", "HEAD": "secondary", "OPTIONS": "secondary", } %} {# method(name) — the coloured verb, wherever an operation is named. #} {% macro method(name) -%} {{ badge(name, METHOD_VARIANT.get(name, "secondary")) }} {%- endmacro %} {# op_line(operation) — verb plus path, the way an API is read aloud. The path is a `kbd` because it is a literal: a reader has to be able to tell `{task_id}` from prose without counting braces. #} {% macro op_line(operation) -%} {% call row(gap=2) %} {{ method(operation.method) }} {{ kbd(operation.path) }} {% if operation.deprecated %}{{ badge("deprecated", "outline") }}{% endif %} {# The padlock. An operation the document declares `security` on needs an authenticated client, and every API browser marks it, because the alternative is finding out from a 401. The scheme names ride in the tooltip rather than on screen: on a list where nearly everything is secured, the same three words after every path is noise. #} {% if operation.security %} {{ caption(operation.security | join(", "), size="xs", icon_name="lock", title="Requires " ~ operation.security | join(", ")) }} {% endif %} {% endcall %} {%- endmacro %} {# op_link(request, route, operation, target) — one row of the sidebar. `sidebar_item` rather than `sidebar_link`: that macro takes a route name and calls `url_for(request, route)` with no parameters, and every operation here is the same route with a different `operation_id`. The method badge is the item's `lead`, which sits in a fixed-width cell. `GET` and `DELETE` are different widths, and without the cell every name starts at a different x and a two-hundred-row index reads as ragged. `hx-*` on the anchor alongside a real `href`: the swap replaces only the detail panel, and the same URL still serves the whole page to a cold navigation, a crawler, or a middle-click. `title` is the path, not the summary. The sidebar already shows the summary, and the path is what you want on hover — the one place it is not on screen. #} {% macro op_link(request, route, operation, target, active=false, query="") -%} {# The filter's text rides along in the link. Two things depend on it: a reload of a pushed URL comes back to the list you were looking at, and the out-of-band nav that follows a click renders filtered rather than snapping back to all two hundred rows. #} {%- set href = url_for(request, route, operation_id=operation.id) ~ ("?q=" ~ query | urlencode if query else "") -%} {{ sidebar_item(operation.summary or operation.path, href, active=active, lead=method(operation.method), title=operation.method ~ " " ~ operation.path, hx_get=href, hx_target="#" ~ target, hx_swap="outerHTML", hx_push_url="true") }} {%- endmacro %} {# model_link(request, route, model, target) — one row of the Schemas branch. The same shape as `op_link` and for the same reasons: a real `href` serving the whole page, plus the `hx-*` that swaps only the panel. Kept separate rather than generalised over "thing with an id", because the two take different route parameters and a macro taking both would carry a parameter pair where one is always `none`. #} {# Closed lookup, like every other one here. `{ }` on `Status` is a lie — an enum is a list of permitted spellings, not an object — and the group heading above it should not be the only thing saying so. #} {% set KIND_ICON = {"object": "braces", "enum": "list"} %} {% macro model_link(request, route, model, target, active=false, query="") -%} {%- set href = url_for(request, route, model_slug=model.slug) ~ ("?q=" ~ query | urlencode if query else "") -%} {# `title` because this is the one row that genuinely does not fit. FastAPI names a form body after the route that declared it — `Body_tasks_update_tasks__task_id__edit_post` is 43 characters — and no sidebar width worth having accommodates that. Truncation is the right answer; being unable to read the whole name anywhere is not. #} {{ sidebar_item(model.name, href, active=active, icon_name=KIND_ICON.get(model.kind, "braces"), title=model.name, hx_get=href, hx_target="#" ~ target, hx_swap="outerHTML", hx_push_url="true") }} {%- endmacro %} {# facts(rows) — label/value pairs: who you are signed in as, what a response carried. A wrapping line rather than a stack of `item()` rows. These are three or four short values, and one feed row each cost 74px apiece — enough to push the operation below the fold on the one panel that has to stay visible while the rest of the page is read. Wrapping keeps that honest when a value is long: nothing is truncated, it takes the next line. `description_list(layout="inline")`: a `