Repository navigation
REST API: Use wp_prepare_json_value_for_client() for view configs and entity fields - #14552
jorgefilipecosta wants to merge 1 commit into
Conversation
…nd entity fields. Remove the private `_rest_cast_empty_objects_from_schema()` helper, which `wp_prepare_json_value_for_client()` supersedes. The public function also recurses into `oneOf`/`anyOf` branches, `patternProperties`, objects and `JsonSerializable` values, and keeps an empty array as `[]` when the schema also allows an array. Follow-up to [64503], [64592]. See #66267.
|
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. |
…nd entity fields. Removes the private `_rest_cast_empty_objects_from_schema()` helper, so a single function prepares empty objects according to a schema. The view config and entity fields endpoints now call `wp_prepare_json_value_for_client()`, and `WP_REST_View_Config_Controller::cast_empty_objects()` delegates to it. The private helper was added in this release cycle, so it is removed without deprecation. `wp_prepare_json_value_for_client()` also recurses into the matching `oneOf`/`anyOf` branch and into `patternProperties`, and keeps `[]` when the schema also allows an array. No view config or entity fields schema allows both an object and an array, so the existing responses are unchanged. Developed in #14552. Follow-up to [64503], [64592]. Props jorgefilipecosta, oandregal. See #66267. git-svn-id: https://develop.svn.wordpress.org/trunk@64602 602fd350-edb4-49c9-b593-d223f7449a82
…nd entity fields. Removes the private `_rest_cast_empty_objects_from_schema()` helper, so a single function prepares empty objects according to a schema. The view config and entity fields endpoints now call `wp_prepare_json_value_for_client()`, and `WP_REST_View_Config_Controller::cast_empty_objects()` delegates to it. The private helper was added in this release cycle, so it is removed without deprecation. `wp_prepare_json_value_for_client()` also recurses into the matching `oneOf`/`anyOf` branch and into `patternProperties`, and keeps `[]` when the schema also allows an array. No view config or entity fields schema allows both an object and an array, so the existing responses are unchanged. Developed in WordPress/wordpress-develop#14552. Follow-up to [64503], [64592]. Props jorgefilipecosta, oandregal. See #66267. Built from https://develop.svn.wordpress.org/trunk@64602 git-svn-id: http://core.svn.wordpress.org/trunk@63752 1a063a9b-81f0-0310-95a4-ce76da25c4cd
|
Committed at 3673e3a. |
…nfigs and entity fields Mirrors WordPress/wordpress-develop#14552: replaces `gutenberg_rest_cast_empty_objects_from_schema()` with a copy of core's `wp_prepare_json_value_for_client()` (and its private `_wp_json_schema_matches_type()` helper), and ports core's tests.
…nfigs and entity fields Mirrors WordPress/wordpress-develop#14552: replaces `gutenberg_rest_cast_empty_objects_from_schema()` with a copy of core's `wp_prepare_json_value_for_client()` (and its private `_wp_json_schema_matches_type()` helper), and ports core's tests.
Follow up to https://core.trac.wordpress.org/changeset/64503 and https://core.trac.wordpress.org/changeset/64592.
This PR removes the private
_rest_cast_empty_objects_from_schema()helper and uses the publicwp_prepare_json_value_for_client()instead, so there is a single function that prepares empty objects according to a schema:wp_prepare_json_value_for_client().WP_REST_View_Config_Controller::cast_empty_objects()(since 7.1) is kept and delegates to it.wp_prepare_json_value_for_client()also handles cases the private helper missed: it recurses into the matchingoneOf/anyOfbranch (e.g. a form fieldchildren: [ [] ]is now[ {} ]),patternProperties,stdClassandJsonSerializablevalues, and keeps[]when the schema also allows an array. No view config or entity fields schema allows both an object and an array, so the existing responses are unchanged.The change was drafted with AI assistance and reviewed by me.
Trac ticket: https://core.trac.wordpress.org/ticket/66267
Testing
Verify unit tests are passing: