You are here

protected function ResourceResponseValidator::validateSchema in JSON:API 8.2

Same name and namespace in other branches
  1. 8 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 src/EventSubscriber/ResourceResponseValidator.php
Validates a response against the JSON:API specification.

File

src/EventSubscriber/ResourceResponseValidator.php, line 250

Class

ResourceResponseValidator
Response subscriber that validates a JSON:API response.

Namespace

Drupal\jsonapi\EventSubscriber

Code

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;
}