Awesome Reviewers

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.

Instruction

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_page default and a result-window check must use the exported FIND_DEFAULT_PER_PAGE rather than a locally re-declared 20, and a numeric field like priority should be bounded with the same rule the domain layer already applies (e.g. schema.number({ min: 0, max: Number.MAX_SAFE_INTEGER }) to match isValidPriority). 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 maxBytes explicitly, 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 PUT meant 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 knows isNew) 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.