Skip to content

Commit b021dac

Browse files
authored
log warning for default title, description (#943)
1 parent b8b8ebf commit b021dac

3 files changed

Lines changed: 68 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- Log warning when default API title, description, landing ID, or version are used to encourage proper API configuration ([#943](https://github.com/stac-utils/stac-fastapi/issues/943))
8+
59
## [6.3.2] - 2026-06-27
610

711
### Fixed

stac_fastapi/types/stac_fastapi/types/config.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
"""stac_fastapi.types.config module."""
22

3+
import logging
34
from typing import Self
45

56
from pydantic import model_validator
67
from pydantic_settings import BaseSettings, SettingsConfigDict
78

9+
logger = logging.getLogger(__name__)
10+
811

912
class ApiSettings(BaseSettings):
1013
"""ApiSettings.
@@ -43,12 +46,30 @@ class ApiSettings(BaseSettings):
4346

4447
@model_validator(mode="after")
4548
def check_incompatible_options(self) -> Self:
46-
"""Check for incompatible options."""
49+
"""Check for incompatible options and warn about default values."""
4750
if self.enable_response_models and self.enable_direct_response:
4851
raise ValueError(
4952
"`enable_reponse_models` and `enable_direct_response` options are incompatible" # noqa: E501
5053
)
5154

55+
defaults_used = []
56+
if self.stac_fastapi_title == "stac-fastapi":
57+
defaults_used.append("stac_fastapi_title")
58+
if self.stac_fastapi_description == "stac-fastapi":
59+
defaults_used.append("stac_fastapi_description")
60+
if self.stac_fastapi_landing_id == "stac-fastapi":
61+
defaults_used.append("stac_fastapi_landing_id")
62+
if self.stac_fastapi_version == "0.1":
63+
defaults_used.append("stac_fastapi_version")
64+
65+
if defaults_used:
66+
logger.warning(
67+
"Using default values for %s. This may impact API discoverability. "
68+
"Please configure these values via environment variables or settings. "
69+
"See https://stac-utils.github.io/stac-fastapi/tips-and-tricks/#set-api-title-description-and-version", # noqa: E501
70+
", ".join(defaults_used),
71+
)
72+
5273
return self
5374

5475

stac_fastapi/types/tests/test_config.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""test config classes."""
22

3+
import logging
4+
35
import pytest
46
from pydantic import ValidationError
57

@@ -27,3 +29,43 @@ def test_incompatible_options():
2729
enable_response_models=True,
2830
enable_direct_response=True,
2931
)
32+
33+
34+
def test_default_values_warning(caplog):
35+
"""test that a warning is logged when using default values."""
36+
with caplog.at_level(logging.WARNING):
37+
ApiSettings()
38+
39+
assert "Using default values for" in caplog.text
40+
assert "stac_fastapi_title" in caplog.text
41+
assert "stac_fastapi_description" in caplog.text
42+
assert "stac_fastapi_landing_id" in caplog.text
43+
assert "stac_fastapi_version" in caplog.text
44+
45+
46+
def test_custom_values_no_warning(caplog):
47+
"""test that no warning is logged when using custom values."""
48+
with caplog.at_level(logging.WARNING):
49+
ApiSettings(
50+
stac_fastapi_title="My API",
51+
stac_fastapi_description="My API Description",
52+
stac_fastapi_landing_id="my-api",
53+
stac_fastapi_version="1.0.0",
54+
)
55+
56+
assert "Using default values for" not in caplog.text
57+
58+
59+
def test_partial_custom_values_warning(caplog):
60+
"""test that a warning is logged only for remaining default values."""
61+
with caplog.at_level(logging.WARNING):
62+
ApiSettings(
63+
stac_fastapi_title="My API",
64+
stac_fastapi_description="My API Description",
65+
)
66+
67+
assert "Using default values for" in caplog.text
68+
assert "stac_fastapi_landing_id" in caplog.text
69+
assert "stac_fastapi_version" in caplog.text
70+
assert "stac_fastapi_title" not in caplog.text
71+
assert "stac_fastapi_description" not in caplog.text

0 commit comments

Comments
 (0)