-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add get_version endpoint to identify REST API current version
- Loading branch information
1 parent
ac65ea8
commit c2aaca6
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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__) |