Browse Source

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.
pull/15013/head
Anandesh Sharma 5 months ago
parent
commit
89e5a83b1d
  1. 13
      fastapi/applications.py

13
fastapi/applications.py

@ -1,3 +1,4 @@
import warnings
from collections.abc import Awaitable, Callable, Coroutine, Sequence from collections.abc import Awaitable, Callable, Coroutine, Sequence
from enum import Enum from enum import Enum
from typing import ( from typing import (
@ -14,7 +15,11 @@ from fastapi.exception_handlers import (
request_validation_exception_handler, request_validation_exception_handler,
websocket_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.logger import logger
from fastapi.middleware.asyncexitstack import AsyncExitStackMiddleware from fastapi.middleware.asyncexitstack import AsyncExitStackMiddleware
from fastapi.openapi.docs import ( 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'" assert self.version, "A version must be provided for OpenAPI, e.g.: '2.1.0'"
# TODO: remove when discarding the openapi_prefix parameter # TODO: remove when discarding the openapi_prefix parameter
if openapi_prefix: if openapi_prefix:
logger.warning( warnings.warn(
'"openapi_prefix" has been deprecated in favor of "root_path", which ' '"openapi_prefix" has been deprecated in favor of "root_path", which '
"follows more closely the ASGI standard, is simpler, and more " "follows more closely the ASGI standard, is simpler, and more "
"automatic. Check the docs at " "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[ self.webhooks: Annotated[
routing.APIRouter, routing.APIRouter,

Loading…
Cancel
Save