Skip to content

Commit 4697be3

Browse files
nanotaboadaclaude
andcommitted
docs(routes): adopt 422 Unprocessable Entity for validation errors (#568)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f1fd42e commit 4697be3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ This project uses famous football coaches as release codenames, following an A-Z
4646

4747
### Changed
4848

49+
- `routes/player_route.py`: explicitly document `422 Unprocessable Entity` for
50+
payload validation errors on POST and PUT endpoints — added `responses={422:
51+
...}` to route decorators (OpenAPI schema) and `Raises:` entries to
52+
docstrings; clarifies the 422 (Pydantic validation failure) vs 400 (semantic
53+
ambiguity) distinction (#568)
54+
4955
### Fixed
5056

5157
### Removed

routes/player_route.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
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
)
4952
async 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
)
192200
async 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

Comments
 (0)