4545 status_code = status .HTTP_201_CREATED ,
4646 summary = "Creates a new Player" ,
4747 tags = ["Players" ],
48+ responses = {
49+ 422 : {"description" : "Unprocessable Entity - request body validation failed" }
50+ },
4851)
4952async def post_async (
5053 player_model : Annotated [PlayerRequestModel , Body (...)],
@@ -64,6 +67,8 @@ async def post_async(
6467
6568 Raises:
6669 HTTPException: HTTP 409 Conflict error if the Player already exists.
70+ HTTPException: HTTP 422 Unprocessable Entity if request body fails Pydantic
71+ validation (missing or invalid required fields).
6772 """
6873 existing = await player_service .retrieve_by_squad_number_async (
6974 async_session , player_model .squad_number
@@ -188,6 +193,9 @@ async def get_by_squad_number_async(
188193 status_code = status .HTTP_204_NO_CONTENT ,
189194 summary = "Updates an existing Player" ,
190195 tags = ["Players" ],
196+ responses = {
197+ 422 : {"description" : "Unprocessable Entity - request body validation failed" }
198+ },
191199)
192200async def put_async (
193201 squad_number : Annotated [int , Path (..., title = SQUAD_NUMBER_TITLE )],
@@ -206,9 +214,12 @@ async def put_async(
206214 Raises:
207215 HTTPException: HTTP 400 Bad Request if squad_number in the request body does
208216 not match the path parameter. The path parameter is the authoritative source
209- of identity on PUT; a mismatch makes the request ambiguous.
217+ of identity on PUT; a mismatch makes the request semantically ambiguous (not
218+ a validation failure).
210219 HTTPException: HTTP 404 Not Found error if the Player with the specified Squad
211220 Number does not exist.
221+ HTTPException: HTTP 422 Unprocessable Entity if request body fails Pydantic
222+ validation (missing or invalid required fields).
212223 """
213224 if player_model .squad_number != squad_number :
214225 raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST )
0 commit comments