-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix: Core abilities schemas. #10510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Core abilities schemas. #10510
Conversation
|
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. |
7bc010e to
fb4c1d0
Compare
fcd2d1d to
ad15c65
Compare
| 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; | ||
| } |
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
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 👍
gziolo
left a comment
There was a problem hiding this 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.
c8673ea to
38dcadf
Compare
…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
Supersede: #10508
This PR fixes two issues with the schema of our core abilities:
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.