Make WordPress Core

Opened 7 weeks ago

Closed 7 weeks ago

Last modified 7 weeks ago

#64139 closed defect (bug) (fixed)

Abilities API: Normalize input from schema

Reported by: gziolo's profile gziolo Owned by: gziolo's profile gziolo
Milestone: 6.9 Priority: normal
Severity: normal Version: 6.9
Component: AI Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Bug fix extracted from WordPress/abilities-api#108.

Follow-up for https://core.trac.wordpress.org/ticket/64098.

Normalizes the input for the ability, applying the default value from the input schema when needed.

When no input is provided and the input schema is defined with a top-level default key, this method returns the value of that key. If the input schema does not define a default, or if the input schema is empty, this method returns null. If input is provided, it is returned as-is.

Change History (5)

This ticket was mentioned in PR #10395 on WordPress/wordpress-develop by @gziolo.


7 weeks ago
#1

Trac ticket: https://core.trac.wordpress.org/ticket/64139

Bug fix extracted from https://github.com/WordPress/abilities-api/pull/108.

## The problem

Without this patch REST would require a weird empty ?input field given how the current controller works with input schema that defines specific shape, example:

'input_schema'        => array(
        'type'                 => 'object',
        'properties'           => array(
                'fields' => array(
                        'type'        => 'array',
                        'items'       => array(
                                'type' => 'string',
                                'enum' => $fields,
                        ),
                        'description' => __( 'Optional: Limit response to specific fields. If omitted, all fields are returned.' ),
                ),
        ),
        'additionalProperties' => false,
        'default'              => array(),
),

Working examples:

GET /run?input # All fields
GET /run?input[fields][]=name # Filtered

We want the REST API controller to infer default value from the input schema, so it's possible to call:

GET /run # All fields

## Solution

Normalizes the input for the ability, applying the default value from the input schema when needed.

When no input is provided and the input schema is defined with a top-level default key, this method returns the value of that key. If the input schema does not define a default, or if the input schema is empty, this method returns null. If input is provided, it is returned as-is.

#2 @gziolo
7 weeks ago

  • Owner set to gziolo
  • Resolution set to fixed
  • Status changed from new to closed

In 61047:

Abilities API: Normalize input from schema

Without this patch REST API would require a weird empty ?input field for optional input given how the current controller works with input schema when it defines the expected shape. This patch normalizes the input for the ability, applying the default value from the input schema when needed.

Developed in https://github.com/WordPress/wordpress-develop/pull/10395.

Follow-up [61032], [61045].

Props gziolo, jorgefilipecosta, mukesh27.
Fixes #64139.

#3 @jorbin
7 weeks ago

  • Component changed from General to AI
Note: See TracTickets for help on using tickets.