Bases: BaseSettings
ApiSettings.
Defines api configuration, potentially through environment variables.
See pydantic-docs.helpmanual.io/usage/settings/.
Attributes:
environment: name of the environment (ex. dev/prod).
debug: toggles debug mode.
forbidden_fields: set of fields defined by STAC but not included in the database.
indexed_fields:
set of fields which are usually in item.properties but are indexed
as distinct columns in the database.
Source code in stac_fastapi/types/stac_fastapi/types/config.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 | class ApiSettings(BaseSettings):
"""ApiSettings.
Defines api configuration, potentially through environment variables.
See https://pydantic-docs.helpmanual.io/usage/settings/.
Attributes:
environment: name of the environment (ex. dev/prod).
debug: toggles debug mode.
forbidden_fields: set of fields defined by STAC but not included in the database.
indexed_fields:
set of fields which are usually in `item.properties` but are indexed
as distinct columns in the database.
"""
stac_fastapi_title: str = "stac-fastapi"
stac_fastapi_description: str = "stac-fastapi"
stac_fastapi_version: str = "0.1"
stac_fastapi_landing_id: str = "stac-fastapi"
app_host: str = "0.0.0.0"
app_port: int = 8000
reload: bool = True
# Enable Pydantic validation for output Response
enable_response_models: bool = False
# Enable direct `Response` from endpoint, skipping validation and serialization
enable_direct_response: bool = False
openapi_url: str = "/api"
docs_url: str = "/api.html"
root_path: str = ""
model_config = SettingsConfigDict(env_file=".env", extra="allow")
@model_validator(mode="after")
def check_incompatible_options(self) -> Self:
"""Check for incompatible options and warn about default values."""
if self.enable_response_models and self.enable_direct_response:
raise ValueError(
"`enable_reponse_models` and `enable_direct_response` options are incompatible" # noqa: E501
)
defaults_used = []
if self.stac_fastapi_title == "stac-fastapi":
defaults_used.append("stac_fastapi_title")
if self.stac_fastapi_description == "stac-fastapi":
defaults_used.append("stac_fastapi_description")
if self.stac_fastapi_landing_id == "stac-fastapi":
defaults_used.append("stac_fastapi_landing_id")
if self.stac_fastapi_version == "0.1":
defaults_used.append("stac_fastapi_version")
if defaults_used:
logger.warning(
"Using default values for %s. This may impact API discoverability. "
"Please configure these values via environment variables or settings. "
"See https://stac-utils.github.io/stac-fastapi/tips-and-tricks/#set-api-title-description-and-version", # noqa: E501
", ".join(defaults_used),
)
return self
|
check_incompatible_options
check_incompatible_options() -> Self
Check for incompatible options and warn about default values.
Source code in stac_fastapi/types/stac_fastapi/types/config.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 | @model_validator(mode="after")
def check_incompatible_options(self) -> Self:
"""Check for incompatible options and warn about default values."""
if self.enable_response_models and self.enable_direct_response:
raise ValueError(
"`enable_reponse_models` and `enable_direct_response` options are incompatible" # noqa: E501
)
defaults_used = []
if self.stac_fastapi_title == "stac-fastapi":
defaults_used.append("stac_fastapi_title")
if self.stac_fastapi_description == "stac-fastapi":
defaults_used.append("stac_fastapi_description")
if self.stac_fastapi_landing_id == "stac-fastapi":
defaults_used.append("stac_fastapi_landing_id")
if self.stac_fastapi_version == "0.1":
defaults_used.append("stac_fastapi_version")
if defaults_used:
logger.warning(
"Using default values for %s. This may impact API discoverability. "
"Please configure these values via environment variables or settings. "
"See https://stac-utils.github.io/stac-fastapi/tips-and-tricks/#set-api-title-description-and-version", # noqa: E501
", ".join(defaults_used),
)
return self
|