Repository navigation
Abilities API: Encode empty object results as JSON objects - #14547
jorgefilipecosta wants to merge 1 commit 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 matchesThe 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.
The REST API's `_fields`, `_embed` and links processing expected array
data and failed with a fatal error on objects. Leave non-array data
unchanged when filtering fields or embedding links, since an empty
object has neither, and convert object data to an array when adding
links.
Follow-up to [64311], [64592].
See #66267, #66230.
d05b08b to
9d63d51
Compare
Follow up to https://core.trac.wordpress.org/changeset/64592 and #14139.
What
wp_prepare_json_value_for_client(), as the AI client already does, 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.[]._fieldsand_embedparameters, and response links, no longer fail with a fatal error on object data:_rest_array_intersect_key_recursive()(_fields) andWP_REST_Server::embed_links()(_embed) leave non-array data unchanged. An empty object has no fields to filter and no links to embed.WP_REST_Server::response_to_data()converts object data to an array before adding_links./wp/v2/taxonomies?type=wingding&_fields=namenow returns{}.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: