specdocular/php-json-schema
最新稳定版本:v0.1.0
Composer 安装命令:
composer require specdocular/php-json-schema
包简介
PHP implementation of JSON Schema (Draft 2020-12)
README 文档
README
A type-safe, fluent PHP implementation of JSON Schema Draft 2020-12.
Installation
composer require specdocular/php-json-schema
Usage
Build JSON Schema definitions using a fluent, type-safe API:
use Specdocular\JsonSchema\Draft202012\StrictFluentDescriptor; use Specdocular\JsonSchema\Draft202012\Keywords\Properties\Property; $schema = StrictFluentDescriptor::object() ->properties( Property::create('name', StrictFluentDescriptor::string()->minLength(1)), Property::create('email', StrictFluentDescriptor::string()->format('email')), Property::create('age', StrictFluentDescriptor::integer()->minimum(0)), ) ->required('name', 'email'); // Compile to array $compiled = $schema->compile(); // Or encode directly to JSON $json = json_encode($schema, JSON_PRETTY_PRINT);
Strict vs Loose Descriptors
StrictFluentDescriptor(recommended) — provides type-specific method autocomplete. Methods likeminLength()are only available on string schemas,minimum()only on numeric schemas, etc.LooseFluentDescriptor— exposes all keywords on every schema. Useful when building schemas with multiple types.
Features
- Full JSON Schema Draft 2020-12 support (all 50 keywords, 7 vocabularies)
- Type-safe fluent API with IDE autocomplete
- Extensible keyword and vocabulary system
- Built-in schema validation (
VocabularyValidator,MetaSchemaValidator) - Framework-agnostic — no dependencies on Laravel or any framework
Note: This library builds JSON Schema definitions. It does not validate data against schemas — use a validation library like
justinrainbow/json-schemafor that.
Related Packages
| Package | Description |
|---|---|
| specdocular/php-openapi | Object-oriented OpenAPI 3.1.x builder (uses this package) |
| specdocular/laravel-rules-to-schema | Convert Laravel validation rules to JSON Schema (uses this package) |
| specdocular/laravel-openapi | Laravel integration for OpenAPI generation |
License
MIT. See LICENSE for details.
统计信息
- 总下载量: 595
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-13