Skip to content

Commit

Permalink
Add openapi params for fern bearer auth, hide healthcheck from fern
Browse files Browse the repository at this point in the history
  • Loading branch information
nikochiko committed Aug 1, 2024
1 parent dc46d6c commit 1b5f46f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions auth/token_authentication.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -55,17 +57,22 @@ 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)):
...
```
"""

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
Expand All @@ -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"}},
)
2 changes: 1 addition & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 1b5f46f

Please sign in to comment.