function ResourceResponseValidator::validateSchema
Same name in other branches
- 8.9.x core/modules/jsonapi/src/EventSubscriber/ResourceResponseValidator.php \Drupal\jsonapi\EventSubscriber\ResourceResponseValidator::validateSchema()
- 10 core/modules/jsonapi/src/EventSubscriber/ResourceResponseValidator.php \Drupal\jsonapi\EventSubscriber\ResourceResponseValidator::validateSchema()
- 11.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.
string $response_data: The JSON string to validate.
Return value
bool TRUE if the string is a valid instance of the schema. FALSE otherwise.
1 call to ResourceResponseValidator::validateSchema()
- ResourceResponseValidator::validateResponse in core/
modules/ jsonapi/ src/ EventSubscriber/ ResourceResponseValidator.php - Validates a response against the JSON:API specification.
File
-
core/
modules/ jsonapi/ src/ EventSubscriber/ ResourceResponseValidator.php, line 167
Class
- ResourceResponseValidator
- Response subscriber that validates a JSON:API response.
Namespace
Drupal\jsonapi\EventSubscriberCode
protected function validateSchema($schema, $response_data) {
$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.