Reviewer · API
API contract accuracy
Keep a route's validation schema, size limits, and HTTP semantics faithful to both the documented behavior and the business rules enforced elsewhere in the code, instead of letting them drift independently.
Keep a route’s validation schema, size limits, and HTTP semantics faithful to both the documented behavior and the business rules enforced elsewhere in the code, instead of letting them drift independently.
- Bounds and defaults: don’t redefine a limit or default value in the request schema; import the same constant the handler/service uses. For example, a
per_pagedefault and a result-window check must use the exportedFIND_DEFAULT_PER_PAGErather than a locally re-declared20, and a numeric field likepriorityshould be bounded with the same rule the domain layer already applies (e.g.schema.number({ min: 0, max: Number.MAX_SAFE_INTEGER })to matchisValidPriority). A single source of truth means a future change to the limit can’t silently desync the schema, the docs string, and the runtime behavior. - Payload size limits: when a field’s documented maximum size (e.g. “up to 10 MiB”) is larger than the router’s default body limit, set
maxBytesexplicitly, with headroom for JSON escaping and the rest of the payload, and add a test asserting the documented maximum is actually accepted. - Verb semantics: make sure an endpoint behaves the way its HTTP method and name imply. A
PUTmeant for editing an existing resource should not silently upsert and recreate something that was deleted out of band (e.g. while a UI flyout was open); if that’s undesired, check existence first on the edit path (the create path already knowsisNew) and return a clear error instead of a silent recreate.
Before merging a new or changed route, check the schema’s bounds/defaults against the code that enforces them downstream, verify any size limit against the documented maximum, and confirm the HTTP verb’s behavior matches what callers would reasonably expect from it.