Skip to content

Commit 93a5a0c

Browse files
wol-softclaude
andcommitted
Merge master into jsonSchemaDraft2019
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>
2 parents 2ad3cf0 + 7288262 commit 93a5a0c

84 files changed

Lines changed: 1540 additions & 315 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/source/combinedSchemas/allOf.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\ComposedValue\\All
6767
public function getPropertyName(): string
6868
// get the value provided to the property
6969
public function getProvidedValue()
70+
// get the JSON pointer to the schema keyword that rejected the value
71+
public function getJsonPointer(): JsonPointer
7072
7173
.. hint::
7274

docs/source/combinedSchemas/anyOf.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\ComposedValue\\Any
5757
public function getPropertyName(): string
5858
// get the value provided to the property
5959
public function getProvidedValue()
60+
// get the JSON pointer to the schema keyword that rejected the value
61+
public function getJsonPointer(): JsonPointer
6062
6163
.. note::
6264

docs/source/combinedSchemas/if.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\ComposedValue\\Con
6969
public function getPropertyName(): string
7070
// get the value provided to the property
7171
public function getProvidedValue()
72+
// get the JSON pointer to the schema keyword that rejected the value
73+
public function getJsonPointer(): JsonPointer
7274
7375
An object level composition will result in an object which contains all properties contained in the three possible blocks of the condition.
7476

docs/source/combinedSchemas/not.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\ComposedValue\\Not
4545
public function getPropertyName(): string
4646
// get the value provided to the property
4747
public function getProvidedValue()
48+
// get the JSON pointer to the schema keyword that rejected the value
49+
public function getJsonPointer(): JsonPointer
4850
4951
.. note::
5052

docs/source/combinedSchemas/oneOf.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\ComposedValue\\One
6767
public function getPropertyName(): string
6868
// get the value provided to the property
6969
public function getProvidedValue()
70+
// get the JSON pointer to the schema keyword that rejected the value
71+
public function getJsonPointer(): JsonPointer
7072
7173
.. note::
7274

docs/source/complexTypes/array.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Generic\\InvalidTy
4242
public function getPropertyName(): string
4343
// get the value provided to the property
4444
public function getProvidedValue()
45+
// get the JSON pointer to the schema keyword that rejected the value
46+
public function getJsonPointer(): JsonPointer
4547
4648
Items
4749
^^^^^
@@ -82,6 +84,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\InvalidIte
8284
public function getPropertyName(): string
8385
// get the value provided to the property
8486
public function getProvidedValue()
87+
// get the JSON pointer to the schema keyword that rejected the value
88+
public function getJsonPointer(): JsonPointer
8589
8690
A more complex array may contain a nested object.
8791

@@ -204,6 +208,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\InvalidTup
204208
public function getPropertyName(): string
205209
// get the value provided to the property
206210
public function getProvidedValue()
211+
// get the JSON pointer to the schema keyword that rejected the value
212+
public function getJsonPointer(): JsonPointer
207213
208214
.. hint::
209215

@@ -259,6 +265,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\Additional
259265
public function getPropertyName(): string
260266
// get the value provided to the property
261267
public function getProvidedValue()
268+
// get the JSON pointer to the schema keyword that rejected the value
269+
public function getJsonPointer(): JsonPointer
262270
263271
If invalid additional items are provided a detailed exception will be thrown containing all violations:
264272

@@ -280,6 +288,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\InvalidAdd
280288
public function getPropertyName(): string
281289
// get the value provided to the property
282290
public function getProvidedValue()
291+
// get the JSON pointer to the schema keyword that rejected the value
292+
public function getJsonPointer(): JsonPointer
283293
284294
Contains
285295
--------
@@ -313,6 +323,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\ContainsEx
313323
public function getPropertyName(): string
314324
// get the value provided to the property
315325
public function getProvidedValue()
326+
// get the JSON pointer to the schema keyword that rejected the value
327+
public function getJsonPointer(): JsonPointer
316328
317329
The ``contains`` keyword also accepts the boolean literals ``true`` and ``false``.
318330

@@ -358,6 +370,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Arrays\\MaxItemsEx
358370
public function getPropertyName(): string
359371
// get the value provided to the property
360372
public function getProvidedValue()
373+
// get the JSON pointer to the schema keyword that rejected the value
374+
public function getJsonPointer(): JsonPointer
361375
362376
Uniqueness
363377
----------
@@ -389,3 +403,5 @@ The thrown exception will be an *PHPModelGenerator\\Exception\\Arrays\\UniqueIte
389403
public function getPropertyName(): string
390404
// get the value provided to the property
391405
public function getProvidedValue()
406+
// get the JSON pointer to the schema keyword that rejected the value
407+
public function getJsonPointer(): JsonPointer

