Opened 4 years ago
Last modified 4 years ago
#56368 new enhancement
Unable to use enum with array data type - REST API
| Reported by: | picocodes | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | REST API | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: | rest-api |
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi @picocodes, thank you for your report!
This modified schema will accept both string values like
'id', and array values like['id', 'title']: