Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Openapi Testing Laravel Package

rebzya/openapi-testing

OpenAPI testing helpers for Laravel and PHP apps: use your OpenAPI spec to drive API contract tests and catch mismatches between documented endpoints and real responses before they ship.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install and pin. composer require --dev r3bzya/openapi-testing — note the package is pre-1.0, so require an explicit constraint (^0.4) rather than *. v0.4.0 (the 0.3.0 → 0.4.0 bump) shipped with a changelog link only and no written notes, so read the diff on GitHub before upgrading an existing 0.3.x install; minor-number bumps in 0.x packages routinely carry breaking signature changes.
  2. Publish config. Run php artisan vendor:publish --tag=openapi-testing-config (tag name may differ — check php artisan vendor:publish output). You'll typically be setting the path to your spec (openapi.json / openapi.yaml), the base URL used to resolve relative servers entries, and a strictness/validation mode.
  3. Look here first: the package's service provider and config file. In a 0.x package these tell you more about current behaviour than the README, which often lags a release behind.
  4. First use case: a single smoke test that takes one real API response and asserts it conforms to the spec for that path + method. Don't start by wiring it across your whole suite — prove one endpoint round-trips, then scale out.

Implementation Patterns

  • Contract-first assertion in feature tests. The day-to-day pattern is: hit your endpoint with Laravel's normal test helpers ($this->getJson(...), acting-as, database factories), then hand the response and the operation (path + method + status code) to the package for schema validation. Keep your existing status-code/JSON-fragment assertions — the spec check is additive, not a replacement.
  • Centralise the plumbing in a base TestCase or trait. You do not want every test knowing the spec path and the operation ID. A small helper like assertMatchesSpec($response, 'GET', '/api/v1/users') in a shared trait keeps tests readable and gives you one place to change when the package's API shifts on the next 0.x bump.
  • Drive it from the spec, not from memory. The real leverage is looping: enumerate paths/methods from the parsed spec and assert that each one you care about is covered by at least one test (or, for GETs against seeded data, auto-generate a smoke test per operation). This catches "we added an endpoint and forgot to test it" drift.
  • Split strict vs. lenient runs. Run strict validation (no extra properties, no nullable laxity) locally and in PRs; run a lenient mode on a nightly job if your production responses carry vendor-specific extras that aren't in the published contract. Trying to make one mode serve both usually means someone disables the check entirely.
  • Test both sides when the package supports it. Response validation is the common case, but if request-body validation is available, assert that your FormRequests and the spec agree — that's where the mismatches actually get shipped.
  • CI integration. Keep it inside your normal PHPUnit/Pest run rather than a separate job, so failures block merges on the same signal as everything else. Cache the parsed/compiled spec between runs if the package supports it; YAML $ref resolution is the slow part on large specs.

Gotchas and Tips

  • 0.x means read the diff. There were no v0.4.0 release notes beyond the compare link. Treat this as an unreviewed upgrade: composer update r3bzya/openapi-testing --dry-run, read the diff, then run the suite. Pin to ~0.4.0 if you need stability mid-quarter.
  • Spec drift is the main failure mode — and it's ambiguous. When a test fails you have to determine whether the code is wrong or the spec is stale. In practice the spec is stale more often than you'd like. Decide up front which artefact is the source of truth and say so in the README, or the first failure will turn into an argument.
  • $ref resolution is the usual culprit for confusing errors: relative refs break when the spec is loaded from a different working directory (common in CI vs. local), and circular refs can blow up the parser. Absolute-ise the spec path in config rather than relying on cwd.
  • OpenAPI features that trip up validators: oneOf / anyOf discrimination, nullable (3.0) vs. type: ['string','null'] (3.1), additionalProperties: false with Laravel resources that add meta/links, and integer-vs-string coercion — PHP's JSON decode turns "1" and 1 into different things, and Laravel casts are easy to get wrong. Add an explicit test for any endpoint using these.
  • Response envelope mismatch. Laravel's default JsonResource wrapping ({"data": ...}) and pagination meta must exist in the spec or every paginated test fails. Check your JsonResource::withoutWrapping() state before blaming the package.
  • Debugging a failure: dump the actual response body and the resolved sub-schema at the failing pointer. "Validation failed" with no path is useless; most validators can be coerced into emitting the JSON pointer, and that's the first thing to configure when something goes red.
  • Extension points to look for in a package this young: a custom resolver/loader (for multi-file specs), a hook to post-process the parsed spec (strip internal-only paths), and a way to ignore specific properties (timestamps, IDs). If any are missing, wrap the package in your own thin assertion class rather than sprinkling if statements through tests — that wrapper is also your migration shim for 0.5.0.
  • Don't let it become the only test. Schema validation proves shape, not semantics — a 200 with empty arrays passes every schema check. Keep behavioural assertions alongside it.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core