app
FastAPI application factory for the patient-data API.
Module
Functions
build_openapi
def build_openapi(app: FastAPI) ‑> dict[str, typing.Any]:Build the OpenAPI document, adding what the route signatures cannot express.
Two additions on top of FastAPI's generation:
- the
EligibilityCriterionfamily schemas. They are real Pydantic models (CRITERION_VARIANTS) but no route returns one, so nothing would otherwise pull them intocomponents. They are advertised on the base schema asx-variantsrather than as aoneOf: several overlap, and a family added later must still validate against the base. ScanImageManifestandScanSegmentationIndex, which describe files inside the scan-image archive rather than any response body.
Neither is reachable from a path by ordinary means, so both are pointed at by
$ref objects — the variants from x-variants/x-family-variants here, the
two archive members from the scan-image route's x-archive-members. A bare
reference string in an extension is invisible to a tool that walks $refs,
which is how a bundler or client generator decides a schema is dead and prunes
it.
Existing schemas are never overwritten, so FastAPI stays authoritative for everything it already generated.
Arguments
app: The application whose routes the document is built from.
Returns The OpenAPI document.
create_app
def create_app( repository: PatientDataRepository, *, verifier: JWTVerifier, allowed_origins: list[str] | None = None, activity_repository: ActivityRepository | None = None,) ‑> fastapi.applications.FastAPI:Build the patient-data API app bound to a repository and verifier.
Arguments
repository: The data-access implementation handlers depend on.verifier: The JWT verifier the auth dependency uses to authenticate requests.allowed_origins: Browser origins permitted to read the API cross-origin via CORS (the Trials Web App's origin). When empty or None no CORS headers are sent, so cross-origin browser reads are disallowed.activity_repository: The activity domain's data-access implementation. Defaults toPrefectActivityRepository()when omitted.
Returns A configured FastAPI application.
dump_openapi_yaml
def dump_openapi_yaml(document: dict[str, Any]) ‑> str:Render an OpenAPI document as YAML.
Shared by the /openapi.yaml route and by
dev-scripts/dump_patient_api_openapi.py, so the served document and the
committed copy cannot differ in rendering — only a content difference should
ever show up in a diff of the two.
Arguments
document: The document to render (app.openapi()).
Returns The YAML text, with every multi-line description as a literal block.