specdocular/laravel-rules-to-schema

Convert Laravel validation rules to JSON Schema

Installs: 215

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/specdocular/laravel-rules-to-schema

v0.1.0 2026-02-13 09:03 UTC

This package is auto-updated.

Last update: 2026-02-13 10:59:37 UTC


README

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.