Skip to content

Add centralized request-schema validation framework - #1030

Merged
Userunknown84 merged 1 commit into
Userunknown84:mainfrom
pavsoss:feat/1024-validation-framework
Jul 31, 2026
Merged

Add centralized request-schema validation framework#1030
Userunknown84 merged 1 commit into
Userunknown84:mainfrom
pavsoss:feat/1024-validation-framework

Conversation

@pavsoss

@pavsoss pavsoss commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Part 1 of 2 for #1024. Request validation was duplicated across handlers, each
re-checking body shape, field presence, types and allowed values inline and
returning its own error. This centralizes the contract: every endpoint declares
a schema once, and a single decorator enforces it before the handler runs.

Invalid requests now get a typed error that lists every offending field in
one response instead of stopping at the first problem. Per-field code and
message overrides mean migrated endpoints return exactly the errors they did
before, so existing clients see no change in accepted or rejected inputs.

jsonschema is not a project dependency and none is added; the validator is a
small in-house implementation covering presence, type, enum and length, plus
lenient query-parameter coercion that matches the previous behaviour. The
existing XSS/auth decorators are unchanged and still run.

Migrated: /predict, /feedback, /feedback/stats, /importance,
/spam-insights. /analyze-email-header registers its contract for reuse but
keeps its file-vs-JSON presence check, which a flat body schema can't express.

Parts

Test plan

  • New coverage for the framework: valid payloads pass; an invalid payload is
    rejected with a typed envelope enumerating every bad field; presence, type,
    enum, min/max length, non-object and malformed bodies, the aggregate
    single-code case, and lenient query coercion.
  • Existing predict/feedback/error-envelope suites continue to pin the same
    codes, messages and status for each accepted and rejected input.

Refs #1024

@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@pavsoss is attempting to deploy a commit to the Aditya Sharma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Userunknown84
Userunknown84 merged commit 532e96c into Userunknown84:main Jul 31, 2026
4 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants