Справочник: dependency¶
Всё, чем эндпоинт помечается как версионированный. Импортируется из корня пакета:
versioning¶
fastapi_easy_versioning.versioning
¶
versioning(
*, until: int | None = None
) -> VersioningSupport
Dependency factory to mark endpoints as versioned.
Marking is opt-in: an endpoint without this dependency is invisible to
versioning and stays only in the version that declares it. Inheritance itself
is performed by
VersioningMiddleware.
Usage
@router.get("/path", dependencies=[Depends(versioning(until=...))])
def endpoint():
...
# Apply versioning to all endpoints in the router
router = APIRouter(dependencies=[Depends(versioning(until=...))])
router.add_api_route("/path", endpoint)
# Or inject versioning metadata into the endpoint
@router.get("/path")
def endpoint(data: Annotated[VersionInfo, Depends(versioning())]):
from_version = data.origin
end_supported_version = data.until
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
until
|
int | None
|
The last version the endpoint is available
in, inclusive. If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
VersioningSupport |
VersioningSupport
|
A dependency callable compatible with FastAPI's |
VersioningSupport¶
fastapi_easy_versioning.VersioningSupport
¶
Callable dependency marking an endpoint as versioned.
Instances are produced by versioning
and are meant to be passed to Depends(); construct them through that
factory rather than directly. An instance only carries the declared until
and is never mutated — the resolved per-route metadata lives in a registry on
the version sub-app, so the same instance can safely be shared by a router
included into several versions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
until
|
int | None
|
The last supported version, as declared at
the call site. Defaults to |
None
|
VersionInfo¶
fastapi_easy_versioning.VersionInfo
¶
Bases: NamedTuple
Resolved versioning metadata of an endpoint.
Yielded by the versioning dependency
when it is injected into an endpoint signature. Both fields are resolved by
the middleware against the actually mounted versions, so until is a
concrete version number even when the endpoint declared none.