WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/20/2020 06:22:39 PM (15 months ago)
Author:
TimothyBlynJacobs
Message:

REST API: Add support for the oneOf and anyOf keywords.

This allows for REST API routes to define more complex validation requirements as JSON Schema instead of procedural validation.

The error code returned from rest_validate_value_from_schema for invalid parameter types has been changed from the generic rest_invalid_param to the more specific rest_invalid_type.

Props yakimun, johnbillion, TimothyBlynJacobs.
Fixes #51025.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-controller.php

    r49082 r49246  
    6767
    6868        $this->assertErrorResponse(
    69             'rest_invalid_param',
     69            'rest_invalid_type',
    7070            rest_validate_request_arg( 'abc', $this->request, 'someinteger' )
    7171        );
     
    141141
    142142        $this->assertErrorResponse(
    143             'rest_invalid_param',
     143            'rest_invalid_type',
    144144            rest_validate_request_arg( '123', $this->request, 'someboolean' )
    145145        );
     
    153153
    154154        $this->assertErrorResponse(
    155             'rest_invalid_param',
     155            'rest_invalid_type',
    156156            rest_validate_request_arg( array( 'foo' => 'bar' ), $this->request, 'somestring' )
    157157        );
     
    298298            'minProperties',
    299299            'maxProperties',
     300            'anyOf',
     301            'oneOf',
    300302        );
    301303        foreach ( $object_properties as $property ) {
Note: See TracChangeset for help on using the changeset viewer.