Description
When additionalProperties is a schema object (rather than false), each additional property value is validated against that schema — but the path is not incremented with the property key. Any validation errors from the sub-schema check are reported at the parent object's path instead of the specific property's path.
Affected Files
src/JsonSchema/Constraints/Drafts/Draft06/AdditionalPropertiesConstraint.php
src/JsonSchema/Constraints/Drafts/Draft07/AdditionalPropertiesConstraint.php
src/JsonSchema/Constraints/Drafts/Draft2019/AdditionalPropertiesConstraint.php
All three have a @todo comment acknowledging this:
$schemaConstraint->check($additionalPropertiesValue, $schema->additionalProperties, $path, $i); // @todo increment path
Steps to Reproduce
{
"properties": { "foo": {} },
"additionalProperties": { "type": "integer" }
}
Validating {"foo": "ok", "bar": "not-an-integer"} produces a type error at path `` (root) instead of /bar.
Expected Behaviour
The error path should point to the specific additional property that failed — e.g. /bar — not to the parent object.
Suggested Fix
Increment the path with the property key before passing it to the sub-schema check:
$schemaConstraint->check($additionalPropertiesValue, $schema->additionalProperties, $path->withAppendedPath($key), $i);
This depends on a path utility being available on JsonPointer — see issue #918 which tracks the same missing utility in RequiredConstraint.
Description
When
additionalPropertiesis a schema object (rather thanfalse), each additional property value is validated against that schema — but the path is not incremented with the property key. Any validation errors from the sub-schema check are reported at the parent object's path instead of the specific property's path.Affected Files
src/JsonSchema/Constraints/Drafts/Draft06/AdditionalPropertiesConstraint.phpsrc/JsonSchema/Constraints/Drafts/Draft07/AdditionalPropertiesConstraint.phpsrc/JsonSchema/Constraints/Drafts/Draft2019/AdditionalPropertiesConstraint.phpAll three have a
@todocomment acknowledging this:Steps to Reproduce
{ "properties": { "foo": {} }, "additionalProperties": { "type": "integer" } }Validating
{"foo": "ok", "bar": "not-an-integer"}produces a type error at path `` (root) instead of/bar.Expected Behaviour
The error path should point to the specific additional property that failed — e.g.
/bar— not to the parent object.Suggested Fix
Increment the path with the property key before passing it to the sub-schema check:
This depends on a path utility being available on
JsonPointer— see issue #918 which tracks the same missing utility inRequiredConstraint.