[wp-trac] [WordPress Trac] #52932: Rest Api enum validation does not work correctly WordPress 5.7

WordPress Trac noreply at wordpress.org
Sun Mar 28 10:50:17 UTC 2021


#52932: Rest Api enum validation does not work correctly WordPress 5.7
---------------------------+-----------------------------
 Reporter:  stefanjoebstl  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  REST API       |    Version:  5.7
 Severity:  normal         |   Keywords:  needs-patch
  Focuses:  rest-api       |
---------------------------+-----------------------------
 The following code produces an error when sending a json request with 1, 2
 or 3. If I don't use the enum validation it works fine...

 {{{#!php
 <?php
   register_rest_route($this->namespace, '/someendpoint', array(
     array(
       'methods' => WP_REST_Server::CREATABLE,
       'callback' => array($this, 'createEndpoint'),
       'args' => array(
         'gender' => array(
           'type' => 'number',
           'enum' => array(
             1,
             2,
             3,
           ),
         ),
       ),
     ),
 ));
 }}}

 The error says: gender isn't one of 1, 2 or 3.

 Kind regards
 Stefan

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52932>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list