twentytwo-labs/api-validator
Twentytwo Labs API Validator is a Laravel/PHP package for validating API requests and responses with reusable rules. It helps keep endpoints consistent, catches malformed payloads early, and makes validation errors easier to surface in your applications.
Verdict up front: conditionally viable as a thin, replaceable contract-validation layer; not viable as a core dependency without a spike and an abstraction seam.
Architecture fit — The package is PSR-7 native, which is the right primitive but the wrong shape for a stock Laravel app. Laravel's HTTP layer is Symfony HttpFoundation; PSR-7 only enters if we add symfony/psr-http-message-bridge plus a PSR-7 implementation (e.g. nyholm/psr7). Net: this is a framework-agnostic PHP component we would wrap, not a Laravel package we install and configure. Its natural usage shape is middleware — validate the request before the controller runs — which maps cleanly onto Laravel middleware or a FormRequest replacement.
Integration feasibility — Moderate. The real work sits in three places: (1) request/response bridging between HttpFoundation and PSR-7, (2) mapping validator failures onto Laravel's 422 / ValidationException contract so API consumers see a consistent error envelope, (3) loading and caching the OpenAPI document. None are exotic; all become ours to own.
Technical risk
league/openapi-psr7-validator is the de facto standard here with real production usage. Any decision must be a bake-off against it, not a unilateral pick.$ref resolution on the hot path is the classic failure mode; requires precompiled/cached schema artifacts.Key questions
oneOf/anyOf, discriminators, nullable, format assertions)?style/content handling, or a useful subset?league/openapi-psr7-validator?Stack fit — PHP 8.x / Laravel 10–11, PSR-7 bridge, with the OpenAPI document treated as a versioned contract artifact in CI. Fits best where the spec is already authoritative rather than aspirational.
Migration path — Non-destructive and incremental: attach as middleware on selected route groups in shadow mode (log-only, never block), then promote to enforcing. No data migration and no consumer-visible change while shadowing.
Compatibility — Verify psr/http-message 1.x vs 2.x against the bridge and any existing PSR-7 dependency; version skew here is the most common install-time breakage. Confirm worker safety under Octane/Swoole if we run long-lived processes.
Sequencing
ContractValidator interface plus adapter, so the library underneath is swappable. This is the whole risk mitigation.ValidationException with field paths matching existing API conventions.Maintenance — We own the bridge and error mapping; expect to vendor or fork if upstream stalls. Budget a few days per year for upstream bumps, plus the ongoing cost of keeping the OpenAPI document truthful — spec staleness is the real maintenance tax, not the library.
Support — No community, no docs ecosystem, no Stack Overflow corpus. Internal-only: one named engineer must own it. That falls below the bar for tier-1 critical-path services unless the abstraction seam exists.
Scaling — Validation is CPU-bound on top of Laravel's own boot. Mitigate with cached/compiled schemas, validating only mutating methods, and sampling in shadow mode. Under Octane, preload the schema once per worker. Measure before enforcing globally on high-volume endpoints.
Failure modes
$ref or malformed document → 500s at boot or first request; fail closed at deploy time.Ramp-up — Low for a mid-level Laravel engineer comfortable with PSR interfaces: ~1 week to productive, ~2–3 weeks to own it responsibly. The learning curve is OpenAPI semantics, not this library.
TPM recommendation — Do not adopt directly on a tier-1 service. Run the spike explicitly as a bake-off against league/openapi-psr7-validator, and adopt only behind a thin internal interface. The value is opportunistic (contract validation, shadow-mode API governance), not foundational.
How can I help you explore Laravel packages today?