|
8 | 8 |
|
9 | 9 | [What is JSON Schema?](https://json-schema.org/overview/what-is-jsonschema)
|
10 | 10 |
|
11 |
| -Support is limited to [draft-07](https://json-schema.org/draft-07) at the moment. |
12 |
| - |
13 | 11 | ## Features
|
14 | 12 |
|
15 | 13 | - 🏗️ **Fluent Builder API** - Build JSON Schemas using an intuitive fluent interface
|
16 |
| -- 📝 **Draft-07 Support** - Full support for JSON Schema Draft-07 specification |
| 14 | +- 📝 **Draft-07 Support** - Full support for JSON Schema [Draft-07](https://json-schema.org/draft-07) specification |
17 | 15 | - ✅ **Validation** - Validate data against schemas with detailed error messages
|
18 | 16 | - 🤝 **Conditional Schemas** - Support for if/then/else, allOf, anyOf, and not conditions
|
19 |
| -- 🔄 **Reflection** - Generate schemas from PHP classes and closures |
| 17 | +- 🔄 **Reflection** - Generate schemas from PHP Classes, Enums and Closures |
20 | 18 | - 💪 **Type Safety** - Built with PHP 8.3+ features and strict typing
|
21 | 19 |
|
22 |
| -## Why? |
23 |
| - |
24 |
| -I found myself looking for a nice, fluent way to build JSON Schemas, but couldn't find anything that fit my needs. |
25 |
| - |
26 |
| -There are many use cases, but the most prevalent right now is usage around LLMs, in particular structured outputs and tool calling. |
27 |
| - |
28 |
| -In fact I'm building an AI framework currently that uses this package to generate JSON Schemas in lots of scenarios. More to come on that soon! |
29 |
| - |
30 | 20 | ## Requirements
|
31 | 21 |
|
32 | 22 | - PHP 8.3+
|
@@ -68,29 +58,28 @@ $schema = SchemaFactory::object('user')
|
68 | 58 | );
|
69 | 59 | ```
|
70 | 60 |
|
71 |
| -You can also use the objects directly instead of the factory methods. |
| 61 | +You can also use the objects directly instead of the factory methods. (Example shows PHP 8.4 syntax) |
72 | 62 |
|
73 | 63 | ```php
|
74 |
| -$schema = (new ObjectSchema('user')) |
| 64 | +$schema = new ObjectSchema('user') |
75 | 65 | ->description('User schema')
|
76 | 66 | ->properties(
|
77 |
| - (new StringSchema('name')) |
| 67 | + new StringSchema('name') |
78 | 68 | ->minLength(2)
|
79 | 69 | ->maxLength(100)
|
80 | 70 | ->required(),
|
81 |
| - (new StringSchema('email')) |
| 71 | + new StringSchema('email') |
82 | 72 | ->format(SchemaFormat::Email)
|
83 | 73 | ->required(),
|
84 |
| - (new IntegerSchema('age')) |
| 74 | + new IntegerSchema('age') |
85 | 75 | ->minimum(18)
|
86 | 76 | ->maximum(150),
|
87 |
| - (new BooleanSchema('active')) |
| 77 | + new BooleanSchema('active') |
88 | 78 | ->default(true),
|
89 |
| - (new ObjectSchema('settings')) |
| 79 | + new ObjectSchema('settings') |
90 | 80 | ->additionalProperties(false)
|
91 | 81 | ->properties(
|
92 |
| - (new StringSchema('theme')) |
93 |
| - ->enum(['light', 'dark']), |
| 82 | + new StringSchema('theme')->enum(['light', 'dark']), |
94 | 83 | ),
|
95 | 84 | );
|
96 | 85 | ```
|
|
0 commit comments