Repository navigation
Abilities API: Encode empty object results as JSON objects - #14547
jorgefilipecosta wants to merge 2 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. 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. |
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. |
…nks. Add the `allow_fields`, `allow_embed` and `allow_links` route and handler options. When an option is false, the `_fields` parameter does not filter the response data, the `_embed` parameter does not embed linked resources, or the response links are not added to the response data as `_links`. A handler option takes precedence over the route option, as with `allow_batch`. This lets a route serve its response data as returned, for example data that follows a schema of its own or that is not an array. See #66267.
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.
Disable the `_fields` and `_embed` parameters and response links for the
run endpoint, so the result follows the ability's output schema whether
it is an object, an array, or a scalar value.
Follow-up to [64311], [64592].
See #66267.
9d63d51 to
374b904
Compare
Follow up to https://core.trac.wordpress.org/changeset/64592 and #14139.
Depends on #14671, whose commit is the first one here.
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.[].allow_fields,allow_embedandallow_linksto false (from REST API: Allow routes to disable_fields,_embedand response links #14671), 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: