Sets the “additionalProperties” to false by default for all object definitions in the schema.
Parameters
$schema
arrayrequired- The schema to modify.
Source
}
}
}
return $response_data;
}
/**
* Sets the "additionalProperties" to false by default for all object definitions in the schema.
*
* @since 5.5.0
* @since 5.6.0 Support the "patternProperties" keyword.
*
* @param array $schema The schema to modify.
* @return array The modified schema.
*/
function rest_default_additional_properties_to_false( $schema ) {
$type = (array) $schema['type'];
if ( in_array( 'object', $type, true ) ) {
if ( isset( $schema['properties'] ) ) {
foreach ( $schema['properties'] as $key => $child_schema ) {
$schema['properties'][ $key ] = rest_default_additional_properties_to_false( $child_schema );
}
}
if ( isset( $schema['patternProperties'] ) ) {
foreach ( $schema['patternProperties'] as $key => $child_schema ) {
$schema['patternProperties'][ $key ] = rest_default_additional_properties_to_false( $child_schema );
User Contributed Notes
You must log in before being able to contribute a note or feedback.