Looking to hire Laravel developers? Try LaraJobs

laravel-rules-to-schema maintained by specdocular

Description
Convert Laravel validation rules to JSON Schema
Last update
2026/02/23 17:01 (dev-main)
License
Downloads
397

Comments
comments powered by Disqus

Laravel Rules to Schema

Latest Version on Packagist PHP Version Tests codecov Code Style

Convert Laravel validation rules into JSON Schema Draft 2020-12 definitions.

Installation

composer require specdocular/laravel-rules-to-schema

The service provider is auto-discovered by Laravel.

Usage

use Specdocular\LaravelRulesToSchema\RuleToSchema;
use Specdocular\LaravelRulesToSchema\ValidationRuleNormalizer;

$converter = app(RuleToSchema::class);

$rules = [
    'email' => ['required', 'email', 'max:255'],
    'age' => ['required', 'integer', 'min:18', 'max:120'],
    'tags' => ['array'],
    'tags.*' => ['string', 'max:50'],
];

$normalizer = new ValidationRuleNormalizer();
$normalized = $normalizer->normalize($rules);

$schema = $converter->transform($normalized);
$compiled = $schema->compile();

Configuration

Publish the config file to customize rule parsers:

php artisan vendor:publish --tag=rules-to-schema-config

Features

  • Converts 25+ built-in Laravel validation rules to JSON Schema
  • Handles nested objects, arrays, and wildcard (*) rules
  • Supports conditional rules (required_if, required_with, etc.)
  • Extensible — register custom rule parsers via config
  • Auto-registered as a Laravel service provider

Related Packages

Package Description
specdocular/php-json-schema JSON Schema Draft 2020-12 builder (foundation)
specdocular/php-openapi Object-oriented OpenAPI builder
specdocular/laravel-openapi Laravel integration for OpenAPI generation

License

MIT. See LICENSE for details.