zero-to-prod/schema-validator

An OpenApi Schema Validator for the Laravel Framework

Maintainers

Package info

github.com/zero-to-prod/schema-validator

pkg:composer/zero-to-prod/schema-validator

Transparency log

Statistics

Installs: 23

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.3.0 2026-08-10 18:50 UTC

This package is auto-updated.

Last update: 2026-08-10 18:50:40 UTC


README

An OpenApi Schema Validator for the Laravel Framework.

Use an OpenAPI 3.* schema as the contract for validating data.

Requirements

Installation

composer require zero-to-prod/schema-validator

Usage

SchemaValidator::make() validates data against an OpenApi 3.* Schema Object and returns Illuminate\Validation\Validator:

use ZeroToProd\SchemaValidator\Property;
use ZeroToProd\SchemaValidator\Schema;
use ZeroToProd\SchemaValidator\SchemaValidator;

// A valid OpenAPI 3.* schema
$schema = [
    Schema::type => Schema::object,
    Schema::required => ['email', 'password', 'device_name'],
    Schema::properties => [
        'email' => [
            Property::type => Property::string,
            Property::maxLength => 255,
            Property::format => Property::email,
        ],
        'password' => [Property::type => Property::string, Property::maxLength => 255],
        'device_name' => [Property::type => Property::string, Property::maxLength => 255],
    ],
];

// Laravel structure
$messages = [
    'email.required' => 'We need to know your email address!',
    'email.max' => 'Your email address is too long!',
];

// Laravel structure
$attributes = [
    'email' => 'email address',
];

$Validator = SchemaValidator::make(request()->all(), $schema, $messages, $attributes);

if ($Validator->fails()) {
    return response()->json($Validator->errors(), 422);
}

$data = $Validator->validated();

Configuration

CLI install. It asks for every value the package can be configured with and writes config/schema-validator.php:

php artisan schema-validator:install

Rerunning it is safe: the file reports created, unchanged or updated, and is only overwritten once you confirm. Agents can do the same through the install tool.

To publish the configuration file by itself instead:

php artisan vendor:publish --tag=schema-validator-config

Agent development

The package registers an MCP server so coding agents can read how it is meant to be used. It requires laravel/mcp.

composer require --dev laravel/mcp
php artisan mcp:start schema-validator

Register it with your agent:

claude mcp add schema-validator -- php artisan mcp:start schema-validator

Three tools are exposed:

  • readme — this document.
  • api — the exact signature of every public class, property and method. Anything unlisted is internal and may change in any release.
  • install — what schema-validator:install does, without a prompt to answer. Takes enabled and handle, each defaulting to the current setting. A file that already says something else is left alone and reported until the call passes overwrite: true.

Point the handle somewhere else, or turn the server off, in config/schema-validator.php:

'mcp' => [
    'enabled' => true,
    'handle' => 'schema-validator',
],

Development

composer check   # lint, rector, phpstan, 100% coverage, bc-check — mutates nothing
composer fix     # rector then pint
composer mcp list                      # the server's tools
composer mcp call api '{}'             # call one

composer check requires a coverage driver (Xdebug or pcov); without one Pest cannot satisfy the --min=100 gate.

License

MIT. See LICENSE.