WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/20/2020 08:17:20 PM (4 months ago)
Author:
TimothyBlynJacobs
Message:

REST API: Make sure all supported JSON Schema keywords are output in the index.

Previously, only a small subset of keywords were exposed which limited the utility of OPTIONS requests.

Props raubvogel, TimothyBlynJacobs.
Fixes #51020.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/class-wp-rest-server.php

    r49252 r49257  
    13811381        }
    13821382
     1383        $allowed_schema_keywords = array_flip( rest_get_allowed_schema_keywords() );
     1384
    13831385        $route = preg_replace( '#\(\?P<(\w+?)>.*?\)#', '{$1}', $route );
    13841386
     
    13981400
    13991401                foreach ( $callback['args'] as $key => $opts ) {
    1400                     $arg_data = array(
    1401                         'required' => ! empty( $opts['required'] ),
    1402                     );
    1403                     if ( isset( $opts['default'] ) ) {
    1404                         $arg_data['default'] = $opts['default'];
    1405                     }
    1406                     if ( isset( $opts['enum'] ) ) {
    1407                         $arg_data['enum'] = $opts['enum'];
    1408                     }
    1409                     if ( isset( $opts['description'] ) ) {
    1410                         $arg_data['description'] = $opts['description'];
    1411                     }
    1412                     if ( isset( $opts['type'] ) ) {
    1413                         $arg_data['type'] = $opts['type'];
    1414                     }
    1415                     if ( isset( $opts['items'] ) ) {
    1416                         $arg_data['items'] = $opts['items'];
    1417                     }
     1402                    $arg_data             = array_intersect_key( $opts, $allowed_schema_keywords );
     1403                    $arg_data['required'] = ! empty( $opts['required'] );
     1404
    14181405                    $endpoint_data['args'][ $key ] = $arg_data;
    14191406                }
Note: See TracChangeset for help on using the changeset viewer.