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. Built from https://develop.svn.wordpress.org/trunk@49257 git-svn-id: http://core.svn.wordpress.org/trunk@49019 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -1874,6 +1874,43 @@ function rest_find_one_matching_schema( $value, $args, $param, $stop_after_first
|
||||
return $matching_schemas[0]['schema_object'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all valid JSON schema properties.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @return string[] All valid JSON schema properties.
|
||||
*/
|
||||
function rest_get_allowed_schema_keywords() {
|
||||
return array(
|
||||
'title',
|
||||
'description',
|
||||
'default',
|
||||
'type',
|
||||
'format',
|
||||
'enum',
|
||||
'items',
|
||||
'properties',
|
||||
'additionalProperties',
|
||||
'patternProperties',
|
||||
'minProperties',
|
||||
'maxProperties',
|
||||
'minimum',
|
||||
'maximum',
|
||||
'exclusiveMinimum',
|
||||
'exclusiveMaximum',
|
||||
'multipleOf',
|
||||
'minLength',
|
||||
'maxLength',
|
||||
'pattern',
|
||||
'minItems',
|
||||
'maxItems',
|
||||
'uniqueItems',
|
||||
'anyOf',
|
||||
'oneOf',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a value based on a schema.
|
||||
*
|
||||
@@ -2765,30 +2802,8 @@ function rest_get_endpoint_args_for_schema( $schema, $method = WP_REST_Server::C
|
||||
|
||||
$schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
|
||||
$endpoint_args = array();
|
||||
$valid_schema_properties = array(
|
||||
'type',
|
||||
'format',
|
||||
'enum',
|
||||
'items',
|
||||
'properties',
|
||||
'additionalProperties',
|
||||
'patternProperties',
|
||||
'minProperties',
|
||||
'maxProperties',
|
||||
'minimum',
|
||||
'maximum',
|
||||
'exclusiveMinimum',
|
||||
'exclusiveMaximum',
|
||||
'multipleOf',
|
||||
'minLength',
|
||||
'maxLength',
|
||||
'pattern',
|
||||
'minItems',
|
||||
'maxItems',
|
||||
'uniqueItems',
|
||||
'anyOf',
|
||||
'oneOf',
|
||||
);
|
||||
$valid_schema_properties = rest_get_allowed_schema_keywords();
|
||||
$valid_schema_properties = array_diff( $valid_schema_properties, array( 'default', 'required' ) );
|
||||
|
||||
foreach ( $schema_properties as $field_id => $params ) {
|
||||
|
||||
@@ -2802,10 +2817,6 @@ function rest_get_endpoint_args_for_schema( $schema, $method = WP_REST_Server::C
|
||||
'sanitize_callback' => 'rest_sanitize_request_arg',
|
||||
);
|
||||
|
||||
if ( isset( $params['description'] ) ) {
|
||||
$endpoint_args[ $field_id ]['description'] = $params['description'];
|
||||
}
|
||||
|
||||
if ( WP_REST_Server::CREATABLE === $method && isset( $params['default'] ) ) {
|
||||
$endpoint_args[ $field_id ]['default'] = $params['default'];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user