zero-to-prod / schema-validator
An OpenApi Schema Validator for the Laravel Framework
Requires
- php: ^8.5
- illuminate/console: ^13.0
- illuminate/support: ^13.0
- illuminate/validation: ^13.0
Requires (Dev)
- laravel/mcp: ^0.9
- laravel/pint: ^1.30
- orchestra/testbench: ^11.0
- pestphp/pest: ^5.0
- pestphp/pest-plugin-rector: ^5.0
- phpstan/phpstan: ^2.2
- rector/rector: ^2.5
Suggests
- laravel/mcp: Required by the MCP server that exposes this package's documentation to coding agents.
README
An OpenApi Schema Validator for the Laravel Framework.
Use an OpenAPI 3.* schema as the contract for validating data.
Requirements
- PHP
^8.5 - Laravel 13
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— whatschema-validator:installdoes, without a prompt to answer. Takesenabledandhandle, each defaulting to the current setting. A file that already says something else is left alone and reported until the call passesoverwrite: 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.