giann / schematics
可转换为JSON Schema的模式
3.3.8
2024-09-27 08:25 UTC
Requires
- php: ^8.1
- giann/trunk: ^1.5.1
- nikic/php-parser: ^4.19.1 || ^5.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5.27
- dev-main
- 3.3.8
- 3.3.7
- 3.3.6
- 3.3.5
- 3.3.4
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.4.0
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.0
This package is auto-updated.
Last update: 2024-09-27 08:26:07 UTC
README
将PHP类转换为JSON Schema并反向转换。
支持的草稿
仅支持常用草稿draft-04和2020-12。
示例
enum Sex: string { case Male = 'male'; case Female = 'female'; case Other = 'other'; } #[ObjectSchema] class Person { public function __construct( #[StringSchema(format: Format::Uuid)] #[Description('unique id of the person')] public string $id, #[ArraySchema( items: new StringSchema(), minContains: 1 )] public array $names, #[IntegerSchema(minimum: 0)] public int $age, #[StringSchema(enumClass: Sex::class)] public string $sex, // Inferred $ref to self public ?Person $father = null ) { } } enum Power: string { case Fly = 'weeeee!'; case Strong = 'smash!'; case Psychic = 'hummmm!'; } // Infer $allOf Person #[ObjectSchema] class Hero extends Person { public function __construct( string $id, array $names, int $age, string $sex, ?Person $father = null, // Infers string property public string $superName, #[StringSchema(enumClass: Power::class)] public string $power ) { parent::__construct($id, $names, $age, $sex, $father); } }
产生以下JSON Schema
{
"type": "object",
"$defs": {
"Person": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "unique id of the person",
"format": "uuid"
},
"names": {
"type": "array",
"items": {
"type": "string"
},
"minContains": 1
},
"age": {
"type": "integer",
"minimum": 0
},
"sex": {
"type": "string",
"enum": ["male", "female", "other"]
},
"father": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/$defs/Person"
}
]
}
},
"required": ["id", "names", "age", "sex", "father"]
}
},
"allOf": [
{
"$ref": "#/$defs/Person"
}
],
"properties": {
"superName": {
"type": "string"
},
"power": {
"type": "string",
"enum": ["weeeee!", "smash!", "hummmm!"]
}
},
"required": ["superName", "power"]
}
尚未支持
$dynamicRef$dynamicAnchor