function JsonSchemaTestTrait::doCheckSchemaAgainstMetaSchema

Check a schema is valid against the meta-schema.

Parameters

array $defined_schema: Defined schema.

bool $accept_no_schema_type: Whether to accept a schema with no meaningful type construct.

4 calls to JsonSchemaTestTrait::doCheckSchemaAgainstMetaSchema()
JsonApiTopLevelResourceNormalizerTest::testConfigEntityResourceObjectSchema in core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiTopLevelResourceNormalizerTest.php
Test the generated config resource object normalization against the schema.
JsonApiTopLevelResourceNormalizerTest::testResourceObjectSchema in core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiTopLevelResourceNormalizerTest.php
Test the generated resource object normalization against the schema.
JsonApiTopLevelResourceNormalizerTest::testTopLevelResourceWithSingleResource in core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiTopLevelResourceNormalizerTest.php
JsonSchemaTestTrait::doTestJsonSchemaIsValid in core/modules/serialization/tests/src/Traits/JsonSchemaTestTrait.php
Validate the normalizer's JSON schema.

File

core/modules/serialization/tests/src/Traits/JsonSchemaTestTrait.php, line 65

Class

JsonSchemaTestTrait
Trait for testing JSON Schema validity and fit to sample data.

Namespace

Drupal\Tests\serialization\Traits

Code

protected function doCheckSchemaAgainstMetaSchema(array $defined_schema, bool $accept_no_schema_type = FALSE) : void {
    $validator = $this->getValidator();
    // Ensure the schema contains a meaningful type construct.
    if (!$accept_no_schema_type) {
        $this->assertFalse(empty(array_filter(array_keys($defined_schema), fn($key) => in_array($key, [
            'type',
            'allOf',
            'oneOf',
            'anyOf',
            'not',
            '$ref',
        ]))));
    }
    // All associative arrays must be encoded as objects.
    $schema = json_decode(json_encode($defined_schema));
    $validator->validate($schema, (object) [
        '$ref' => 'file://' . __DIR__ . '/../../../src/json-schema-draft-04-meta-schema.json',
    ]);
    $this->assertTrue($validator->isValid());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.