PHPackages                             kentaroutakeda/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. [HTTP &amp; Networking](/categories/http)
4. /
5. kentaroutakeda/laravel-openapi-validator

ActiveLibrary[HTTP &amp; Networking](/categories/http)

kentaroutakeda/laravel-openapi-validator
========================================

Laravel OpenAPI Validator - Request and response validators based on the OpenAPI Specification.

v1.10.0(3mo ago)918.5k↑245.2%MITPHPPHP &gt;=8.1CI passing

Since Dec 31Pushed 1mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (15)Versions (33)Used By (0)

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

[](#laravel-openapi-validator)

Request and response validators based on the OpenAPI Specification.

Summary
-------

[](#summary)

- Validate any request and response with a pre-prepared OpenAPI Spec.
- Automatically load specs from [Laravel OpenAPI](https://nova-edge.github.io/laravel-openapi/) or [L5 Swagger](https://github.com/DarkaOnLine/L5-Swagger/wiki).
- You can also load your own specs without using these libraries.
- You can customize validation and error logging behavior on a per-route or application-wide basis.
- Can display [Swagger UI](https://swagger.io/tools/swagger-ui/). You can view the documentation and test the API.

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.0 or higher

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

[](#installation)

You can install the package via composer:

```
composer require kentaroutakeda/laravel-openapi-validator
```

Usage
-----

[](#usage)

1. Configure OpenAPI Specification

    If you're using Laravel OpenAPI, you don't need to do anything.

    For L5 Swagger, the following settings are required:

    ```
    # .env
    OPENAPI_VALIDATOR_PROVIDER="l5-swagger"
    ```

    How to load your own schema without using these packages will be explained later.
2. Register Middleware

    ```
    Route::get('/example', ExampleController::class)
        ->middleware(OpenApiValidator::class); //  'my-resolver',

        'providers' => [
            // Set the provider name you created.
            'my-resolver' => [
                // Specify the class you created in the `resolver` parameter.
                'resolver' => MyResolver::class,
            ],
        ],
    ];
    ```

### Error responses and customization

[](#error-responses-and-customization)

By default, it is formatted according to [RFC 7807 - Problem Details for HTTP APIs](https://datatracker.ietf.org/doc/html/rfc7807).

Validation errors, stack traces and original response can also be included depending on your settings. For example, it might look like this:

```
{
  "title": "NoResponseCode",
  "detail": "OpenAPI spec contains no such operation [/,get,201]", // Error reason
  "status": 500, // Same as HTTP response code
  "originalResponse": { "status": "201" }, // Original response before validation
  "trace": [
    { "error": "...", "message": "...", "file": "...", "line": 42 },
    { "...": "..." }
  ]
}
```

Here's how to change to a different format:

1. First, implement a class to generate a response. For example:

    ```
    class MyErrorRenderer implements ErrorRendererInterface
    {
        public function render(
            \Throwable $error,
            Request $request,
            ?Response $response = null,
        ): Response {
            return new Response(
                match ($response === null) {
                    ErrorType::Request => "Request Error: " . $error->getMessage(),
                    ErrorType::Response => "Response Error: " . $error->getMessage(),
                }
            );
        }
    }
    ```
2. Next, register the class to the service container.

    ```
    // AppServiceProvider.php

    public function register(): void
    {
        $this->app->bind(
            ErrorRendererInterface::class,
            MyErrorRenderer::class
        );
    }
    ```

### Events

[](#events)

If a validation error occurs, an event will be fired depending on the type of error.

- `ValidationFailedInterface` - All errors
    - `RequestValidationFailed` - Request validation error
    - `ResponseValidationFailed` - Response validation error

Contributing and Development
----------------------------

[](#contributing-and-development)

Feel free to open an Issue or add a Pull request.

When adding a pull request, please refer to the following setup steps.

```
# Clone this repository and move to the directory.
git clone https://github.com/KentarouTakeda/laravel-openapi-validator.git
cd laravel-openapi-validator

# Install dependencies.
composer install

# (Optional) Install tools: The commit hook automatically formats the code.
npm install

# Run tests.
vendor/bin/phpunit
```

License
-------

[](#license)

Laravel OpenAPI Validator is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance85

Actively maintained with recent releases

Popularity33

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~26 days

Recently: every ~10 days

Total

30

Last Release

108d ago

Major Versions

v0.10.3 → v1.0.02024-01-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a86ded11ab00ad8b8dc35aff2c7a8ef06ce2dab6518b783de742cdfd37f51da?d=identicon)[KentarouTakeda](/maintainers/KentarouTakeda)

---

Top Contributors

[![KentarouTakeda](https://avatars.githubusercontent.com/u/4785040?v=4)](https://github.com/KentarouTakeda "KentarouTakeda (286 commits)")

---

Tags

apidocsdocumentationlaravelmiddlewareopenapirestspecificationswaggervalidationvalidatormiddlewareapilaravelvalidatorvalidationrestdocumentationspecificationswaggeropenapidocs

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[vyuldashev/laravel-openapi

Generate OpenAPI Specification for Laravel Applications

4571.2M](/packages/vyuldashev-laravel-openapi)[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

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

Generate OpenAPI Specification for Laravel Applications

38178.7k2](/packages/tartanlegrand-laravel-openapi)[kirschbaum-development/laravel-openapi-validator

Automatic OpenAPI validation for Laravel HTTP tests

581.1M5](/packages/kirschbaum-development-laravel-openapi-validator)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[noitran/opendox

OpenApi(Swagger) 3.0 package for Lumen 5.5+ and Laravel 5.5+ with REDOC UI and SwaggerUI 3

2313.9k](/packages/noitran-opendox)

PHPackages © 2026

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