Replace untyped dict request bodies with validated API models #6

Closed
opened 2026-08-23 22:37:28 +02:00 by kristofferopsahl · 1 comment
Collaborator

Finding

The write/solver endpoints accept raw dict bodies and manually coerce selected fields:

  • backend/web/main.py:1131 /api/squad
  • backend/web/main.py:1164 /api/autocomplete
  • backend/web/main.py:1237 /api/override

Malformed shapes can reach Python operations and produce 500s rather than structured 4xx responses (for example non-iterable picks, unhashable element IDs, missing element_id, non-list gws, or unexpected note types). Unknown fields and practical size limits are also unconstrained.

Suggested direction

  • Define Pydantic request models with typed IDs, bounded probabilities, bounded string lengths, list cardinality, uniqueness, and explicit extra-field policy.
  • Move request-shape validation out of endpoint business logic while keeping domain validation in rules/override code.
  • Add malformed-input and oversized-input tests for each endpoint.

Acceptance criteria

  • Invalid request shapes consistently return documented 4xx validation responses.
  • Endpoint functions receive typed, bounded values.
  • Valid current frontend requests behave unchanged.
## Finding The write/solver endpoints accept raw `dict` bodies and manually coerce selected fields: - `backend/web/main.py:1131` `/api/squad` - `backend/web/main.py:1164` `/api/autocomplete` - `backend/web/main.py:1237` `/api/override` Malformed shapes can reach Python operations and produce 500s rather than structured 4xx responses (for example non-iterable `picks`, unhashable element IDs, missing `element_id`, non-list `gws`, or unexpected note types). Unknown fields and practical size limits are also unconstrained. ## Suggested direction - Define Pydantic request models with typed IDs, bounded probabilities, bounded string lengths, list cardinality, uniqueness, and explicit extra-field policy. - Move request-shape validation out of endpoint business logic while keeping domain validation in `rules`/override code. - Add malformed-input and oversized-input tests for each endpoint. ## Acceptance criteria - Invalid request shapes consistently return documented 4xx validation responses. - Endpoint functions receive typed, bounded values. - Valid current frontend requests behave unchanged.
Author
Collaborator

Implemented on main in commit 141f4bf and covered by regression tests. Closing as complete.

Implemented on main in commit 141f4bf and covered by regression tests. Closing as complete.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
solvreven/FPL#6
No description provided.