mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
REST API: Don't assume all item schemas have properties.
All schema types, not just objects, are permitted as the base type of a resource. A future patch could add validation support for those types, but this fix only prevents a PHP warning from being issued. Props dhavalkasvala, johnwatkins0, birgire. Fixes #48785. git-svn-id: https://develop.svn.wordpress.org/trunk@47328 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -154,6 +154,7 @@ require __DIR__ . '/exceptions.php';
|
||||
require __DIR__ . '/utils.php';
|
||||
require __DIR__ . '/spy-rest-server.php';
|
||||
require __DIR__ . '/class-wp-rest-test-search-handler.php';
|
||||
require __DIR__ . '/class-wp-rest-test-configurable-controller.php';
|
||||
require __DIR__ . '/class-wp-fake-block-type.php';
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Unit tests covering WP_REST_Controller functionality using a flexible schema.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage REST API
|
||||
* @since 5.4.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* WP_REST_Test_Configurable_Controller class.
|
||||
*
|
||||
* @group restapi
|
||||
*
|
||||
* @since 5.4.0
|
||||
*/
|
||||
class WP_REST_Test_Configurable_Controller extends WP_REST_Controller {
|
||||
|
||||
/**
|
||||
* Test schema.
|
||||
*
|
||||
* @since 5.4.0
|
||||
*
|
||||
* @var array $test_schema
|
||||
*/
|
||||
protected $test_schema;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 5.4.0
|
||||
*
|
||||
* @param array $test_schema Schema for use in testing.
|
||||
*/
|
||||
public function __construct( $test_schema ) {
|
||||
$this->test_schema = $test_schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the test schema.
|
||||
*
|
||||
* @since 5.4.0
|
||||
*
|
||||
* @return array Test schema.
|
||||
*/
|
||||
public function get_test_schema() {
|
||||
return $this->test_schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item's schema, conforming to JSON Schema.
|
||||
*
|
||||
* @since 5.4.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
return $this->add_additional_fields_schema( $this->get_test_schema() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user