Skip to content

Commit 814145d

Browse files
committed
fix: prevent double-declaration of openapi endpoint
1 parent 7836434 commit 814145d

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/stac_auth_proxy/app.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@ def create_app(settings: Optional[Settings] = None) -> FastAPI:
3131

3232
proxy = ReverseProxy(upstream=str(settings.upstream_url))
3333

34+
openapi_handler = OpenApiSpecHandler(
35+
proxy=proxy, oidc_config_url=str(settings.oidc_discovery_url)
36+
).dispatch
37+
3438
# Endpoints that are explicitely marked private
3539
for path, methods in settings.private_endpoints.items():
3640
app.add_api_route(
3741
path,
38-
proxy.stream,
42+
(
43+
proxy.stream
44+
if not path == settings.openapi_spec_endpoint
45+
else openapi_handler
46+
),
3947
methods=methods,
4048
dependencies=[Depends(auth_scheme)],
4149
)
@@ -44,20 +52,14 @@ def create_app(settings: Optional[Settings] = None) -> FastAPI:
4452
for path, methods in settings.public_endpoints.items():
4553
app.add_api_route(
4654
path,
47-
proxy.stream,
55+
(
56+
proxy.stream
57+
if not path == settings.openapi_spec_endpoint
58+
else openapi_handler
59+
),
4860
methods=methods,
4961
)
5062

51-
# Endpoint with special OpenAPI transformation functionality
52-
if settings.openapi_spec_endpoint:
53-
app.add_api_route(
54-
settings.openapi_spec_endpoint,
55-
OpenApiSpecHandler(
56-
proxy=proxy, oidc_config_url=str(settings.oidc_discovery_url)
57-
).dispatch,
58-
methods=["GET"],
59-
)
60-
6163
# Catchall for remainder of the endpoints
6264
app.add_api_route(
6365
"/{path:path}",

0 commit comments

Comments
 (0)