diff --git a/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php b/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php index 3b93f8e..722844e 100644 --- a/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php +++ b/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php @@ -97,7 +97,7 @@ class SymfonyConstraintAnnotationReader $existingRequiredFields[] = $reflectionProperty->getName(); - $this->schema->setRequired(array_unique($existingRequiredFields)); + $this->schema->setRequired(array_values(array_unique($existingRequiredFields))); } /** diff --git a/Tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php b/Tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php new file mode 100644 index 0000000..dadbd6f --- /dev/null +++ b/Tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php @@ -0,0 +1,48 @@ +getProperties(); + $property = new Schema(); + $schema = new Schema(); + + $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(new AnnotationReader()); + $symfonyConstraintAnnotationReader->setSchema($schema); + foreach ($reflectionProperties as $reflectionProperty) { + $symfonyConstraintAnnotationReader->updateProperty($reflectionProperty, $property); + } + + // expect required to be numeric array with sequential keys (not [0 => ..., 2 => ...]) + $this->assertEquals($schema->getRequired(), ['property1', 'property2']); + } +}