Opened 2 years ago
Last modified 2 years ago
#56368 new enhancement
Unable to use enum with array data type - REST API
Reported by: | picocodes | 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)
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']
: