Skip to content

Commit 7595ac7

Browse files
authored
Disable additionalProperties in json schema assertions (api-platform#3830)
1 parent cf69423 commit 7595ac7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Bridge/Symfony/Bundle/Test/ApiTestAssertionsTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use ApiPlatform\Core\JsonSchema\SchemaFactoryInterface;
2121
use PHPUnit\Framework\ExpectationFailedException;
2222
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
23+
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
2324
use Symfony\Contracts\HttpClient\ResponseInterface;
2425

2526
/**
@@ -111,14 +112,14 @@ public static function assertMatchesJsonSchema($jsonSchema, ?int $checkMode = nu
111112

112113
public static function assertMatchesResourceCollectionJsonSchema(string $resourceClass, ?string $operationName = null, string $format = 'jsonld'): void
113114
{
114-
$schema = self::getSchemaFactory()->buildSchema($resourceClass, $format, Schema::TYPE_OUTPUT, OperationType::COLLECTION, $operationName);
115+
$schema = self::getSchemaFactory()->buildSchema($resourceClass, $format, Schema::TYPE_OUTPUT, OperationType::COLLECTION, $operationName, null, [AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false]);
115116

116117
static::assertMatchesJsonSchema($schema->getArrayCopy());
117118
}
118119

119120
public static function assertMatchesResourceItemJsonSchema(string $resourceClass, ?string $operationName = null, string $format = 'jsonld'): void
120121
{
121-
$schema = self::getSchemaFactory()->buildSchema($resourceClass, $format, Schema::TYPE_OUTPUT, OperationType::ITEM, $operationName);
122+
$schema = self::getSchemaFactory()->buildSchema($resourceClass, $format, Schema::TYPE_OUTPUT, OperationType::ITEM, $operationName, null, [AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false]);
122123

123124
static::assertMatchesJsonSchema($schema->getArrayCopy());
124125
}

0 commit comments

Comments
 (0)