Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix: top level default is not valid json schema.
  • Loading branch information
jorgefilipecosta committed Nov 12, 2025
commit b9712f46fe1d9b41d35c21be82bfa726dce6613c
14 changes: 11 additions & 3 deletions src/wp-includes/abilities-api/class-wp-ability.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,18 @@
}

$input_schema = $this->get_input_schema();
if ( ! empty( $input_schema ) && array_key_exists( 'default', $input_schema ) ) {
return $input_schema['default'];
// This tries to compute a default value from the input schema properties.
// It is a very basic implementation and does not cover all JSON Schema features.
// It only looks for `default` values in the top-level `properties`.
if ( ! empty( $input_schema ) && array_key_exists( 'properties', $input_schema ) ) {
$result = array();

Check failure on line 452 in src/wp-includes/abilities-api/class-wp-ability.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Whitespace found at end of line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$result = array();
$result = array();

foreach ( $input_schema['properties'] as $property_name => $property_schema ) {
if ( array_key_exists( 'default', $property_schema ) ) {
$result[ $property_name ] = $property_schema['default'];
}
}
return $result;
}

return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/abilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@
'type' => 'string',
'enum' => $site_info_fields,
),
'default' => array(),

Check failure on line 99 in src/wp-includes/abilities.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 space after "=>"; 2 found
'description' => __( 'Optional: Limit response to specific fields. If omitted, all fields are returned.' ),
),
),
'additionalProperties' => false,
'default' => array(),
),
'output_schema' => array(
'type' => 'object',
Expand Down
Loading