Opened 4 weeks ago
Closed 3 weeks ago
#64252 closed defect (bug) (fixed)
Fix: Core abilities schemas.
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | General | Keywords: | has-patch dev-reviewed |
| Focuses: | Cc: |
Description
There are 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.
This ticket tracks the fixes.
Change History (8)
This ticket was mentioned in PR #10510 on WordPress/wordpress-develop by @jorgefilipecosta.
4 weeks ago
#1
#2
@
4 weeks ago
- Owner set to jorgefilipecosta
- Resolution set to fixed
- Status changed from new to closed
In 61244:
#3
@
4 weeks ago
- Keywords dev-feedback added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for backport to 6.9.
#4
@
4 weeks ago
They have examples on the schema with is not complient with the version draft-04 of schema JSON we are using.
Is this something that we can have a test to ensure there isn't an issue in the future?
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.
Is this an issue with any other REST endpoints? Should it be fixed in a more global manner rather than in a single endpoint?
#5
@
4 weeks ago
- Keywords dev-reviewed added; dev-feedback removed
I reviewed the patch, and it looks good. Adding a unit test covering this edge case would be beneficial.
@jorbin, good question whether it would make sense to lift it up higher in the REST API handler. My understanding is that this problem exists primarily when you pass JSON as data in the response. In this particular case, we know exactly the expected type of the default value, so we can correct it accordingly so it transforms correctly when serialized to JSON.
Supersede: https://github.com/WordPress/wordpress-develop/pull/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 https://github.com/WordPress/abilities-api/pull/144, do the testing instructions of that PR and verify things worked.