harbor run -t datacurve/fastapi-deprecation-response-headersharbor download datacurve/fastapi-deprecation-response-headersFastAPI currently treats deprecated=True as schema metadata only ("deprecated": true) and does not add runtime response signals. Extend routing so clients can reliably detect deprecations from HTTP responses.
Use standards-based headers:
DeprecationSunsetLinkdeprecated=True must emit Deprecation: true.sunset: datetime | None.sunset is set, emit Sunset in RFC 7231 date format.x-sunset (ISO 8601) in OpenAPI when present.deprecation_date: datetime | None.Deprecation: <RFC 7231 date> (not true).deprecation_date takes precedence over deprecated=True.x-deprecation-date (ISO 8601) in OpenAPI when present.successor_url: str | None.Link: <url>; rel="successor-version".x-successor-url in OpenAPI when present.DeprecationTrackingMiddleware in fastapi/middleware/deprecation.py.{"deprecated_hits": int, "sunset_hits": int}.deprecated=True or deprecation_date.sunset."http" scopes; skip others (for example, websocket).get_stats() (copy semantics) and reset_stats().Deprecation or Sunset, preserve it (case-insensitive check).Link, merge successor link by appending , <new_link> (RFC 8288 style list behavior).sunset, deprecation_date, successor_url) everywhere these routing and application APIs are exposed.deprecated parameter must also follow the same propagation and inheritance rules described below (it already exists on routes, routers, and include_router calls; ensure it propagates consistently with the new parameters).deprecated, sunset, deprecation_date, and successor_url):
include_router(...) parameters apply to omitted route values and override the included router's own defaults.add_api_route routes inherit router defaults when route-level values are omitted.FastAPI(...) constructor parameters serve as the outermost defaults and are inherited by all routes and included routers when no closer ancestor provides a value.