docs/source/complexTypes/enum.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ The thrown exception will be an *PHPModelGenerator\\Exception\\Generic\\EnumExce
7070
public function getPropertyName(): string
7171
// get the value provided to the property
7272
public function getProvidedValue()
73+
// get the JSON pointer to the schema keyword that rejected the value
74+
public function getJsonPointer(): JsonPointer

docs/source/complexTypes/multiType.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Generic\\InvalidTy
3737
public function getPropertyName(): string
3838
// get the value provided to the property
3939
public function getProvidedValue()
40+
// get the JSON pointer to the schema keyword that rejected the value
41+
public function getJsonPointer(): JsonPointer
4042
4143
Additional validators
4244
---------------------

docs/source/complexTypes/object.rst

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Generic\\InvalidTy
6363
public function getPropertyName(): string
6464
// get the value provided to the property
6565
public function getProvidedValue()
66+
// get the JSON pointer to the schema keyword that rejected the value
67+
public function getJsonPointer(): JsonPointer
6668
6769
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:
6870

@@ -74,6 +76,8 @@ The nested object will be validated in the nested class Car which may throw addi
7476
public function getPropertyName(): string
7577
// get the value provided to the property
7678
public function getProvidedValue()
79+
// get the JSON pointer to the schema keyword that rejected the value
80+
public function getJsonPointer(): JsonPointer
7781
7882
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.
7983

@@ -99,9 +103,40 @@ Otherwise, if an `$id` is present, the basename of the $id and as a last fallbac
99103
Naming of nested classes
100104
^^^^^^^^^^^^^^^^^^^^^^^^
101105

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
138+
to the generator configuration via
139+
`setClassNameGenerator() <../gettingStarted.html#class-name-generator>`__.
105140

106141
Property Name Normalization
107142
^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -231,6 +266,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Object\\MaxPropert
231266
public function getPropertyName(): string
232267
// get the value provided to the property
233268
public function getProvidedValue()
269+
// get the JSON pointer to the schema keyword that rejected the value
270+
public function getJsonPointer(): JsonPointer
234271
235272
Additional Properties
236273
---------------------
@@ -278,6 +315,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Object\\Additional
278315
public function getPropertyName(): string
279316
// get the value provided to the property
280317
public function getProvidedValue()
318+
// get the JSON pointer to the schema keyword that rejected the value
319+
public function getJsonPointer(): JsonPointer
281320
282321
If invalid additional properties are provided a detailed exception will be thrown containing all violations:
283322

@@ -299,6 +338,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Object\\InvalidAdd
299338
public function getPropertyName(): string
300339
// get the value provided to the property
301340
public function getProvidedValue()
341+
// get the JSON pointer to the schema keyword that rejected the value
342+
public function getJsonPointer(): JsonPointer
302343
303344
.. warning::
304345

@@ -395,6 +436,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Object\\InvalidPro
395436
public function getPropertyName(): string
396437
// get the value provided to the property
397438
public function getProvidedValue()
439+
// get the JSON pointer to the schema keyword that rejected the value
440+
public function getJsonPointer(): JsonPointer
398441
399442
Dependencies
400443
------------
@@ -444,6 +487,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Dependency\\Invali
444487
public function getPropertyName(): string
445488
// get the value provided to the property
446489
public function getProvidedValue()
490+
// get the JSON pointer to the schema keyword that rejected the value
491+
public function getJsonPointer(): JsonPointer
447492
448493
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:
449494

@@ -541,6 +586,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Dependency\\Invali
541586
public function getPropertyName(): string
542587
// get the value provided to the property
543588
public function getProvidedValue()
589+
// get the JSON pointer to the schema keyword that rejected the value
590+
public function getJsonPointer(): JsonPointer
544591
545592
Multiple violations against the schema dependency may be included.
546593

@@ -592,6 +639,8 @@ The thrown exception will be a *PHPModelGenerator\\Exception\\Object\\InvalidPat
592639
public function getPropertyName(): string
593640
// get the value provided to the property
594641
public function getProvidedValue()
642+
// get the JSON pointer to the schema keyword that rejected the value
643+
public function getJsonPointer(): JsonPointer
595644
596645
.. note::
597646

docs/source/generic/combinedException.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,11 @@ The exception which will be thrown (combined array-exception and combined-schema
8787
- Composition element #1: Failed
8888
* Missing required value for name
8989
* Invalid type for name. Requires string, got NULL
90-
- Composition element #2: Valid
90+
- Composition element #2: Valid
91+
92+
.. seealso::
93+
94+
Each leaf ``ValidationException`` inside a combined exception also exposes a JSON pointer to the
95+
schema keyword that rejected the value. See
96+
`Collect errors vs. early return <../gettingStarted.html#collect-errors-vs-early-return>`__
97+
for details on ``getJsonPointer()``.

0 commit comments

Comments
 (0)