Repository navigation
Abilities API: Prepare empty object results for JSON clients - #14139
Sukhendu2002 wants to merge 1 commit into
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
gziolo
left a comment
There was a problem hiding this comment.
Everything else looks good to me. The schema handling and test coverage look solid. My only concern is the interaction with REST response processing noted inline. I’d be happy to address that in stages and move forward with the cases we can safely support now.
Prepare empty objects and nested values using their output schemas, reusing REST schema matching and validation helpers. Prefer array branches only when the value satisfies their array constraints, including nested branches and explicit or inferred types. Prepare complete AI client results and nested properties of associative REST results. Keep REST root empty arrays and numeric collections unchanged for compatibility with the server's _fields and _embed processing. Add focused schema regression tests and coverage for both client adapters. Validation: 774 tests and 1,474 assertions, with two existing PHPUnit warnings; coding standards and PHP compatibility checks pass. Co-authored-by: Grzegorz Ziolkowski <grzegorz@gziolo.pl> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
5b0ae36 to
0d92137
Compare
gziolo
left a comment
There was a problem hiding this comment.
Thanks, @Sukhendu2002! My feedback is addressed. With 7.2 Beta 1 today, I had to act fast and pushed the changes directly to this branch. I hope that's OK.
The main change: the REST run controller now prepares only associative results. Root empty results and numeric collections stay as they are for now, so _fields and _embed keep working. We can cover those in a follow-up.
Looks good to go! 🚀
|
Committed with https://core.trac.wordpress.org/changeset/64592. |
Trac ticket: https://core.trac.wordpress.org/ticket/66267
What
Adds
wp_prepare_json_value_for_client()to prepare ability results according to their output schema before sending them to JSON clients.The helper:
objectbut notarray.[]when bothobjectandarrayare allowed.properties,patternProperties,additionalProperties, and arrayitems.stdClass, andJsonSerializablevalues.Why
An ability can return an empty PHP array for an output schema with
type: object. Server-side validation accepts that value, but JSON encoding produces[]instead of{}.This violates the published output schema and can be rejected by strict clients or AI providers expecting an object. When both
objectandarrayare allowed, the empty array remains[]because its intended JSON type is ambiguous.Testing
npm run test:php -- --filter 'Tests_JSON_Schema|Tests_REST_API_WpRestAbilitiesV1RunController|Tests_AI_Client_AbilityFunctionResolver|Tests_AI_Client_PromptBuilder'Use of AI Tools
AI assistance: Yes
Tool(s): Pi agent
Model(s): GPT-5.6 Sol
Used for: Initial code skeleton, Test drafting
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.