Make WordPress Core

Opened 2 months ago

Closed 2 months ago

Last modified 2 months 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.


2 months 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
2 months 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
2 months ago

  • Component changed from General to AI

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


2 months ago
#4

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

Addresses feedback raised by @jorgefilipecosta during syncing changes to Abilties API repository:

Note: See TracTickets for help on using tickets.