Make WordPress Core

Opened 2 months ago

Last modified 10 days ago

#48785 new defect (bug)

REST API: WP_REST_Controller::get_public_item_schema() assumes that the schema has properties.

Reported by: pento Owned by:
Milestone: 5.4 Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: needs-unit-tests good-first-bug has-patch
Focuses: Cc:
PR Number:


My understanding of JSON Schema is that the base type doesn't necessarily need to be an object, it can be any type, so it's possible to define an endpoint that returns a string:

        '$schema'     => 'http://json-schema.org/draft-04/schema#',
        'title'       => 'foo',
        'type'        => 'string',
        'description' => __( 'This is my magical endpoint that just returns a string.' ),

Other methods on WP_REST_Controller seem to check that properties is defined on the schema, but ::get_public_item_schema() doesn't.

Attachments (2)

#48785.patch (530 bytes) - added by dhavalkasvala 2 months ago.
#48785-improve.patch (534 bytes) - added by dhavalkasvala 8 weeks ago.

Download all attachments as: .zip

Change History (11)

#1 @dkarfa
2 months ago

Hi @pento
Yes, ::get_item_schema() returing the properties

#2 @TimothyBlynJacobs
2 months ago

  • Milestone changed from Awaiting Review to 5.4

Yep, this would be good to fix. I've run into the issue as well.

#3 @dhavalkasvala
2 months ago

  • Keywords has-patch added; needs-patch removed

#4 @TimothyBlynJacobs
8 weeks ago

Thanks for working on a patch for this @dhavalkasvala! Do you want to try tackling a unit test for this? Coding standards wise, we should also have spaces around the parentheses.

#5 @TimothyBlynJacobs
5 weeks ago

Thanks for updating the patch @dhavalkasvala, this looks good! Do you want to work on a unit test for this? No worries if not.

#6 @dhavalkasvala
5 weeks ago

@TimothyBlynJacobs I want to work on unit test but don't how to do that right now.

Last edited 5 weeks ago by dhavalkasvala (previous) (diff)

#7 @TimothyBlynJacobs
5 weeks ago

No worries @dhavalkasvala! There is some documentation available on WordPress.org: https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/

I sent you a message on Slack as well. Feel free to ping me about getting started with it.

This ticket was mentioned in Slack in #core-restapi by pbiron. View the logs.

13 days ago

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.

10 days ago

Note: See TracTickets for help on using tickets.