mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2026-02-25 02:20:17 +00:00
✨ api: add SETTINGS.show_api_docs
This commit is contained in:
parent
30d1c5fba9
commit
1eab05a6ea
2 changed files with 12 additions and 9 deletions
2
api/.vscode/launch.json
vendored
2
api/.vscode/launch.json
vendored
|
|
@ -21,7 +21,7 @@
|
|||
"${workspaceFolder}/advent22_api"
|
||||
],
|
||||
"env": {
|
||||
"WEBDAV__CACHE_TTL": "30"
|
||||
"ADVENT22__WEBDAV__CACHE_TTL": "30"
|
||||
},
|
||||
"justMyCode": true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
|
|
@ -62,29 +62,32 @@ class Settings(BaseSettings):
|
|||
#####
|
||||
|
||||
production_mode: bool = False
|
||||
show_api_docs: bool = Field(
|
||||
default_factory=lambda data: not data["production_mode"]
|
||||
)
|
||||
ui_directory: str = "/opt/advent22/ui"
|
||||
|
||||
#####
|
||||
# openapi settings
|
||||
#####
|
||||
|
||||
def __dev_value[T](self, value: T) -> T | None:
|
||||
if self.production_mode:
|
||||
return None
|
||||
|
||||
def __api_docs[T](self, value: T) -> T | None:
|
||||
if self.show_api_docs:
|
||||
return value
|
||||
|
||||
return None
|
||||
|
||||
@property
|
||||
def openapi_url(self) -> str | None:
|
||||
return self.__dev_value("/api/openapi.json")
|
||||
return self.__api_docs("/api/openapi.json")
|
||||
|
||||
@property
|
||||
def docs_url(self) -> str | None:
|
||||
return self.__dev_value("/api/docs")
|
||||
return self.__api_docs("/api/docs")
|
||||
|
||||
@property
|
||||
def redoc_url(self) -> str | None:
|
||||
return self.__dev_value("/api/redoc")
|
||||
return self.__api_docs("/api/redoc")
|
||||
|
||||
#####
|
||||
# webdav settings
|
||||
|
|
|
|||
Loading…
Reference in a new issue