specdocular/laravel-rules-to-schema 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

specdocular/laravel-rules-to-schema

最新稳定版本:v0.1.0

Composer 安装命令:

composer require specdocular/laravel-rules-to-schema

包简介

Convert Laravel validation rules to JSON Schema

README 文档

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.

统计信息

  • 总下载量: 401
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-13