Make WordPress Core

Opened 4 weeks ago

Closed 3 weeks ago

#64252 closed defect (bug) (fixed)

Fix: Core abilities schemas.

Reported by: jorgefilipecosta's profile jorgefilipecosta Owned by: jorgefilipecosta's profile jorgefilipecosta
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

Supersede: https://github.com/WordPress/wordpress-develop/pull/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 https://github.com/WordPress/abilities-api/pull/144, do the testing instructions of that PR and verify things worked.

#2 @jorgefilipecosta
4 weeks ago

  • Owner set to jorgefilipecosta
  • Resolution set to fixed
  • Status changed from new to closed

In 61244:

Fix: Core abilities invalid schemas (has examples and returns empty array 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.

#3 @jorgefilipecosta
4 weeks ago

  • Keywords dev-feedback added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for backport to 6.9.

#4 @jorbin
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 @gziolo
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.

This ticket was mentioned in Slack in #core by wildworks. View the logs.


3 weeks ago

#7 @wildworks
3 weeks ago

This ticket was brought up in today's Bug Scrub. Should we just backport the patch as is in time for 6.9 RC2 tomorrow?

#8 @jorgefilipecosta
3 weeks ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 61252:

Fix: Core abilities invalid schemas (has examples and returns empty array intested of object).

This 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 https://github.com/WordPress/wordpress-develop/pull/10510.

Props jorgefilipecosta, gziolo.
Fixes #64252.

Note: See TracTickets for help on using tickets.