hide openapi, docs and redoc in production mode
This commit is contained in:
parent
9063ebe93a
commit
e83f56a932
1 changed files with 21 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue