Application¶
rn_forge.fastapi.app
¶
Construct FastAPI applications with the standard rn-forge adapters.
AppConfig(*, registry=default_registry(), checks=dict[str, Check](), required_checks=(), check_timeout=2.0, realm=None, tracing=True, log=None, liveness_path=LIVENESS_PATH, readiness_path=READINESS_PATH, legacy_liveness_path=LEGACY_LIVENESS_PATH, max_body_bytes=1048576, api_catalog=True, security_headers=True, hsts=False, cors=None)
dataclass
¶
The standard adapter configuration for :class:FastApiApp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
ProblemRegistry
|
Domain exception mappings. Register application exceptions before constructing this configuration. |
default_registry()
|
checks
|
Mapping[str, Check]
|
Readiness checks, keyed by their wire-visible names. |
dict[str, Check]()
|
required_checks
|
Collection[str]
|
Check names whose failure returns 503 from the readiness path. |
()
|
check_timeout
|
float | None
|
Maximum seconds a single readiness check may run. |
2.0
|
realm
|
str | None
|
Optional Bearer authentication realm for problem responses. |
None
|
tracing
|
bool
|
Instrument the application with
|
True
|
log
|
Log | None
|
Optional sink for |
None
|
liveness_path
|
str
|
The liveness path. |
LIVENESS_PATH
|
readiness_path
|
str
|
The readiness path. |
READINESS_PATH
|
legacy_liveness_path
|
str | None
|
An alias of liveness_path, marked deprecated
in the OpenAPI document. |
LEGACY_LIVENESS_PATH
|
max_body_bytes
|
int | None
|
The largest request body admitted, per RFC 9110
§15.5.14. |
1048576
|
api_catalog
|
bool
|
Serve RFC 9727's |
True
|
security_headers
|
bool
|
Install the OWASP REST Security Cheat Sheet response
headers ( |
True
|
hsts
|
bool
|
Also add |
False
|
cors
|
CorsPolicy | None
|
A CORS policy to install, or |
None
|
FastApiApp(config=None, *, routers=(), lifespan=None, title='FastAPI', description='', version='0.1.0', **fastapi_kwargs)
¶
Bases: FastAPI
A :class:fastapi.FastAPI with the standard rn-forge wiring installed.
FastAPI is inherited rather than wrapped, so @app.get(),
add_middleware and the full :class:~fastapi.FastAPI constructor
keyword set remain available.
Initialize the application and install the standard adapters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AppConfig | None
|
Standard adapter configuration. Defaults to
|
None
|
routers
|
Sequence[APIRouter]
|
Application routers to include in order. |
()
|
lifespan
|
Lifespan[FastAPI] | None
|
Application startup and shutdown hook. |
None
|
title
|
str
|
OpenAPI document title. |
'FastAPI'
|
description
|
str
|
OpenAPI document description. |
''
|
version
|
str
|
OpenAPI document version. |
'0.1.0'
|
**fastapi_kwargs
|
Any
|
Forwarded to the :class: |
{}
|
openapi()
¶
Return the OpenAPI document, repaired for problem-response accuracy.
Builds through super().openapi() — which caches the document the
way plain :class:~fastapi.FastAPI does — and repairs the cached
document exactly once. A consumer subclass adds further repairs by
overriding this method and calling super().openapi() first.