diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php index 4e90f4fba2..37fa0a0e73 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php @@ -239,7 +239,7 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller { ), 'rating' => array( 'description' => __( 'The star rating of the block.' ), - 'type' => 'integer', + 'type' => 'number', 'context' => array( 'view' ), ), 'rating_count' => array( @@ -249,12 +249,12 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller { ), 'active_installs' => array( 'description' => __( 'The number sites that have activated this block.' ), - 'type' => 'string', + 'type' => 'integer', 'context' => array( 'view' ), ), 'author_block_rating' => array( 'description' => __( 'The average rating of blocks published by the same author.' ), - 'type' => 'integer', + 'type' => 'number', 'context' => array( 'view' ), ), 'author_block_count' => array( diff --git a/tests/phpunit/tests/rest-api/rest-block-directory-controller.php b/tests/phpunit/tests/rest-api/rest-block-directory-controller.php index f772c1e026..4658b0ae7e 100644 --- a/tests/phpunit/tests/rest-api/rest-block-directory-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-directory-controller.php @@ -212,6 +212,46 @@ class WP_REST_Block_Directory_Controller_Test extends WP_Test_REST_Controller_Te $this->assertArrayHasKey( 'humanized_updated', $properties ); } + /** + * @ticket 53621 + */ + public function test_get_items_response_conforms_to_schema() { + wp_set_current_user( self::$admin_id ); + $plugin = $this->get_mock_plugin(); + + // Fetch the block directory schema. + $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/block-directory/search' ); + $schema = rest_get_server()->dispatch( $request )->get_data()['schema']; + + add_filter( + 'plugins_api', + static function () use ( $plugin ) { + return (object) array( + 'info' => + array( + 'page' => 1, + 'pages' => 1, + 'results' => 1, + ), + 'plugins' => array( + $plugin, + ), + ); + } + ); + + // Fetch a block plugin. + $request = new WP_REST_Request( 'GET', '/wp/v2/block-directory/search' ); + $request->set_query_params( array( 'term' => 'cache' ) ); + + $result = rest_get_server()->dispatch( $request ); + $data = $result->get_data(); + + $valid = rest_validate_value_from_schema( $data[0], $schema ); + + $this->assertNotWPError( $valid ); + } + /** * Simulate a network failure on outbound http requests to a given hostname. *