Make WordPress Core

Opened 10 months ago

Closed 10 months ago

Last modified 4 months ago

#64139 closed defect (bug) (fixed)

Abilities API: Normalize input from schema

Reported by: gziolo Owned by: gziolo
Priority: normal Milestone: 6.9
Component: Abilities API Version: 6.9
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

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 (6)

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


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

  • Owner set to gziolo
  • Resolutionfixed
  • Status newclosed

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

  • Component GeneralAI

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


10 months ago
#4

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

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

#6 @desrosj
4 months ago

  • Component AIAbilities API

Moving tickets related to the Abilities API to a new sub-component.

Note: See TracTickets for help on using tickets.