Repository navigation
Fix nested empty object validation - #646
Open
Adebayo120 wants to merge 1 commit into
Open
Adebayo120 wants to merge 1 commit into
Adebayo120 wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adebayo120
requested review from
CodeWithKyrian,
Nyholm,
chr-hertel and
soyuka
as code owners
October 31, 2026 15:15
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Schema coercion can incorrectly accept arrays as object-valued tool output while rejecting valid nullable-object and additional-property inputs.
3 open issues
What changed in this PR
This PR updates schema-aware data preparation to handle nested empty JSON objects that become empty PHP arrays during associative decoding.
Changes:
- Pass property and array-item schemas through recursive data conversion.
- Convert nested empty arrays to objects when the schema explicitly requires an object.
- Add a regression test for an empty nested
parametersobject.
| File | Description |
|---|---|
| tests/Unit/Capability/Discovery/SchemaValidatorTest.php | Adds coverage for nested empty-object validation. |
| src/Capability/Discovery/SchemaValidator.php | Adds schema-aware recursive conversion and schema lookup helpers. |
Review effort: Balanced
Comment on lines
+130
to
+131
| if (!$isRoot && $this->expectsObjectType($schema) && \is_array($data) && [] === $data) { | ||
| return new \stdClass(); |
Comment on lines
+165
to
+173
| if (\is_array($schema)) { | ||
| return isset($schema['type']) && 'object' === $schema['type']; | ||
| } | ||
|
|
||
| if (\is_object($schema)) { | ||
| return isset($schema->type) && 'object' === $schema->type; | ||
| } | ||
|
|
||
| return false; |
Comment on lines
+183
to
+187
| return $schema['items'] ?? null; | ||
| } | ||
|
|
||
| if (\is_object($schema) && isset($schema->properties) && \is_object($schema->properties)) { | ||
| return $schema->properties->{$property} ?? ($schema->items ?? null); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
json_decode(..., true)turns{}into an empty PHP array.{"parameters": {}}that previously failed withExpected object, but received array.Reproduction
Before the fix this returned an error complaining
/parameterswas an array rather than an object.Validation
php vendor/bin/phpunit tests/Unit/Capability/Discovery/SchemaValidatorTest.phpphp vendor/bin/phpstan analyse --no-progress --configuration=phpstan.dist.neon src/Capability/Discovery/SchemaValidator.php tests/Unit/Capability/Discovery/SchemaValidatorTest.phpphp vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --dry-run --diff src/Capability/Discovery/SchemaValidator.php tests/Unit/Capability/Discovery/SchemaValidatorTest.php