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
Swagger Assertions

Swagger Assertions Laravel Package

fr3d/swagger-assertions

Laravel testing package adding PHPUnit assertions that validate API responses against your Swagger/OpenAPI definitions. Use it in feature tests to check status codes, schemas, and response structures, keeping documentation and endpoints in sync and catching contract drift early.

View on GitHub
Deep Wiki
Context7

fr3d/swagger-assertions brings OpenAPI-driven assertions to Laravel's HTTP testing suite, letting you verify that real API responses match your Swagger/OpenAPI documentation. Instead of hand-writing brittle expectations, you point tests at a documented path and let the package validate status codes, schemas, and headers automatically—so your docs and implementation stay in sync.

  • Asserts JSON responses against OpenAPI schema definitions
  • Validates status codes, headers, and response body structure
  • Plugs into familiar Laravel $this->get() style tests
  • Clear failure messages pinpoint schema mismatches
  • Supports OpenAPI 3 and Swagger 2 specifications
Frequently asked questions about Swagger Assertions
How do I install fr3d/swagger-assertions in a Laravel app?
Install it as a dev dependency with composer require --dev fr3d/swagger-assertions and pin an exact version with a committed lockfile. It is a test-time assertion library, not a Laravel runtime package, so keep it out of production dependencies. Then wire it into a PHPUnit or Pest test for a single endpoint to confirm it works with your setup.
Does fr3d/swagger-assertions support OpenAPI 3.x or only Swagger 2.0?
The package centers on Swagger 2.0 definitions and there is no confirmed support for OpenAPI 3.x. If your canonical spec is OpenAPI 3.x, evaluate actively maintained validators first and treat this package as a fallback only if conversion to Swagger 2.0 is trivial. Confirm version handling in a short spike before adopting.
Can I use fr3d/swagger-assertions with Laravel TestResponse in PHPUnit or Pest?
Not out of the box. Laravel feature tests return Illuminate\Testing\TestResponse, while the library expects HTTP message objects, so you will likely need a small adapter or normalizer that extracts method, URI, query, headers, status, and body. Keep that adapter isolated so it can be replaced or removed later.
Is fr3d/swagger-assertions safe to use in production?
No. It is a PHPUnit assertion library meant for contract testing in development and CI, not for request handling, middleware, or API gateways. Installing it as a dev dependency keeps it out of your production runtime.
Which PHP, Laravel, and PHPUnit versions does fr3d/swagger-assertions support?
The last release was in 2021, which predates current Laravel and PHPUnit majors, so compatibility must be verified. Check the composer.json constraints for PHP and PHPUnit, run a spike against your current stack, and confirm whether it works with Pest if you use it.
What is the license of fr3d/swagger-assertions?
The license is reported as NOASSERTION, which is a legal blocker until clarified. Do not adopt the package in a commercial codebase until legal or open-source review resolves the actual license and the repository provenance, since the distributed package name differs from the repository.
How do I convert a Laravel TestResponse into the request and response shape the package expects?
Write a small adapter that maps the Laravel test response to the HTTP message format the library expects, capturing method, URI, query string, headers, status code, and body. The library is framework-agnostic, so this translation layer is usually required. Keep the adapter isolated and covered by its own tests so it can be swapped or deleted if you change tools.
Is fr3d/swagger-assertions still maintained?
Maintenance from the vendor side is effectively nonexistent: the last release was in 2021 and the package has zero dependents. If you adopt it, expect to own dependency pinning, compatibility patches, and an eventual migration or fork. Assign an internal owner and keep an exit plan.
What are good alternatives to fr3d/swagger-assertions for Laravel API contract testing?
Actively maintained OpenAPI validators and schema assertion tools for PHP are generally better long-term bets, especially for OpenAPI 3.x. For a maintained Swagger 2.0 definition inside an existing PHPUnit suite this package can work as an additive quality gate. Compare maintenance status, license clarity, and spec version support before choosing.
Should I run contract assertions on every Laravel endpoint or just critical paths?
Start with one high-value endpoint and prove the assertions catch both valid and intentionally invalid responses. Expand to critical paths only rather than every endpoint, and run contract assertions alongside your existing feature tests instead of replacing them. Full coverage rarely justifies the maintenance cost of an old, lightly adopted dependency.
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.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo