Skip to main content

Systems · validation

Adaptate — runtime validation for shared API models

One shared model, optional by default. Per-consumer rules set what is required at runtime. Docs and gateways use the same model. Uses Zod with OpenAPI / JSON Schema when consumers need different required fields.

For API authors where Partner A requires fields Partner B must omit.

  • One optional base model for all consumers
  • Per-consumer rules at runtime
  • Same model for code, docs, and gateways

Surfaces

  • npm packages (@adaptate/core, utils, adaptate)
  • Runtime adapter composition in Node
  • OpenAPI / JSON Schema bridge helpers

Product

When Partner A needs fields Partner B skips, one static schema fails. It blocks everyone or checks too little.

Tech and architecture

  • TypeScript
  • Zod
  • OpenAPI
  • JSON Schema
  • Node.js

Architecture

  • npm packages (@adaptate/core, utils, adaptate) for runtime validation in Node
  • Consumer adapters apply per-consumer rules keyed by route or caller
  • Validation stays TypeScript-first on top of Zod
  • OpenAPI / JSON Schema bridges generate or align contracts from the same model

Key components

  • Base model: fields optional by default so the shared shape stays honest
  • Consumer adapters: runtime per-consumer rules keyed by consumer or route context
  • Interop helpers: bridges toward OpenAPI / JSON Schema for docs and gateways

Data flow

  1. Request context selects consumer contract
  2. Adapter composes base + per-consumer rules
  3. Parse / validate payload
  4. Typed result or structured error

Failed validation stays local to the request. Schema authorship stays in code review, not in a detached CMS of JSON files.

Tradeoffs

  • Runtime per-consumer rules are more flexible than codegen-per-partner and harder to exhaustively type than a closed Zod union
  • Publishing as npm packages forces semver discipline; breaking rule semantics is a major version
  • OpenAPI interop lags exotic Zod refinements — document the subset you promise

Testing and ops

  • Unit tests lock per-consumer rule precedence, unknown-key policy, and missing-field errors
  • Package publish is the release train; consumers pin versions
  • CI runs type-check and the validation matrix before npm

More shipped walkthroughs in this set, or back to the landscape.