Source code for fsh_lib.openapi
"""kiln's openapi-extension keys + their runtime constructor.
Routes the BE generates carry two custom extensions consumed by
the FE codegen layer:
* ``X_CACHE_KEY`` (``"x-cache-key"``) -- string identifying
the TanStack Query key root the FE should use for this route's
response cache. Only emitted on read routes (any GET, plus the
POST search endpoints that are semantically reads). Its
presence *is* the read signal: the FE generates ``useQuery`` /
``useSuspenseQuery`` wrappers for any GET or any route carrying
a cache key, and treats everything else as a mutation -- so no
separate "this is a query" extension is needed.
* ``X_RESOURCE`` (``"x-resource"``) -- the resource's *singular*
slug (the model's snake name, e.g. ``"task"`` for the ``tasks``
resource). Stamped on *every* CRUD route (reads and writes
alike, unlike ``X_CACHE_KEY``). It's the canonical resource
identity: the FE groups a resource's routes by it (to discover
the CRUD SDK fns), and derives the saved-view ``resource_type``
discriminator + default singular display label from it. The
plural cache namespace is the separate ``X_CACHE_KEY`` (e.g.
``"tasks"``); a read route carries both, which is how the FE
bridges its plural config key to this singular identity.
* ``X_AUTH_ROLE`` (``"x-auth-role"``) -- ``"login"`` /
``"validate"`` / ``"logout"`` on the three auth-router routes.
Lets the FE derive the auth SDK fns (and, off them, the session
+ credentials types) instead of naming them in fe.jsonnet.
:func:`construct_openapi_extra` builds a dict suitable for
FastAPI's ``openapi_extra=`` kwarg. Generated handlers call it
inline so the extension keys live in exactly one place (this
module). Hand-written handlers can use it the same way.
"""
from __future__ import annotations
X_CACHE_KEY = "x-cache-key"
X_RESOURCE = "x-resource"
X_AUTH_ROLE = "x-auth-role"