Skip to content

Commit b9712f4

Browse files
Fix: top level default is not valid json schema.
1 parent 81e3dbe commit b9712f4

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/wp-includes/abilities-api/class-wp-ability.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,18 @@ public function normalize_input( $input = null ) {
445445
}
446446

447447
$input_schema = $this->get_input_schema();
448-
if ( ! empty( $input_schema ) && array_key_exists( 'default', $input_schema ) ) {
449-
return $input_schema['default'];
448+
// This tries to compute a default value from the input schema properties.
449+
// It is a very basic implementation and does not cover all JSON Schema features.
450+
// It only looks for `default` values in the top-level `properties`.
451+
if ( ! empty( $input_schema ) && array_key_exists( 'properties', $input_schema ) ) {
452+
$result = array();
453+
foreach ( $input_schema['properties'] as $property_name => $property_schema ) {
454+
if ( array_key_exists( 'default', $property_schema ) ) {
455+
$result[ $property_name ] = $property_schema['default'];
456+
}
457+
}
458+
return $result;
450459
}
451-
452460
return null;
453461
}
454462

src/wp-includes/abilities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ function wp_register_core_abilities(): void {
9696
'type' => 'string',
9797
'enum' => $site_info_fields,
9898
),
99+
'default' => array(),
99100
'description' => __( 'Optional: Limit response to specific fields. If omitted, all fields are returned.' ),
100101
),
101102
),
102103
'additionalProperties' => false,
103-
'default' => array(),
104104
),
105105
'output_schema' => array(
106106
'type' => 'object',

0 commit comments

Comments
 (0)