Skip to content

Commit 5111935

Browse files
authored
fix(symfony): object typed property schema collection restriction (#6823)
1 parent 8668de0 commit 5111935

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaCollectionRestriction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function create(Constraint $constraint, ApiProperty $propertyMetadata): a
4040
{
4141
$restriction = [
4242
'type' => 'object',
43-
'properties' => [],
43+
'properties' => new \ArrayObject(),
4444
'additionalProperties' => $constraint->allowExtraFields,
4545
];
4646
$required = [];

tests/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaCollectionRestrictionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function testCreate(Constraint $constraint, ApiProperty $propertyMetadata
7979

8080
public static function createProvider(): \Generator
8181
{
82-
yield 'empty' => [new Collection([]), new ApiProperty(), ['type' => 'object', 'properties' => [], 'additionalProperties' => false]];
82+
yield 'empty' => [new Collection([]), new ApiProperty(), ['type' => 'object', 'properties' => new \ArrayObject(), 'additionalProperties' => false]];
8383

8484
$fields = [
8585
'name' => new Required([
@@ -104,13 +104,13 @@ public static function createProvider(): \Generator
104104
],
105105
]),
106106
];
107-
$properties = [
107+
$properties = new \ArrayObject([
108108
'name' => new \ArrayObject(),
109109
'email' => ['minLength' => 2, 'maxLength' => 255, 'format' => 'email'],
110110
'phone' => ['pattern' => '^([+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*)$'],
111111
'age' => ['exclusiveMinimum' => 0],
112-
'social' => ['type' => 'object', 'properties' => ['githubUsername' => new \ArrayObject()], 'additionalProperties' => false, 'required' => ['githubUsername']],
113-
];
112+
'social' => ['type' => 'object', 'properties' => new \ArrayObject(['githubUsername' => new \ArrayObject()]), 'additionalProperties' => false, 'required' => ['githubUsername']],
113+
]);
114114
$required = ['name', 'email', 'social'];
115115

116116
yield 'with fields' => [

tests/Symfony/Validator/Metadata/Property/ValidatorPropertyMetadataFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ public function testCreateWithPropertyCollectionRestriction(): void
630630

631631
$this->assertEquals([
632632
'type' => 'object',
633-
'properties' => [
633+
'properties' => new \ArrayObject([
634634
'name' => new \ArrayObject(),
635635
'email' => ['format' => 'email', 'minLength' => 2, 'maxLength' => 255],
636636
'phone' => ['pattern' => '^([+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*)$'],
@@ -639,13 +639,13 @@ public function testCreateWithPropertyCollectionRestriction(): void
639639
],
640640
'social' => [
641641
'type' => 'object',
642-
'properties' => [
642+
'properties' => new \ArrayObject([
643643
'githubUsername' => new \ArrayObject(),
644-
],
644+
]),
645645
'additionalProperties' => false,
646646
'required' => ['githubUsername'],
647647
],
648-
],
648+
]),
649649
'additionalProperties' => true,
650650
'required' => ['name', 'email', 'social'],
651651
], $schema);

0 commit comments

Comments
 (0)