From 1b5f46f95f5138cc23669e3f08953917ad0b9b27 Mon Sep 17 00:00:00 2001 From: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Thu, 1 Aug 2024 18:28:42 +0530 Subject: [PATCH] Add openapi params for fern bearer auth, hide healthcheck from fern --- auth/token_authentication.py | 19 ++++++++++++++----- server.py | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/auth/token_authentication.py b/auth/token_authentication.py index 483e291b6..a1281faa7 100644 --- a/auth/token_authentication.py +++ b/auth/token_authentication.py @@ -1,3 +1,5 @@ +from typing import Any + from fastapi import Request from fastapi.exceptions import HTTPException from fastapi.openapi.models import HTTPBase as HTTPBaseModel, SecuritySchemeType @@ -55,7 +57,7 @@ class APIAuth(SecurityBase): ### Usage: ```python - api_auth = APIAuth(scheme_name="Bearer", description="Bearer $GOOEY_API_KEY") + api_auth = APIAuth(scheme_name="bearer", description="Bearer $GOOEY_API_KEY") @app.get("/api/users") def get_users(authenticated_user: AppUser = Depends(api_auth)): @@ -63,9 +65,14 @@ def get_users(authenticated_user: AppUser = Depends(api_auth)): ``` """ - def __init__(self, scheme_name: str, description: str): + def __init__( + self, scheme_name: str, description: str, openapi_extra: dict[str, Any] = None + ): self.model = HTTPBaseModel( - type=SecuritySchemeType.http, scheme=scheme_name, description=description + type=SecuritySchemeType.http, + scheme=scheme_name, + description=description, + **(openapi_extra or {}), ) self.scheme_name = scheme_name self.description = description @@ -88,7 +95,9 @@ def __call__(self, request: Request) -> AppUser: return authenticate_credentials(auth[1]) -auth_scheme = "Bearer" +auth_scheme = "bearer" api_auth_header = APIAuth( - scheme_name=auth_scheme, description=f"{auth_scheme} $GOOEY_API_KEY" + scheme_name=auth_scheme, + description=f"{auth_scheme} $GOOEY_API_KEY", + openapi_extra={"x-fern-bearer": {"name": "apiKey", "env": "GOOEY_API_KEY"}}, ) diff --git a/server.py b/server.py index 2a8744c2a..7879adab2 100644 --- a/server.py +++ b/server.py @@ -92,7 +92,7 @@ async def startup(): limiter.total_tokens = config("MAX_THREADS", default=limiter.total_tokens, cast=int) -@app.get("/", tags=["Misc"]) +@app.get("/", tags=["Misc"], openapi_extra={"x-fern-ignore": True}) async def health(): return "OK"