From e83f56a932831f3886027a82c197586cc3ec57e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 21 Sep 2023 00:56:25 +0200 Subject: [PATCH] hide openapi, docs and redoc in production mode --- api/advent22_api/core/settings.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/api/advent22_api/core/settings.py b/api/advent22_api/core/settings.py index 65737f4..92392c4 100644 --- a/api/advent22_api/core/settings.py +++ b/api/advent22_api/core/settings.py @@ -1,6 +1,10 @@ +from typing import TypeVar + from pydantic import BaseModel from pydantic_settings import BaseSettings, SettingsConfigDict +T = TypeVar("T") + class DavSettings(BaseModel): """ @@ -49,9 +53,23 @@ class Settings(BaseSettings): # openapi settings ##### - openapi_url: str = "/openapi.json" - docs_url: str | None = None if production_mode else "/docs" - redoc_url: str | None = None if production_mode else "/redoc" + def __dev_value(self, value: T) -> T | None: + if self.production_mode: + return None + + return value + + @property + def openapi_url(self) -> str | None: + return self.__dev_value("/api/openapi.json") + + @property + def docs_url(self) -> str | None: + return self.__dev_value("/api/docs") + + @property + def redoc_url(self) -> str | None: + return self.__dev_value("/api/redoc") ##### # webdav settings