Skip to content

Conversation

@jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Nov 12, 2025

Supersede: #10508

This PR fixes two issues with the schema of our core abilities:

  • It includes examples, which is not compliant with the draft-04 JSON schema we are using, causing problems when the schema is used on client validation.
  • One of the defaults is an empty array that gets passed to the client as [] and not {}. When [] is validated on the client it is not a valid input and things fail.

cc: @gziolo

Ticket: https://core.trac.wordpress.org/ticket/64252

Testing

On the browser console execute:
wp.apiFetch({ path: '/wp-abilities/v1/abilities/'} ).then(console.log);

Verify ability core/get-environment-info has no examples on the output schema.
Verify core/get-site-info input schema default is {} and not [].

Test abilities API plugin with PR WordPress/abilities-api#144, do the testing instructions of that PR and verify things worked.

@github-actions
Copy link

github-actions bot commented Nov 12, 2025

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 jorgefilipecosta, 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

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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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.

@jorgefilipecosta jorgefilipecosta force-pushed the fix/core-abilities-schemas branch 2 times, most recently from 7bc010e to fb4c1d0 Compare November 12, 2025 20:48
@jorgefilipecosta jorgefilipecosta force-pushed the fix/core-abilities-schemas branch from fcd2d1d to ad15c65 Compare November 13, 2025 10:43
Comment on lines 219 to 223
if ( isset( $data['input_schema']['type'] ) && 'object' === $data['input_schema']['type'] && isset( $data['input_schema']['default'] ) ) {
$default = $data['input_schema']['default'];
if ( is_array( $default ) && empty( $default ) ) {
$data['input_schema']['default'] = (object) $default;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest extracting it as a helper method and applying it directly to the result from $ability->get_input_schema() and $ability->get_output_schema().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will apply the feedback 👍

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. There is some follow-up refactor possible as outlined in https://github.com/WordPress/wordpress-develop/pull/10510/files#r2523298859.

@jorgefilipecosta jorgefilipecosta force-pushed the fix/core-abilities-schemas branch from c8673ea to 38dcadf Compare November 13, 2025 19:31
pento pushed a commit that referenced this pull request Nov 13, 2025
…rray intested of object).

Theis commit fixes two issues with the core abilities schemas we have:
- They have examples on the schema with is not complient with the version draft-04 of schema JSON we are using.
- The top level defaults are defined as an empty array and they are of type object, but a php empty array gets JSON serialized and returned in the rest API as [] instead of {}, causing problems on the client validation.

Developed in #10510.

Props jorgefilipecosta, gziolo.
Fixes #64252.

git-svn-id: https://develop.svn.wordpress.org/trunk@61244 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions
Copy link

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 61244
GitHub commit: 2b0423d

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Nov 13, 2025
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.

2 participants