Opened 3 years ago
Last modified 3 years ago
#56368 new enhancement
Unable to use enum with array data type - REST API
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | REST API | Keywords: | |
| Focuses: | rest-api | Cc: |
Description
I would like to be able to specify enums when creating a REST schema property that accepts an array of values.
For example:
<?PHP $query_schema['orderby'] = array( 'description' => __( 'Sort collection by object attribute.' ), 'type' => array( 'string', 'array' ), 'default' => 'id', 'items' => array( 'type' => 'string', ), 'enum' => array( 'id', 'title', 'date', 'include' ), 'validate_callback' => 'rest_validate_request_arg', );
Change History (3)
#3
@
3 years ago
- Keywords reporter-feedback removed
I have just noticed another ticket which was reporting issues with the schema I have suggested: #54740
I am sorry giving bad advice!
Also in that ticket there is a comment with the same enhancement you gave: https://core.trac.wordpress.org/ticket/54740#comment:3
Version 0, edited 3 years ago
by
(next)
Note: See
TracTickets for help on using
tickets.
Hi @picocodes, thank you for your report!
I have tested your schema with this validator https://jsonschemalint.com/#!/version/draft-04/markup/json, and not accepting array values is the correct behavior.
What do you think, can you use the schema below instead? It will accept both string values like
'id', and array values like['id', 'title']: