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
Copy file name to clipboardExpand all lines: docs/source/complexTypes/object.rst
+68-2Lines changed: 68 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ Generated interface:
37
37
public function setCar(?Car $name): self;
38
38
public function getCar(): ?Car;
39
39
40
-
// class Car
40
+
// class Person_Car
41
41
public function setModel(?string $name): self;
42
42
public function getModel(): ?string;
43
43
public function setPs(?int $name): self;
@@ -55,8 +55,23 @@ Namespaces
55
55
If a nested class is generated the nested class will be located in the same namespace as the parent class.
56
56
If the nested class occurs somewhere else and has already been generated a class from another namespace may be used (compare `namespaces <../generic/namespaces.html>`__ for additional information concerning class re-usage).
57
57
58
+
Naming
59
+
------
60
+
61
+
Naming of classes
62
+
^^^^^^^^^^^^^^^^^
63
+
64
+
If the given main object in a JSON-Schema file contains a `$id` the id will be used as class name. Otherwise the name of the file will be used.
65
+
66
+
Naming of nested classes
67
+
^^^^^^^^^^^^^^^^^^^^^^^^
68
+
69
+
Nested classes are prefixed with the parent class. If an object `Person` has a nested object `car` the class for car will be named **Person_Car**.
70
+
71
+
For the class name of a nested class the `$id` property of the nested object is used. If the id property isn't present the property key combined with a uniqid will be used.
72
+
58
73
Property Name Normalization
59
-
---------------------------
74
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
60
75
61
76
Property names are normalized to provide valid and readable PHP code. All non alpha numeric characters will be removed.
62
77
@@ -183,6 +198,57 @@ If invalid additional properties are provided a detailed exception will be throw
183
198
- invalid additional property 'additional2'
184
199
* Invalid type for age. Requires int, got string
185
200
201
+
Recursive Objects
202
+
-----------------
203
+
204
+
If objects are defined recursive the recursion will be resolved into a single class.
205
+
206
+
.. code-block:: json
207
+
208
+
{
209
+
"definitions": {
210
+
"person": {
211
+
"$id": "person",
212
+
"type": "object",
213
+
"properties": {
214
+
"name": {
215
+
"type": "string"
216
+
},
217
+
"children": {
218
+
"type": "array",
219
+
"items": {
220
+
"$ref": "#/definitions/person"
221
+
}
222
+
}
223
+
}
224
+
}
225
+
},
226
+
"$id": "family",
227
+
"type": "object",
228
+
"properties": {
229
+
"members": {
230
+
"type": "array",
231
+
"items": {
232
+
"$ref": "#/definitions/person"
233
+
}
234
+
}
235
+
}
236
+
}
237
+
238
+
Generated interface:
239
+
240
+
.. code-block:: php
241
+
242
+
// class Family, arrays typehinted in docblocks with Family_Person[]
243
+
public function setMembers(?array $members): self;
244
+
public function getMembers(): ?array;
245
+
246
+
// class Person, arrays typehinted in docblocks with Family_Person[]
References can be used to re-use parts/objects of JSON-Schema definitions.
9
+
10
+
Supported reference types
11
+
-------------------------
12
+
13
+
* internal (in a single file) reference by id (example: `"$ref": "IdOfMyObject"`)
14
+
* internal (in a single file) reference by path (example: `"$ref": "#/definitions/myObject"`)
15
+
* relative reference based on the location on the file system to a complete file (example: `"$ref": "./../modules/myObject.json"`)
16
+
* relative reference based on the location on the file system to an object by id (example: `"$ref": "./../modules/myObject.json#IdOfMyObject"`)
17
+
* relative reference based on the location on the file system to an object by path (example: `"$ref": "./../modules/myObject.json#/definitions/myObject"`)
18
+
* network reference to a complete file (example: `"$ref": "https://my.domain.com/schema/modules/myObject.json"`)
19
+
* network reference to an object by id (example: `"$ref": "https://my.domain.com/schema/modules/myObject.json#IdOfMyObject"`)
20
+
* network reference to an object by path (example: `"$ref": "https://my.domain.com/schema/modules/myObject.json#/definitions/myObject"`)
21
+
22
+
Object reference
23
+
----------------
24
+
25
+
An example for properties referring to a definition inside the same schema:
0 commit comments