On this page4 sections
ReferenceIntermediate4-6 min reference

API Schema Validation

Asserting an exact value (status === "active") is brittle; asserting the shape (status is one of a known enum, id is a UUID, total is a number) is robust and catches whole classes of regressions. This sheet is the quick reference for schema-based assertions and the drift they catch. For the spec format itself, see the OpenAPI / Swagger sheet.

What a schema check covers

DimensionExample assertion
Presencerequired: ["id", "email", "createdAt"]
Typeemail is string, total is number, items is array
Formatstring with format: email / uuid / date-time
Enumstatus["active","pending","closed"]
Rangeminimum, maximum, minLength, maxLength
Nullabilityfield may be null vs must be present
No extrasadditionalProperties: false catches leaked fields

JSON Schema keywords worth knowing

KeywordMeans
requiredFields that must exist
typestring number integer boolean object array null
enumAllowed value set
formatSemantic string format
additionalProperties: falseReject unexpected fields (drift!)
$refReuse a shared schema
oneOf / anyOfPolymorphic / union shapes

What it catches that value-assertions miss

  • A new field leaking PII into the response (additionalProperties: false).
  • A type silently changing ("123" string vs 123 number) after a refactor.
  • A required field disappearing on one code path.
  • An enum gaining an undocumented value — contract drift between spec and code.

Common mistakes

  • Asserting one exact value instead of the shape (brittle, low coverage).
  • Allowing additionalProperties, so leaked/extra fields pass silently.
  • Validating only 200 bodies — error bodies have schemas too.
  • Letting the schema and the OpenAPI spec diverge; generate one from the other.

// Related resources