Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): add FastAPI base config class with docs/OpenAPI paths #204

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bento_lib/config/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
__all__ = [
"CorsOriginsParsingEnvSettingsSource",
"BentoBaseConfig",
"BentoFastAPIBaseConfig",
]


Expand Down Expand Up @@ -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"
12 changes: 11 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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
Expand Down