Skip to content

Commit 7d7328f

Browse files
committed
REST API: Preserve client-side ability schema keywords
1 parent a73ffcb commit 7d7328f

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ public function get_item_permissions_check( $request ) {
191191
/**
192192
* Additional schema keywords to preserve in REST responses.
193193
*
194-
* These are not included in rest_get_allowed_schema_keywords(), but are
195-
* still recognized as schema traversal locations for ability schemas.
194+
* Ability schemas are exposed to clients as JSON Schema. Preserve additional
195+
* draft-04 keywords so clients can validate richer schemas, even when some
196+
* of those keywords are not enforced by the server-side REST schema validator.
196197
*
197198
* @since 7.1.0
198199
* @var string[]
@@ -201,6 +202,7 @@ public function get_item_permissions_check( $request ) {
201202
'required',
202203
'allOf',
203204
'not',
205+
'$ref',
204206
'definitions',
205207
'dependencies',
206208
'additionalItems',

tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,7 @@ public function test_internal_schema_keywords_stripped_from_nested_sub_schemas()
962962
'category' => 'general',
963963
'input_schema' => array(
964964
'type' => 'object',
965+
'$ref' => '#/definitions/address',
965966
'anyOf' => array(
966967
array(
967968
'type' => 'object',
@@ -1063,6 +1064,7 @@ public function test_internal_schema_keywords_stripped_from_nested_sub_schemas()
10631064
$data = $response->get_data();
10641065

10651066
// Verify internal keywords are stripped from anyOf sub-schemas.
1067+
$this->assertSame( '#/definitions/address', $data['input_schema']['$ref'] );
10661068
$this->assertArrayHasKey( 'anyOf', $data['input_schema'] );
10671069
$this->assertArrayNotHasKey( 'sanitize_callback', $data['input_schema']['anyOf'][0] );
10681070
$this->assertSame( 'object', $data['input_schema']['anyOf'][0]['type'] );

0 commit comments

Comments
 (0)