feat(api): 支持 x-api-version (#29)
* feat(relationship): support legacy-compatible response format * feat(score): add support for legacy score response format in API * fix(score): avoid missing greenlet * fix(score): fix missing field for model validation * feat(user): apply legacy score format for user * feat(api): use `int` to hint `APIVersion`
This commit is contained in:
16
app/dependencies/api_version.py
Normal file
16
app/dependencies/api_version.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import Depends, Header
|
||||
|
||||
|
||||
def get_api_version(version: int | None = Header(None, alias="x-api-version")) -> int:
|
||||
if version is None:
|
||||
return 0
|
||||
if version < 1:
|
||||
raise ValueError
|
||||
return version
|
||||
|
||||
|
||||
APIVersion = Annotated[int, Depends(get_api_version)]
|
||||
Reference in New Issue
Block a user