diff --git a/bento_lib/config/pydantic.py b/bento_lib/config/pydantic.py index eb7a47c..6c99436 100644 --- a/bento_lib/config/pydantic.py +++ b/bento_lib/config/pydantic.py @@ -10,6 +10,7 @@ __all__ = [ "CorsOriginsParsingEnvSettingsSource", "BentoBaseConfig", + "BentoFastAPIBaseConfig", ] @@ -59,3 +60,8 @@ def settings_customise_sources( dotenv_settings, file_secret_settings, ) + + +class BentoFastAPIBaseConfig(BentoBaseConfig): + service_docs_path: str = "/docs" + service_openapi_path: str = "/openapi.json" diff --git a/tests/test_config.py b/tests/test_config.py index da0957b..eef3e87 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,7 +1,7 @@ import logging import os import pytest -from bento_lib.config.pydantic import BentoBaseConfig +from bento_lib.config.pydantic import BentoBaseConfig, BentoFastAPIBaseConfig from bento_lib.service_info.helpers import build_service_info_from_pydantic_config @@ -27,6 +27,16 @@ def test_base_pydantic_config_env(): os.environ["CORS_ORIGINS"] = "" +def test_fastapi_pydantic_config(): + assert BentoFastAPIBaseConfig.model_validate(TEST_CONFIG_VALUES).service_docs_path == "/docs" + + try: + os.environ["SERVICE_DOCS_PATH"] = "/docs-alt" + assert BentoFastAPIBaseConfig.model_validate(TEST_CONFIG_VALUES).service_docs_path == "/docs-alt" + finally: + os.environ["SERVICE_DOCS_PATH"] = "" + + @pytest.mark.asyncio async def test_build_service_info_for_config(): # Make sure we can build service info from an instance of a Pydantic config with no validation errors