#64139 closed defect (bug) (fixed)
Abilities API: Normalize input from schema
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| 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
#2
@
7 weeks ago
- Owner set to gziolo
- Resolution set to fixed
- Status changed from new to closed
In 61047:
This ticket was mentioned in PR #10424 on WordPress/wordpress-develop by @gziolo.
7 weeks ago
#4
Trac ticket: https://core.trac.wordpress.org/ticket/64139
Addresses feedback raised by @jorgefilipecosta during syncing changes to Abilties API repository:
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
?inputfield 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 fieldsGET
/run?input[fields][]=name # FilteredWe 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
defaultkey, this method returns the value of that key. If the input schema does not define adefault, or if the input schema is empty, this method returns null. If input is provided, it is returned as-is.