You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The JSON Schema Generator is a PHP package that simplifies the generation of [JSON schemas](https://json-schema.org/) from Data Transfer Object (DTO) classes.
10
+
The JSON Schema Generator is a PHP package that simplifies the generation of [JSON schemas](https://json-schema.org/) from Data Transfer Object (DTO) classes.
11
11
It supports PHP enumerations and generic type annotations for arrays and provides an attribute for specifying title, description, and default value.
12
12
13
13
Main use case - structured output definition for LLMs.
@@ -107,17 +107,34 @@ Example array output:
107
107
'description' => [
108
108
'title' => 'Description',
109
109
'description' => 'The description of the movie',
110
-
'type' => 'string',
110
+
'oneOf' => [
111
+
['type' => 'null'],
112
+
['type' => 'string'],
113
+
],
111
114
],
112
-
'director' => [
113
-
'type' => 'string',
115
+
'director' => [
116
+
'oneOf' => [
117
+
['type' => 'null'],
118
+
['type' => 'string'],
119
+
],
114
120
],
115
121
'releaseStatus' => [
116
122
'title' => 'Release Status',
117
123
'description' => 'The release status of the movie',
118
-
'allOf' => [
124
+
'oneOf' => [
119
125
[
120
-
'$ref' => '#/definitions/ReleaseStatus',
126
+
'type' => 'null',
127
+
],
128
+
[
129
+
'type' => 'string',
130
+
'enum' => [
131
+
'Released',
132
+
'Rumored',
133
+
'Post Production',
134
+
'In Production',
135
+
'Planned',
136
+
'Canceled',
137
+
],
121
138
],
122
139
],
123
140
],
@@ -126,20 +143,6 @@ Example array output:
126
143
'title',
127
144
'year',
128
145
],
129
-
'definitions' => [
130
-
'ReleaseStatus' => [
131
-
'title' => 'ReleaseStatus',
132
-
'type' => 'string',
133
-
'enum' => [
134
-
'Released',
135
-
'Rumored',
136
-
'Post Production',
137
-
'In Production',
138
-
'Planned',
139
-
'Canceled',
140
-
],
141
-
],
142
-
],
143
146
];
144
147
```
145
148
@@ -159,7 +162,8 @@ final class Actor
159
162
/**
160
163
* @var array<Movie>
161
164
*/
162
-
public readonly array $movies = [],
165
+
public readonly ?array $movies = null,
166
+
public readonly ?Movie $bestMovie = null;
163
167
) {
164
168
}
165
169
}
@@ -191,11 +195,29 @@ Example array output:
191
195
'type' => 'string',
192
196
],
193
197
'movies' => [
194
-
'type' => 'array',
195
-
'items' => [
196
-
'$ref' => '#/definitions/Movie',
198
+
'oneOf' => [
199
+
[
200
+
'type' => 'null',
201
+
],
202
+
[
203
+
'type' => 'array',
204
+
'items' => [
205
+
'$ref' => '#/definitions/Movie',
206
+
],
207
+
],
208
+
],
209
+
],
210
+
'bestMovie' => [
211
+
'title' => 'Best Movie',
212
+
'description' => 'The best movie of the actor',
213
+
'oneOf' => [
214
+
[
215
+
'type' => 'null',
216
+
],
217
+
[
218
+
'$ref' => '#/definitions/Movie',
219
+
],
197
220
],
198
-
'default' => [],
199
221
],
200
222
],
201
223
'required' => [
@@ -219,41 +241,192 @@ Example array output:
219
241
'description' => [
220
242
'title' => 'Description',
221
243
'description' => 'The description of the movie',
222
-
'type' => 'string',
244
+
'oneOf' => [
245
+
['type' => 'null'],
246
+
['type' => 'string'],
247
+
],
223
248
],
224
249
'director' => [
225
-
'type' => 'string',
250
+
'oneOf' => [
251
+
['type' => 'null'],
252
+
['type' => 'string'],
253
+
],
226
254
],
227
255
'releaseStatus' => [
228
256
'title' => 'Release Status',
229
257
'description' => 'The release status of the movie',
0 commit comments