diff --git a/fastapi/routing.py b/fastapi/routing.py index 5f9eda87c6..c0cc36296d 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -1412,12 +1412,8 @@ class APIRouter(routing.Router): "openapi_extra": openapi_extra, "generate_unique_id_function": current_generate_unique_id, } - if ( - "strict_content_type" in route_init_params - or any( - p.kind == inspect.Parameter.VAR_KEYWORD - for p in route_init_params.values() - ) + if "strict_content_type" in route_init_params or any( + p.kind == inspect.Parameter.VAR_KEYWORD for p in route_init_params.values() ): route_kwargs["strict_content_type"] = get_value_or_default( strict_content_type, self.strict_content_type diff --git a/tests/test_custom_route_class.py b/tests/test_custom_route_class.py index 49ce7768a4..214aaae89d 100644 --- a/tests/test_custom_route_class.py +++ b/tests/test_custom_route_class.py @@ -1,6 +1,6 @@ -from collections.abc import Sequence +from collections.abc import Callable, Sequence from enum import Enum -from typing import Any, Callable +from typing import Any import pytest from fastapi import APIRouter, FastAPI, params @@ -128,6 +128,7 @@ def test_openapi_schema(): } ) + def test_custom_api_route_without_strict_content_type(): """ Regression test for #15503: @@ -212,6 +213,7 @@ def test_custom_api_route_without_strict_content_type(): assert response.status_code == 200 assert response.json() == {"ok": True} + def test_custom_api_route_with_kwargs(): """ Custom APIRoute classes using **kwargs should still receive @@ -219,7 +221,9 @@ def test_custom_api_route_with_kwargs(): """ class KwargsRoute(APIRoute): - def __init__(self, path: str, endpoint: Callable[..., Any], **kwargs: Any) -> None: + def __init__( + self, path: str, endpoint: Callable[..., Any], **kwargs: Any + ) -> None: super().__init__(path, endpoint, **kwargs) app_kwargs = FastAPI()