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.


git-svn-id: https://develop.svn.wordpress.org/trunk@49246 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs
2020-10-20 18:22:39 +00:00
parent 194d32b970
commit 54aa0bc7d1
10 changed files with 1546 additions and 38 deletions

View File

@@ -128,6 +128,42 @@ class WP_REST_Test_Controller extends WP_REST_Controller {
),
'minProperties' => 1,
'maxProperties' => 10,
'anyOf' => array(
array(
'properties' => array(
'object_id' => array(
'type' => 'integer',
'minimum' => 100,
),
),
),
array(
'properties' => array(
'object_id' => array(
'type' => 'integer',
'maximum' => 100,
),
),
),
),
'oneOf' => array(
array(
'properties' => array(
'object_id' => array(
'type' => 'integer',
'minimum' => 100,
),
),
),
array(
'properties' => array(
'object_id' => array(
'type' => 'integer',
'maximum' => 100,
),
),
),
),
'ignored_prop' => 'ignored_prop',
'context' => array( 'view' ),
),