fix: use REST-safe ability union schemas - #3081
Merged
Merged
Conversation
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
typeunions with WordPress REST-supportedanyOfbranches while preserving every declared alternative_doing_it_wrong, representative content/nullable/multi-type, and Abilities REST response coverageRoot Cause
WordPress core supports array-valued
typedeclarations, butrest_validate_value_from_schema()only collapses a multi-type schema when the runtime value matches one of its members. When no member matches, the unresolved array reaches the built-in type check and emits the misleading_doing_it_wrongnotice before returning a validation error.The production
contentsignature comes from the core template/template-part REST schema inWP_REST_Templates_Controller, wherecontentisobject|string; list-valued payloads match neither type. Data Machine does not own or alter that core schema. This PR prevents the same failure mode in Data Machine's registered schemas by expressing unions with core'sanyOfrepresentation, which returns a normal no-matching-schema error without a developer notice.Core paths checked:
wp-includes/rest-api.php:rest_handle_multi_type_schema(),rest_find_any_matching_schema(),rest_validate_value_from_schema()wp-includes/abilities-api/class-wp-ability.php: input/output validationwp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php: schema exposurewp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-run-controller.php: REST execution validationwp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php: exactcontentsignalValidation
php tests/rest-schema-validation-smoke.phpwp --skip-plugins --skip-themes eval-file tests/rest-schema-validation-smoke.phpphp tests/ability-provider-bootstrap-idempotency-smoke.phpphp tests/lazy-runtime-ability-registration-smoke.phpphp tests/content-format-abilities-smoke.php(44 assertions)composer lint -- --report=summaryHomeboy's local PHPUnit gate selected the suite but reported zero executed tests, matching the candidate-gate infrastructure failure documented in Homeboy #12006. The focused source and real-WordPress runtime smokes above executed and passed independently.
Fixes #3067