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
Conflicts resolved in AdditionalPropertiesAccessorPostProcessor:
- Kept both the &$updatedPropertiesCount parameter (from jsonSchemaDraft2019)
and the ->withJsonPointer() stamping (from master)
- Kept both new test methods: testMinPropertiesExceptionExposesCount and
testRegularPropertyMergedFromMultipleBranchesReportsFirstDeclaredPointer
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/source/complexTypes/object.rst
+52-3Lines changed: 52 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,6 +63,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Generic\\InvalidTy
63
63
public function getPropertyName(): string
64
64
// get the value provided to the property
65
65
public function getProvidedValue()
66
+
// get the JSON pointer to the schema keyword that rejected the value
67
+
public function getJsonPointer(): JsonPointer
66
68
67
69
The nested object will be validated in the nested class Car which may throw additional exceptions if invalid data is provided. If the internal validation of a nested object fails a *PHPModelGenerator\\Exception\\Generic\\NestedObjectException* will be thrown which provides the following methods to get further error details:
68
70
@@ -74,6 +76,8 @@ The nested object will be validated in the nested class Car which may throw addi
74
76
public function getPropertyName(): string
75
77
// get the value provided to the property
76
78
public function getProvidedValue()
79
+
// get the JSON pointer to the schema keyword that rejected the value
80
+
public function getJsonPointer(): JsonPointer
77
81
78
82
If `error collection <../gettingStarted.html#collect-errors-vs-early-return>`__ is enabled the nested exception returned by `getNestedException` will be an **ErrorRegistryException** containing all validation errors of the nested object. Otherwise it will contain the first validation error which occurred during the validation of the nested object.
79
83
@@ -99,9 +103,40 @@ Otherwise, if an `$id` is present, the basename of the $id and as a last fallbac
99
103
Naming of nested classes
100
104
^^^^^^^^^^^^^^^^^^^^^^^^
101
105
102
-
For the class name of a nested class the `title` property (fallback to `$id`) of the nested object is used.
103
-
If neither the title nor the $id property is present the property key will be prefixed with the parent class.
104
-
If an object `Person` has a nested object `car` without a `title` and an `$id` the class for car will be named **Person_Car**.
106
+
For the class name of a nested class the following priority order applies:
107
+
108
+
1. **title** — used as-is if present on the nested schema.
109
+
2. **$id** — the basename of the ``$id`` URI is used if present.
110
+
3. **$anchor** — the ``$anchor`` value is used if present (Draft 2019-09 and later). ``$anchor``
111
+
is a plain-string identifier with the same intent as ``$id`` but without URI semantics.
112
+
4. **Definition key** — when the nested schema is referenced from a named ``definitions`` or
113
+
``$defs`` slot (e.g. ``$ref: "#/definitions/address"``), the definition key is used
114
+
(e.g. ``address``). This produces stable, readable names even for schemas that carry no
115
+
``title``, ``$id``, or ``$anchor``.
116
+
5. **Inline property name** — when the schema is defined inline directly under a ``properties``
117
+
keyword, the property key is used without a content hash. Property keys are unique within
118
+
their containing object, so the combination of parent class name and property key is
119
+
already collision-free. For example, an inline ``car`` object inside ``Person`` becomes
120
+
**Person_Car**.
121
+
6. **Array items** — when the schema is the ``items`` of a named array property, the array
122
+
property name is extracted and ``Item`` is appended, making it clear that the class
123
+
represents one element of the array rather than the array itself. For example, the items
124
+
of a ``tags`` array property become **{Parent}_TagsItem**.
125
+
7. **Property name + content hash** — final fallback for schemas that do not match any of the
126
+
above (e.g. inline schemas inside composition branches like ``anyOf``/``oneOf``). The
127
+
property key is prefixed with the parent class name and a short content hash is appended
128
+
to avoid collisions between branches that share the same property name.
129
+
130
+
.. hint::
131
+
132
+
Set ``title``, ``$id``, or ``$anchor`` on nested schemas, or use named
133
+
``definitions``/``$defs`` entries, to get the most explicit and predictable class names.
134
+
Schemas with large ``definitions`` blocks that lack these keywords will automatically
135
+
receive names derived from their definition key.
136
+
137
+
For full control over class naming, implement ``ClassNameGeneratorInterface`` and pass it
@@ -231,6 +266,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Object\\MaxPropert
231
266
public function getPropertyName(): string
232
267
// get the value provided to the property
233
268
public function getProvidedValue()
269
+
// get the JSON pointer to the schema keyword that rejected the value
270
+
public function getJsonPointer(): JsonPointer
234
271
235
272
Additional Properties
236
273
---------------------
@@ -278,6 +315,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Object\\Additional
278
315
public function getPropertyName(): string
279
316
// get the value provided to the property
280
317
public function getProvidedValue()
318
+
// get the JSON pointer to the schema keyword that rejected the value
319
+
public function getJsonPointer(): JsonPointer
281
320
282
321
If invalid additional properties are provided a detailed exception will be thrown containing all violations:
283
322
@@ -299,6 +338,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Object\\InvalidAdd
299
338
public function getPropertyName(): string
300
339
// get the value provided to the property
301
340
public function getProvidedValue()
341
+
// get the JSON pointer to the schema keyword that rejected the value
342
+
public function getJsonPointer(): JsonPointer
302
343
303
344
.. warning::
304
345
@@ -395,6 +436,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Object\\InvalidPro
395
436
public function getPropertyName(): string
396
437
// get the value provided to the property
397
438
public function getProvidedValue()
439
+
// get the JSON pointer to the schema keyword that rejected the value
440
+
public function getJsonPointer(): JsonPointer
398
441
399
442
Dependencies
400
443
------------
@@ -444,6 +487,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Dependency\\Invali
444
487
public function getPropertyName(): string
445
488
// get the value provided to the property
446
489
public function getProvidedValue()
490
+
// get the JSON pointer to the schema keyword that rejected the value
491
+
public function getJsonPointer(): JsonPointer
447
492
448
493
As stated above the dependency declaration is not bidirectional. If the presence of a billing_address shall also require the credit_card property to be required the dependency has to be declared separately:
449
494
@@ -541,6 +586,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Dependency\\Invali
541
586
public function getPropertyName(): string
542
587
// get the value provided to the property
543
588
public function getProvidedValue()
589
+
// get the JSON pointer to the schema keyword that rejected the value
590
+
public function getJsonPointer(): JsonPointer
544
591
545
592
Multiple violations against the schema dependency may be included.
546
593
@@ -592,6 +639,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Object\\InvalidPat
592
639
public function getPropertyName(): string
593
640
// get the value provided to the property
594
641
public function getProvidedValue()
642
+
// get the JSON pointer to the schema keyword that rejected the value
0 commit comments