PHPackages                             kirschbaum-development/laravel-openapi-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. kirschbaum-development/laravel-openapi-validator

ActiveLibrary[API Development](/categories/api)

kirschbaum-development/laravel-openapi-validator
================================================

Automatic OpenAPI validation for Laravel HTTP tests

2.0.0(2mo ago)581.1M—7.1%14[3 issues](https://github.com/kirschbaum-development/laravel-openapi-validator/issues)4MITPHPPHP ^8.0CI passing

Since Nov 13Pushed 2mo ago17 watchersCompare

[ Source](https://github.com/kirschbaum-development/laravel-openapi-validator)[ Packagist](https://packagist.org/packages/kirschbaum-development/laravel-openapi-validator)[ Docs](https://github.com/kirschbaum-development/laravel-openapi-validator)[ RSS](/packages/kirschbaum-development-laravel-openapi-validator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (16)Used By (4)

Laravel OpenAPI Validator
=========================

[](#laravel-openapi-validator)

[![Laravel Supported Versions](https://camo.githubusercontent.com/9d89fb66d31f1bc045dd995577593171a82d029875e09a099ae862c13d8251db/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31312e782f31322e782f31332e782d677265656e2e737667)](https://camo.githubusercontent.com/9d89fb66d31f1bc045dd995577593171a82d029875e09a099ae862c13d8251db/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31312e782f31322e782f31332e782d677265656e2e737667)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Using an OpenAPI spec is a great way to create and share a contract to which your API adheres. This package will automatically verify both the request and response used in your integration and feature tests wherever the Laravel HTTP testing methods (`->get('/uri')`, etc) are used.

Behind the scenes this package connects the [Laravel HTTP helpers](https://laravel.com/docs/8.x/http-tests) to [The PHP League's OpenAPI Validator](https://github.com/thephpleague/openapi-psr7-validator).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require kirschbaum-development/laravel-openapi-validator
```

Setup
-----

[](#setup)

In any feature/integration test (such as those that extend the framework's `Tests\TestCase` base class), add the `ValidatesOpenApiSpec` trait:

```
use Kirschbaum\OpenApiValidator\ValidatesOpenApiSpec;

class HttpTest extends TestCase
{
    use ValidatesOpenApiSpec;
}
```

In many situations, the defaults should handle configuration. If you need to customize your configuration (namely the location of the `openapi.yaml` or `openapi.json` file), publish the config with:

```
php artisan vendor:publish --provider="Kirschbaum\OpenApiValidator\OpenApiValidatorServiceProvider"
```

and configure the path to the OpenAPI spec in `config/openapi_validator.php` to fit your needs.

Usage
-----

[](#usage)

After applying the trait to your test class, anytime you interact with an HTTP test method (`get`, `post`, `put`, `delete`, `postJson`, `call`, etc), the validator will validate both the request and the response.

### Skipping Validation

[](#skipping-validation)

Especially when initially writing tests (such as in TDD), it can be helpful to turn off the request or response validation until the tests are closer to complete. You can do so as follows:

```
public function testEndpointInProgress()
{
    $response = $this->withoutRequestValidation()->get('/'); // Skips request validation, still validates response
    // or
    $response = $this->withoutResponseValidation()->get('/'); // Validates the request, but skips response
    // or
    $response = $this->withoutValidation()->get('/'); // No validation
}
```

You are free to chain these methods as shown above, or call them on their own:

```
public function testEndpointInProgress()
{
    $this->withoutRequestValidation();
    $response = $this->get('/');
}
```

Keep in mind that `withoutRequestValidation()`, `withoutResponseValidation()`, and `withoutValidation()` only apply to the *next* request/response and will reset afterwards.

#### Skipping Responses Based on Response Code

[](#skipping-responses-based-on-response-code)

We assume, by default, that any `5xx` status code should not be validated. You may change this by setting the protected `responseCodesToSkip` property on your test class, or by using the `skipResponseCode` method to add response codes (single, array, or a regex pattern):

```
use Kirschbaum\OpenApiValidator\ValidatesOpenApiSpec;

class HttpTest extends TestCase
{
    use ValidatesOpenApiSpec;

    protected $responseCodesToSkip = [200]; // Will validate every response EXCEPT 200

    public function testNoRedirects()
    {
        $this->skipResponseCode(300); // Will skip 200 and 300
        $this->skipResponseCode(301, 302); // Will skip 200, 300, 301, 302
        $this->skipResponseCode('3[1-2]1'); // Will skip 200, 300, 301, 302, 311, and 321
        // ...
    }
}
```

### Authentication/Authorization

[](#authenticationauthorization)

In most tests, you're likely using Laravel's helpers such as `actingAs($user)` to handle auth. This package, by default, assumes you're using bearer token as an authorization header, *and that this is specified in your OpenAPI spec*. The validator will expect the authorization to be part of the request, even though Laravel does not send them. If you are using security other than a bearer token, you should override the `getAuthenticatedRequest` method and add the appropriate headers. Note that they do not need to be valid (unless your code will check them), they just need to be present to satisfy the validator.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Zack Teska](https://github.com/zerodahero)

Sponsorship
-----------

[](#sponsorship)

Development of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more [about us](https://kirschbaumdevelopment.com) or [join us](https://careers.kirschbaumdevelopment.com)!

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance87

Actively maintained with recent releases

Popularity53

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~139 days

Recently: every ~208 days

Total

15

Last Release

60d ago

Major Versions

0.4.0 → 1.0.02024-04-04

1.1.1 → 2.0.02026-03-19

PHP version history (4 changes)0.1.0PHP ^7.3

0.1.1PHP ^7.3|^8.0

0.2.0PHP ^7.4|^8.0

1.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f56743d64d77958321d43b2df49e9696d19c9dd99995730c5c38ccae50408fa?d=identicon)[Kirschbaum](/maintainers/Kirschbaum)

![](https://www.gravatar.com/avatar/2eabd98e880412f6caf8e816eaa1ccddb7645724aa3b5f604addeb6273ae72c1?d=identicon)[zerodahero](/maintainers/zerodahero)

---

Top Contributors

[![zerodahero](https://avatars.githubusercontent.com/u/6423168?v=4)](https://github.com/zerodahero "zerodahero (18 commits)")[![luisdalmolin](https://avatars.githubusercontent.com/u/403446?v=4)](https://github.com/luisdalmolin "luisdalmolin (9 commits)")[![k2tzumi](https://avatars.githubusercontent.com/u/1182787?v=4)](https://github.com/k2tzumi "k2tzumi (5 commits)")[![tyamahori](https://avatars.githubusercontent.com/u/21966964?v=4)](https://github.com/tyamahori "tyamahori (2 commits)")[![sixmonkey](https://avatars.githubusercontent.com/u/15140258?v=4)](https://github.com/sixmonkey "sixmonkey (1 commits)")[![vaidas-lungis](https://avatars.githubusercontent.com/u/5111555?v=4)](https://github.com/vaidas-lungis "vaidas-lungis (1 commits)")[![ysato](https://avatars.githubusercontent.com/u/56924527?v=4)](https://github.com/ysato "ysato (1 commits)")[![PHLAK](https://avatars.githubusercontent.com/u/53531?v=4)](https://github.com/PHLAK "PHLAK (1 commits)")[![JeroenVanOort](https://avatars.githubusercontent.com/u/5616838?v=4)](https://github.com/JeroenVanOort "JeroenVanOort (1 commits)")[![MizouziE](https://avatars.githubusercontent.com/u/90829439?v=4)](https://github.com/MizouziE "MizouziE (1 commits)")[![jackbayliss](https://avatars.githubusercontent.com/u/13621738?v=4)](https://github.com/jackbayliss "jackbayliss (1 commits)")

---

Tags

laravelvalidationswaggeropenapi

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kirschbaum-development-laravel-openapi-validator/health.svg)

```
[![Health](https://phpackages.com/badges/kirschbaum-development-laravel-openapi-validator/health.svg)](https://phpackages.com/packages/kirschbaum-development-laravel-openapi-validator)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
