From 89e5a83b1d3126c13a9999e134dd7722817444e2 Mon Sep 17 00:00:00 2001 From: Anandesh Sharma Date: Fri, 27 Feb 2026 04:15:53 +0530 Subject: [PATCH] Use FastAPIDeprecationWarning for openapi_prefix deprecation The openapi_prefix parameter deprecation used logger.warning() which is inconsistent with the rest of the codebase that uses warnings.warn() with FastAPIDeprecationWarning. This makes the deprecation filterable with standard Python warning filters and consistent with other deprecations. --- fastapi/applications.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fastapi/applications.py b/fastapi/applications.py index e7e816c2e9..51f837b3db 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -1,3 +1,4 @@ +import warnings from collections.abc import Awaitable, Callable, Coroutine, Sequence from enum import Enum from typing import ( @@ -14,7 +15,11 @@ from fastapi.exception_handlers import ( request_validation_exception_handler, websocket_request_validation_exception_handler, ) -from fastapi.exceptions import RequestValidationError, WebSocketRequestValidationError +from fastapi.exceptions import ( + FastAPIDeprecationWarning, + RequestValidationError, + WebSocketRequestValidationError, +) from fastapi.logger import logger from fastapi.middleware.asyncexitstack import AsyncExitStackMiddleware from fastapi.openapi.docs import ( @@ -930,11 +935,13 @@ class FastAPI(Starlette): assert self.version, "A version must be provided for OpenAPI, e.g.: '2.1.0'" # TODO: remove when discarding the openapi_prefix parameter if openapi_prefix: - logger.warning( + warnings.warn( '"openapi_prefix" has been deprecated in favor of "root_path", which ' "follows more closely the ASGI standard, is simpler, and more " "automatic. Check the docs at " - "https://fastapi.tiangolo.com/advanced/sub-applications/" + "https://fastapi.tiangolo.com/advanced/sub-applications/", + category=FastAPIDeprecationWarning, + stacklevel=2, ) self.webhooks: Annotated[ routing.APIRouter,