Skip to content

Abilities API: Add coverage for top-level required in input validation#12012

Open
gziolo wants to merge 1 commit into
WordPress:trunkfrom
gziolo:64955-abilities-required-tests
Open

Abilities API: Add coverage for top-level required in input validation#12012
gziolo wants to merge 1 commit into
WordPress:trunkfrom
gziolo:64955-abilities-required-tests

Conversation

@gziolo
Copy link
Copy Markdown
Member

@gziolo gziolo commented May 29, 2026

Summary

Adds focused test coverage documenting how a top-level required keyword is treated during WP_Ability::validate_input(), and removes inert top-level required flags from existing test schemas.

Background

WordPress validates object values against either a draft-04 required array of property names, or a draft-03 per-property required boolean (see rest_validate_value_from_schema()). A required flag placed at the root of a schema is never consulted by the validator, so it has no effect on validation. A number of test schemas in this file set required => true at the top level of simple-type schemas, which is inert and misleading.

Changes

  • New data-provider-driven test_validate_input_top_level_required, covering both valid and invalid input for each variant:
    • top-level required: true — inert (only type is enforced)
    • top-level required: false — inert; does not permit null
    • required omitted — baseline; identical behavior
    • draft-04 required array on an object type — honored; enforces property presence
  • Removes the inert top-level required => true flags from simple-type schemas. The meaningful per-property required flags in the object data set are preserved.

This is a test-only change: it validates existing WP_Ability behavior and adds no production code.

Trac ticket: https://core.trac.wordpress.org/ticket/64955

🤖 Generated with Claude Code

Document how a top-level `required` keyword is treated by WP_Ability::validate_input(). For a non-object root type it is inert: validation gates solely on `type`, and `required: false` does not make a `null` value acceptable. For an object type, a draft-04 `required` array of property names is honored and enforces property presence.

Also remove the inert top-level `required => true` flags that were set on simple-type schemas throughout the test file, since they had no effect on validation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props gziolo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant