Context
- Route decorators accept
body_model (Pydantic v2) and body_schema (dict) for OpenAPI (oxyroute/app.py, src/lib.rs).
- JSON body is parsed in
src/dispatch.rs but not validated against the model/schema at runtime.
Problem
OpenAPI documents request shapes that the framework does not enforce. Handlers must manually validate Pydantic models, unlike FastAPI-style DX.
Proposed change
- Store validation metadata on
RouteEntry at registration.
- Before the handler runs, validate parsed JSON against
body_model (Pydantic) or optional JSON Schema.
- Return 422 with a normalized error shape on validation failure.
- Decide handler API: validated model instance vs existing
json dict (document breaking vs additive choice).
Files
oxyroute/app.py, src/lib.rs, src/dispatch.rs, src/state.rs
docs/openapi.md, docs/handlers.md, tests (Pydantic v2)
Acceptance criteria
- Invalid payload returns 422 without calling the route handler.
- Valid payload reaches handler with documented shape.
- OpenAPI generation unchanged or improved.
- Tests cover Pydantic validation errors.
Framework impact
Less boilerplate in handlers; closer to FastAPI request validation.
Context
body_model(Pydantic v2) andbody_schema(dict) for OpenAPI (oxyroute/app.py,src/lib.rs).src/dispatch.rsbut not validated against the model/schema at runtime.Problem
OpenAPI documents request shapes that the framework does not enforce. Handlers must manually validate Pydantic models, unlike FastAPI-style DX.
Proposed change
RouteEntryat registration.body_model(Pydantic) or optional JSON Schema.jsondict (document breaking vs additive choice).Files
oxyroute/app.py,src/lib.rs,src/dispatch.rs,src/state.rsdocs/openapi.md,docs/handlers.md, tests (Pydantic v2)Acceptance criteria
Framework impact
Less boilerplate in handlers; closer to FastAPI request validation.