diff --git a/src/narrativelog/main.py b/src/narrativelog/main.py index c5931fc..7b7a56e 100644 --- a/src/narrativelog/main.py +++ b/src/narrativelog/main.py @@ -10,6 +10,7 @@ find_messages, get_configuration, get_message, + get_version, ) app = fastapi.FastAPI() @@ -27,6 +28,7 @@ subapp.include_router(find_messages.router) subapp.include_router(get_configuration.router) subapp.include_router(get_message.router) +subapp.include_router(get_version.router) @subapp.get("/", response_class=fastapi.responses.HTMLResponse) diff --git a/src/narrativelog/routers/get_version.py b/src/narrativelog/routers/get_version.py new file mode 100644 index 0000000..c40c348 --- /dev/null +++ b/src/narrativelog/routers/get_version.py @@ -0,0 +1,27 @@ +__all__ = ["get_version"] + +import fastapi +import pydantic + +from .. import __version__ +from ..shared_state import SharedState, get_shared_state + +router = fastapi.APIRouter() + + +class Version(pydantic.BaseModel): + version: str = pydantic.Field(title="Current version of the REST API.") + + class Config: + orm_mode = True + from_attributes = True + + +@router.get("/version", response_model=Version) +@router.get("/version/", response_model=Version, include_in_schema=False) +async def get_version( + state: SharedState = fastapi.Depends(get_shared_state), +) -> Version: + """Get the current version of the package.""" + + return Version(version=__version__)