From 78d1336cbb85d26154b73e9fe32ba7d4a5385766 Mon Sep 17 00:00:00 2001 From: Alex Couper Date: Thu, 23 May 2024 23:53:54 +0000 Subject: [PATCH] Add better docstring --- fastapi/applications.py | 104 ++++++++++++++++++++++++++++++++++++---- fastapi/routing.py | 104 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 192 insertions(+), 16 deletions(-) diff --git a/fastapi/applications.py b/fastapi/applications.py index acd60899b..cda509bb9 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -1716,7 +1716,18 @@ class FastAPI(Starlette): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -2093,7 +2104,18 @@ class FastAPI(Starlette): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -2475,7 +2497,18 @@ class FastAPI(Starlette): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -2857,7 +2890,18 @@ class FastAPI(Starlette): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -3234,7 +3278,18 @@ class FastAPI(Starlette): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -3611,7 +3666,18 @@ class FastAPI(Starlette): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -3988,7 +4054,18 @@ class FastAPI(Starlette): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -4370,7 +4447,18 @@ class FastAPI(Starlette): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, diff --git a/fastapi/routing.py b/fastapi/routing.py index afbcd04ee..6796dbe5e 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -1576,7 +1576,18 @@ class APIRouter(routing.Router): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ), ] = None, include_in_schema: Annotated[ bool, @@ -1957,7 +1968,18 @@ class APIRouter(routing.Router): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -2343,7 +2365,18 @@ class APIRouter(routing.Router): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -2729,7 +2762,18 @@ class APIRouter(routing.Router): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -3110,7 +3154,18 @@ class APIRouter(routing.Router): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -3491,7 +3546,18 @@ class APIRouter(routing.Router): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -3877,7 +3943,18 @@ class APIRouter(routing.Router): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool, @@ -4263,7 +4340,18 @@ class APIRouter(routing.Router): ), ] = False, response_model_context: Annotated[ - Optional[dict], Doc("Context to be used when encoding the response model.") + Optional[Dict[str, Any]], Doc( + """ + Additional context to pass to Pydantic when creating the response. + + This will be passed in as serialization context to the response model. + + Note: This feature is a noop on pydantic < 2.7.2 + + Read more about serialization context in the + [Pydantic documentation](https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context) + """ + ) ] = None, include_in_schema: Annotated[ bool,