function ResourceResponseValidator::validateSchema
Same name in this branch
- 11.x core/modules/jsonapi/src/EventSubscriber/ResourceResponseValidator.php \Drupal\jsonapi\EventSubscriber\ResourceResponseValidator::validateSchema()
Same name and namespace in other branches
- 10 core/modules/jsonapi/src/EventSubscriber/ResourceResponseValidator.php \Drupal\jsonapi\EventSubscriber\ResourceResponseValidator::validateSchema()
- 9 core/modules/jsonapi/src/EventSubscriber/ResourceResponseValidator.php \Drupal\jsonapi\EventSubscriber\ResourceResponseValidator::validateSchema()
- 8.9.x core/modules/jsonapi/src/EventSubscriber/ResourceResponseValidator.php \Drupal\jsonapi\EventSubscriber\ResourceResponseValidator::validateSchema()
Validates a string against a JSON Schema. It logs any possible errors.
Parameters
object $schema: The JSON Schema object.
mixed $response_data: The JSON string to validate.
Return value
bool TRUE if the string is a valid instance of the schema. FALSE otherwise.
File
-
core/
modules/ jsonapi/ tests/ modules/ jsonapi_response_validator/ src/ EventSubscriber/ ResourceResponseValidator.php, line 119
Class
- ResourceResponseValidator
- Response subscriber that validates a JSON:API response.
Namespace
Drupal\jsonapi_response_validator\EventSubscriberCode
protected function validateSchema(object $schema, mixed $response_data) : bool {
// @phpstan-ignore method.deprecated
$this->validator
->check($response_data, $schema);
$is_valid = $this->validator
->isValid();
if (!$is_valid) {
$this->logger
->debug("Response failed validation.\nResponse:\n@data\n\nErrors:\n@errors", [
'@data' => Json::encode($response_data),
'@errors' => Json::encode($this->validator
->getErrors()),
]);
}
return $is_valid;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.