Skip to content

Commit 7f7211e

Browse files
committed
Get application name from config, rename config dependency
1 parent 3679c94 commit 7f7211e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/http_app/dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
from http_app import context
33

44

5-
def app_config() -> AppConfig:
5+
def get_app_config() -> AppConfig:
66
return context.app_config.get()

src/http_app/routes/auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer, SecurityScopes
66

77
from common import AppConfig
8-
from http_app.dependencies import app_config
8+
from http_app.dependencies import get_app_config
99

1010

1111
class MissingAuthorizationServerException(HTTPException):
@@ -26,15 +26,15 @@ def __init__(self):
2626
super().__init__(status_code=status.HTTP_401_UNAUTHORIZED, detail="Requires authentication")
2727

2828

29-
def _jwks_client(config: Annotated[AppConfig, Depends(app_config)]) -> jwt.PyJWKClient:
29+
def _jwks_client(config: Annotated[AppConfig, Depends(get_app_config)]) -> jwt.PyJWKClient:
3030
if not config.AUTH.JWKS_URL:
3131
raise MissingAuthorizationServerException()
3232
return jwt.PyJWKClient(config.AUTH.JWKS_URL)
3333

3434

3535
async def decode_jwt(
3636
security_scopes: SecurityScopes,
37-
config: AppConfig = Depends(app_config),
37+
config: AppConfig = Depends(get_app_config),
3838
jwks_client: jwt.PyJWKClient = Depends(_jwks_client),
3939
token: Optional[HTTPAuthorizationCredentials] = Depends(HTTPBearer()),
4040
):

src/http_app/routes/docs_ws.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import json
2+
from typing import Annotated
23

34
import pydantic_asyncapi as pa
45
from fastapi import APIRouter
6+
from fastapi.params import Depends
57
from starlette.responses import HTMLResponse
68

9+
from common import AppConfig
710
from common.asyncapi import get_schema
11+
from http_app.dependencies import get_app_config
812

913
router = APIRouter(prefix="/docs/ws")
1014

@@ -32,6 +36,7 @@ def asyncapi_raw() -> pa.v3.AsyncAPI:
3236
# https://github.com/asyncapi/asyncapi-react/blob/v2.5.0/docs/usage/standalone-bundle.md
3337
@router.get("", include_in_schema=False)
3438
async def get_asyncapi_html(
39+
app_config: Annotated[AppConfig, Depends(get_app_config)],
3540
sidebar: bool = True,
3641
info: bool = True,
3742
servers: bool = True,
@@ -40,7 +45,6 @@ async def get_asyncapi_html(
4045
schemas: bool = True,
4146
errors: bool = True,
4247
expand_message_examples: bool = False,
43-
title: str = "Websocket",
4448
) -> HTMLResponse:
4549
"""Generate HTML for displaying an AsyncAPI document."""
4650
config = {
@@ -74,7 +78,7 @@ async def get_asyncapi_html(
7478
<head>
7579
"""
7680
f"""
77-
<title>{title} AsyncAPI</title>
81+
<title>{app_config.APP_NAME} AsyncAPI</title>
7882
"""
7983
"""
8084
<link rel="icon" href="https://www.asyncapi.com/favicon.ico">

0 commit comments

Comments
 (0)