diff --git a/docs/user-guide/configuration.md b/docs/user-guide/configuration.md index 10cb4e9c..02a2dd30 100644 --- a/docs/user-guide/configuration.md +++ b/docs/user-guide/configuration.md @@ -124,6 +124,7 @@ The application is configurable via environment variables. "^/$": ["GET"], "^/api.html$": ["GET"], "^/api$": ["GET"], + "^/conformance$": ["GET"], "^/docs/oauth2-redirect": ["GET"], "^/healthz": ["GET"] } @@ -143,9 +144,9 @@ The application is configurable via environment variables. : Path of OpenAPI specification, used for augmenting spec response with auth configuration - **Type:** string or null - **Required:** No, defaults to `null` (disabled) - **Example:** `/api` + **Type:** string or null + **Required:** No, defaults to `/api` + **Example:** `''` (disabled) ### `OPENAPI_AUTH_SCHEME_NAME` @@ -175,9 +176,9 @@ The application is configurable via environment variables. : Path of Swagger UI, used to indicate that a custom Swagger UI should be hosted, typically useful when providing accompanying `SWAGGER_UI_INIT_OAUTH` arguments - **Type:** string or null - **Required:** No, defaults to `null` (disabled) - **Example:** `/api.html` + **Type:** string or null + **Required:** No, defaults to `/api.html` + **Example:** `''` (disabled) ### `SWAGGER_UI_INIT_OAUTH` diff --git a/src/stac_auth_proxy/app.py b/src/stac_auth_proxy/app.py index a81c44ac..b497c0db 100644 --- a/src/stac_auth_proxy/app.py +++ b/src/stac_auth_proxy/app.py @@ -80,18 +80,25 @@ async def lifespan(app: FastAPI): # Handlers (place catch-all proxy handler last) # - if settings.swagger_ui_endpoint: - assert ( - settings.openapi_spec_endpoint - ), "openapi_spec_endpoint must be set when using swagger_ui_endpoint" + # If we have customized Swagger UI Init settings (e.g. a provided client_id) + # then we need to serve our own Swagger UI in place of the upstream's. This requires + # that we know the Swagger UI endpoint and the OpenAPI spec endpoint. + if all( + [ + settings.swagger_ui_endpoint, + settings.openapi_spec_endpoint, + settings.swagger_ui_init_oauth, + ] + ): app.add_route( settings.swagger_ui_endpoint, SwaggerUI( - openapi_url=settings.openapi_spec_endpoint, + openapi_url=settings.openapi_spec_endpoint, # type: ignore init_oauth=settings.swagger_ui_init_oauth, ).route, include_in_schema=False, ) + if settings.healthz_prefix: app.include_router( HealthzHandler(upstream_url=str(settings.upstream_url)).router, diff --git a/src/stac_auth_proxy/config.py b/src/stac_auth_proxy/config.py index e0a4349e..d610420c 100644 --- a/src/stac_auth_proxy/config.py +++ b/src/stac_auth_proxy/config.py @@ -57,10 +57,14 @@ class Settings(BaseSettings): enable_compression: bool = True # OpenAPI / Swagger UI - openapi_spec_endpoint: Optional[str] = Field(pattern=_PREFIX_PATTERN, default=None) + openapi_spec_endpoint: Optional[str] = Field( + pattern=_PREFIX_PATTERN, default="/api" + ) openapi_auth_scheme_name: str = "oidcAuth" openapi_auth_scheme_override: Optional[dict] = None - swagger_ui_endpoint: Optional[str] = None + swagger_ui_endpoint: Optional[str] = Field( + pattern=_PREFIX_PATTERN, default="/api.html" + ) swagger_ui_init_oauth: dict = Field(default_factory=dict) # Auth @@ -70,6 +74,7 @@ class Settings(BaseSettings): r"^/$": ["GET"], r"^/api.html$": ["GET"], r"^/api$": ["GET"], + r"^/conformance$": ["GET"], r"^/docs/oauth2-redirect": ["GET"], r"^/healthz": ["GET"], }