Repository navigation
Abilities API: Encode empty object results as JSON objects - #14547
jorgefilipecosta wants to merge 3 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
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. |
core/settings-get when no setting matches
8e657ba to
29c2ab8
Compare
|
I noted in #14139 that we should follow-up and figure out how to map |
29c2ab8 to
0437a0b
Compare
core/settings-get when no setting matches0437a0b to
e68fd10
Compare
core/settings-get when no setting matches
e68fd10 to
d05b08b
Compare
core/settings-get when no setting matchesd05b08b to
9d63d51
Compare
Hi @gziolo this PR was updated and addressed these issues. |
|
Could we let controllers explicitly opt out of The problem extends beyond objects to scalar values, where these transformations have no meaningful application. Currently, The ability execution controller could disable all three explicitly, preserving the ability’s output schema and making behavior predictable regardless of whether the result is an object, array, or scalar. |
9d63d51 to
374b904
Compare
gziolo
left a comment
There was a problem hiding this comment.
A few suggestions to make the test cases easier to follow and strengthen coverage of the response-preservation behavior.
374b904 to
cd02d31
Compare
|
I approved #14671, so let's commit it, and I will finish reviewing this one. Currently, it contains changes from both. |
|
@jorgefilipecosta, do we still want to include this in WordPress 7.2? |
cd02d31 to
0ac67da
Compare
|
Hi @gziolo, yes, I think so. The PR was rebased and is now only the run controller change on top of https://core.trac.wordpress.org/changeset/64689; without it |
gziolo
left a comment
There was a problem hiding this comment.
All my previous feedback is addressed, thanks! One optional simplification: now that data_processing has its own REST API coverage, the test matrix seems broader than this controller needs.
Could we test each output shape once, then keep focused cases for the route’s processing opt-out, ability-owned _links, the served settings response, and preloading? That would preserve the regression coverage while avoiding repeated tests of shared REST behavior.
| "PATCH", | ||
| "DELETE" | ||
| ], | ||
| "data_processing": { |
The run endpoint prepared only associative array results for JSON
clients, so an empty array returned for an object output schema, such as
the `core/settings-get` result when no setting matches, was encoded as []
and failed output validation in JSON clients. Prepare every result,
including root results, lists and object results, so empty objects are
encoded as {} while arrays stay arrays.
Register the run endpoint with the `data_processing` route option set to
`false`, so the `_fields` and `_embed` parameters and response links leave
the result unchanged and it follows the ability's output schema whether it
is an object, an array, or a scalar value.
Follow-up to [64311], [64592], [64689].
See #66267.
Test each output shape once, and keep focused tests for the run route's processing opt-out, the links returned by an ability, the served settings response and preloading, instead of repeating every shape with each combination of the global `_fields` and `_embed` parameters and response links.
cc4f554 to
eb63dba
Compare
Follow up to https://core.trac.wordpress.org/changeset/64592 (#14139) and https://core.trac.wordpress.org/changeset/64689 (#14671).
What
wp_prepare_json_value_for_client(), not only associative arrays. An empty array returned for an object output schema is now encoded as{}at the root, in lists, and inside object orJsonSerializableresults, instead of[], which the JS client (executeAbility()) rejected withability_invalid_output. This fixes it for all abilities, e.g.core/settings-getwhen no setting matches.[].data_processingroute option (from https://core.trac.wordpress.org/changeset/64689) tofalse, so_fields,_embedand response links leave the result unchanged, and it follows the ability's output schema whether it is an object, an array, or a scalar value.Issue found while testing the query abilities through the JS client; the fix was drafted with AI assistance and reviewed by me.
Trac ticket: https://core.trac.wordpress.org/ticket/66267
Testing
Verify unit tests are passing: