[wp-trac] [WordPress Trac] #56368: Unable to use enum with array data type - REST API

WordPress Trac noreply at wordpress.org
Sat Sep 3 08:46:05 UTC 2022


#56368: Unable to use enum with array data type - REST API
-------------------------+------------------------------
 Reporter:  picocodes    |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  REST API     |     Version:
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:  rest-api
-------------------------+------------------------------

Comment (by anna.bansaghi):

 This modified schema will accept both string values like `'id'`, and array
 values like `['id', 'title']`:
 {{{#!php
 <?php
    $query_schema['orderby'] = array(
     'description'       => __( 'Sort collection by object attribute.' ),
     'default'           => 'id',
     'oneOf'             => array(
         array(
             'type' => 'string',
             'enum' => array(
                 'id',
                 'title',
                 'date',
                 'include'
             )
         ),
         array(
             'type'  => 'array',
             'items' => array(
                 'type' => 'string',
                 'enum' => array(
                     'id',
                     'title',
                     'date',
                     'include'
                 )
             )
         )
     ),
     'validate_callback' => 'rest_validate_request_arg',
 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56368#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list