Search by

specdocular / laravel-rules-to-schema

mohammad-alavi

Convert Laravel validation rules to JSON Schema

Package info

github.com/specdocular/laravel-rules-to-schema

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

Statistics

Installs: 455

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 1

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

This package is auto-updated.

Last update: 2026-09-08 18:08:44 UTC


README

Latest Version on Packagist PHP Version Tests codecov Code Style

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

Requirements

  • PHP 8.2 or higher
  • Laravel 10, 11, or 12

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

Contributing

Contributions are welcome. See CONTRIBUTING.md for setup, the required checks, and versioning.

Security

If you discover a security vulnerability, please follow the process in SECURITY.md rather than opening a public issue.

License

MIT. See LICENSE for details.