From d695c1e521ead73f5a6842d05754e32e890187cc Mon Sep 17 00:00:00 2001 From: timonrieger Date: Sat, 26 Apr 2025 15:58:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20"Global=20Responses"=20sec?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/advanced/additional-responses.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/en/docs/advanced/additional-responses.md b/docs/en/docs/advanced/additional-responses.md index 03d48c2a7..39453a063 100644 --- a/docs/en/docs/advanced/additional-responses.md +++ b/docs/en/docs/advanced/additional-responses.md @@ -191,6 +191,20 @@ But if you have specified a custom response class with `None` as its media type, /// +## Global Responses + +You can also register responses at the application level. +This automatically adds the specified response models to every endpoint, without needing to define them individually. +Use the same syntax as demonstrated above. + +```Python +class MyErrorModel(BaseModel): + message: str + code: str + +app = FastAPI(responses={"default": {"model": MyErrorModel, "description": "Error response"}}) +``` + ## Combining information You can also combine response information from multiple places, including the `response_model`, `status_code`, and `responses` parameters.