Skip to content

Commit b62521d

Browse files
committed
fix: add additionalProperties (false) to the generated JSON schema
1 parent 8e58a98 commit b62521d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/JsonSchema/SchemaFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function buildSchema(string $className, string $format = 'json', string $
109109
return $schema;
110110
}
111111

112-
$definition = new \ArrayObject(['type' => 'object']);
112+
$definition = new \ArrayObject(['type' => 'object', 'additionalProperties' => false]);
113113
$definitions[$definitionName] = $definition;
114114
if (null !== $resourceMetadata && null !== $description = $resourceMetadata->getDescription()) {
115115
$definition['description'] = $description;

tests/JsonSchema/SchemaFactoryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function testBuildSchemaForNonResourceClass(): void
7373
$this->assertArrayHasKey($rootDefinitionKey, $definitions);
7474
$this->assertArrayHasKey('type', $definitions[$rootDefinitionKey]);
7575
$this->assertSame('object', $definitions[$rootDefinitionKey]['type']);
76+
$this->assertFalse($definitions[$rootDefinitionKey]['additionalProperties']);
7677
$this->assertArrayHasKey('properties', $definitions[$rootDefinitionKey]);
7778
$this->assertArrayHasKey('foo', $definitions[$rootDefinitionKey]['properties']);
7879
$this->assertArrayHasKey('type', $definitions[$rootDefinitionKey]['properties']['foo']);
@@ -136,6 +137,7 @@ public function testBuildSchemaForOperationWithOverriddenSerializerGroups(): voi
136137
$this->assertArrayHasKey($rootDefinitionKey, $definitions);
137138
$this->assertArrayHasKey('type', $definitions[$rootDefinitionKey]);
138139
$this->assertSame('object', $definitions[$rootDefinitionKey]['type']);
140+
$this->assertFalse($definitions[$rootDefinitionKey]['additionalProperties']);
139141
$this->assertArrayHasKey('properties', $definitions[$rootDefinitionKey]);
140142
$this->assertArrayHasKey('alias', $definitions[$rootDefinitionKey]['properties']);
141143
$this->assertArrayHasKey('type', $definitions[$rootDefinitionKey]['properties']['alias']);

0 commit comments

Comments
 (0)