Repository navigation
Conversation
The helper added in [64592] was only exercised indirectly through `wp_prepare_json_value_for_client()`. Add a data provider covering explicit and inherited types, anyOf/oneOf branches, nested combining keywords, and the case where the type and a valid value are found in different branches. Follow-up to [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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_wp_json_schema_matches_type()was added in r64592 / ba4c6de (#66267) and is currently only tested indirectly throughwp_prepare_json_value_for_client(). This PR adds direct tests for it.The new data provider covers:
typeallows the requested typeminItems)type,anyOforoneOf(returnsfalse)anyOfwith a matching branchanyOfwhere the type is in one branch and the valid value is in another (must be rejected, as the docblock says)oneOfwith no branch of the requested type, and with two matching branchesanyOfandoneOftogether (both must match)anyOfnested insideoneOfobjectrequested for an empty arrayThe patch only adds tests. The helper's code is unchanged.
Notes for reviewers
Two behaviours came up while writing these. Neither is introduced by r64592.
rest_validate_value_from_schema()still gets the full schema, so an invalid string branch next to a matching array branch causes aTypeErrorinrest-api.php.rest_find_any_matching_schema()fails the same way on such a schema, so I didn't add that case.rest_is_object()treats a PHP list such asarray( 'a' )as a valid object. SooneOfwith anobjectbranch next to anarraybranch can count as two matches.Testing
phpunit --group json-schema: OK (92 tests, 149 assertions)phpunit -c tests/phpunit/multisite.xml --group json-schema: OK (92 tests, 149 assertions)phpcs tests/phpunit/tests/json-schema.php: no issuesTrac ticket: https://core.trac.wordpress.org/ticket/66267
Use of AI Tools
I used Claude Code (Anthropic) to help write the test cases and this description. I reviewed every case, ran the tests locally, and checked the results.
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 WordPress Core Handbook for more details.