From 1eab05a6ea9f8d38e2e3f9e6dd78cf83df167033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Sun, 22 Feb 2026 12:06:16 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20api:=20add=20SETTINGS.show=5Fapi=5F?= =?UTF-8?q?docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/.vscode/launch.json | 2 +- api/advent22_api/core/settings.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 4ad13ab..924c9c3 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -21,7 +21,7 @@ "${workspaceFolder}/advent22_api" ], "env": { - "WEBDAV__CACHE_TTL": "30" + "ADVENT22__WEBDAV__CACHE_TTL": "30" }, "justMyCode": true } diff --git a/api/advent22_api/core/settings.py b/api/advent22_api/core/settings.py index a574b17..d4d9d39 100644 --- a/api/advent22_api/core/settings.py +++ b/api/advent22_api/core/settings.py @@ -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 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