Preserve empty JSON schema object maps#234
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #234 +/- ##
============================================
+ Coverage 88.12% 88.21% +0.08%
- Complexity 1213 1225 +12
============================================
Files 60 60
Lines 3934 3963 +29
============================================
+ Hits 3467 3496 +29
Misses 467 467
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
felixarntz
left a comment
There was a problem hiding this comment.
@chubes4 Thank you for the PR! Mostly looks good, a few minor things to address.
| $tools[] = [ | ||
| 'type' => 'function', | ||
| 'function' => $functionDeclaration->toArray(), | ||
| 'function' => $function, |
There was a problem hiding this comment.
isn't all this code just the same as this simpler version?
| 'function' => $function, | |
| $tools[] = [ | |
| 'type' => 'function', | |
| 'function' => $functionDeclaration->jsonSerialize(), |
| * | ||
| * @return array<string, mixed>|\stdClass|null The JSON-serializable parameters schema. | ||
| */ | ||
| public function getJsonSerializableParameters() |
There was a problem hiding this comment.
see above, this really shouldn't be a public method. it's oddly specific to be part of a public API, and doesn't seem needed as public anyway.
| * objects even when empty. PHP arrays cannot preserve that distinction | ||
| * without casting the empty map before serialization. | ||
| * | ||
| * @since 0.1.0 |
There was a problem hiding this comment.
@since annotations for new code must always use @since n.e.x.t.
| /** | ||
| * {@inheritDoc} | ||
| * | ||
| * @since 0.1.0 |
There was a problem hiding this comment.
see above. also applies throughout the PR.
|
Thank you! Will fix everything noted. |
Summary
FunctionDeclarationthat preserves empty JSON Schema object-map fields as{}.FunctionDeclaration::jsonSerialize()to use the safe parameter representation.Fixes #233.
Testing
vendor/bin/phpunit tests/unit/Tools/DTO/FunctionDeclarationTest.php --filter testJsonSerializationPreservesEmptySchemaObjectMapsvendor/bin/phpunit tests/unit/Providers/OpenAiCompatibleImplementation/AbstractOpenAiCompatibleTextGenerationModelTest.php --filter testPrepareToolsParamPreservesEmptySchemaObjectMapsvendor/bin/phpunit tests/unit/Tools/DTO/FunctionDeclarationTest.phpvendor/bin/phpunit tests/unit/Providers/OpenAiCompatibleImplementation/AbstractOpenAiCompatibleTextGenerationModelTest.phpcomposer phpcscomposer phpstanAI assistance