Make WordPress Core

Opened 12 days ago

Last modified 5 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 8 days ago.
#48785-improve.patch (534 bytes) - added by dhavalkasvala 4 days ago.

Download all attachments as: .zip

Change History (6)

#1 @dkarfa
12 days ago

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

#2 @TimothyBlynJacobs
11 days ago

  • Milestone changed from Awaiting Review to 5.4

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

8 days ago

#3 @dhavalkasvala
8 days ago

  • Keywords has-patch added; needs-patch removed

#4 @TimothyBlynJacobs
5 days 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.

Note: See TracTickets for help on using tickets.