diff --git a/src/ModelDescriber/Annotations/AnnotationsReader.php b/src/ModelDescriber/Annotations/AnnotationsReader.php index afc6a3720..0d6248048 100644 --- a/src/ModelDescriber/Annotations/AnnotationsReader.php +++ b/src/ModelDescriber/Annotations/AnnotationsReader.php @@ -23,7 +23,7 @@ class AnnotationsReader { private PropertyPhpDocReader $phpDocReader; private OpenApiAnnotationsReader $openApiAnnotationsReader; - private SymfonyConstraintAnnotationReader $symfonyConstraintAnnotationReader; + private SymfonyAnnotationReader $symfonyAnnotationReader; private ReflectionReader $reflectionReader; /** @@ -36,14 +36,14 @@ public function __construct( ) { $this->phpDocReader = new PropertyPhpDocReader(); $this->openApiAnnotationsReader = new OpenApiAnnotationsReader($modelRegistry, $mediaTypes); - $this->symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader($useValidationGroups); + $this->symfonyAnnotationReader = new SymfonyAnnotationReader($useValidationGroups); $this->reflectionReader = new ReflectionReader(); } public function updateDefinition(\ReflectionClass $reflectionClass, OA\Schema $schema): bool { $this->openApiAnnotationsReader->updateSchema($reflectionClass, $schema); - $this->symfonyConstraintAnnotationReader->setSchema($schema); + $this->symfonyAnnotationReader->setSchema($schema); $this->reflectionReader->setSchema($schema); return $this->shouldDescribeModelProperties($schema); @@ -60,13 +60,14 @@ public function getPropertyName($reflection, string $default): string /** * @param \ReflectionProperty|\ReflectionMethod $reflection * @param string[]|null $serializationGroups + * @param array $context */ - public function updateProperty($reflection, OA\Property $property, ?array $serializationGroups = null): void + public function updateProperty($reflection, OA\Property $property, array &$context, ?array $serializationGroups = null): void { $this->openApiAnnotationsReader->updateProperty($reflection, $property, $serializationGroups); $this->phpDocReader->updateProperty($reflection, $property); $this->reflectionReader->updateProperty($reflection, $property); - $this->symfonyConstraintAnnotationReader->updateProperty($reflection, $property, $serializationGroups); + $this->symfonyAnnotationReader->updateProperty($reflection, $property, $context, $serializationGroups); } /** diff --git a/src/ModelDescriber/Annotations/ReflectionReader.php b/src/ModelDescriber/Annotations/ReflectionReader.php index 648c85352..817ca7aef 100644 --- a/src/ModelDescriber/Annotations/ReflectionReader.php +++ b/src/ModelDescriber/Annotations/ReflectionReader.php @@ -18,7 +18,7 @@ /** * Read default values of a property from the function or property signature. * - * This needs to be called before the {@see SymfonyConstraintAnnotationReader}, + * This needs to be called before the {@see SymfonyAnnotationReader}, * otherwise required properties might be considered wrongly. * * @internal diff --git a/src/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php b/src/ModelDescriber/Annotations/SymfonyAnnotationReader.php similarity index 89% rename from src/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php rename to src/ModelDescriber/Annotations/SymfonyAnnotationReader.php index 8696a63a4..97f8091d7 100644 --- a/src/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php +++ b/src/ModelDescriber/Annotations/SymfonyAnnotationReader.php @@ -22,7 +22,7 @@ /** * @internal */ -class SymfonyConstraintAnnotationReader +class SymfonyAnnotationReader { use SetsContextTrait; @@ -39,19 +39,27 @@ public function __construct(bool $useValidationGroups = false) } /** - * Update the given property and schema with defined Symfony constraints. + * Update the given property and schema with defined Symfony attributes. * * @param \ReflectionProperty|\ReflectionMethod $reflection + * @param array $context * @param string[]|null $validationGroups */ - public function updateProperty($reflection, OA\Property $property, ?array $validationGroups = null): void + public function updateProperty($reflection, OA\Property $property, array &$context = [], ?array $validationGroups = null): void { - foreach ($this->getAttributes($property->_context, $reflection, $validationGroups) as $outerAttribute) { + // Handle constraints + foreach ($this->getConstraintAttributes($property->_context, $reflection, $validationGroups) as $outerAttribute) { $innerAttributes = $outerAttribute instanceof Assert\Compound || $outerAttribute instanceof Assert\Sequentially ? $outerAttribute->constraints : [$outerAttribute]; - $this->processPropertyAttributes($reflection, $property, $innerAttributes); + $this->processConstraintPropertyAttributes($reflection, $property, $innerAttributes); + } + + // Handle context + $context = $reflection->getAttributes(\Symfony\Component\Serializer\Attribute\Context::class); + if (1 === \count($context)) { + $context['symfony_context'] = $context[0]->getArguments()[0]; } } @@ -59,7 +67,7 @@ public function updateProperty($reflection, OA\Property $property, ?array $valid * @param \ReflectionProperty|\ReflectionMethod $reflection * @param Constraint[] $attributes */ - private function processPropertyAttributes($reflection, OA\Property $property, array $attributes): void + private function processConstraintPropertyAttributes($reflection, OA\Property $property, array $attributes): void { foreach ($attributes as $attribute) { if ($attribute instanceof Assert\NotBlank || $attribute instanceof Assert\NotNull) { @@ -179,7 +187,7 @@ private function applyEnumFromChoiceConstraint(OA\Schema $property, Assert\Choic * * @return iterable */ - private function getAttributes(Context $parentContext, $reflection, ?array $validationGroups): iterable + private function getConstraintAttributes(Context $parentContext, $reflection, ?array $validationGroups): iterable { // To correctly load OA attributes $this->setContextFromReflection($parentContext, $reflection); diff --git a/src/ModelDescriber/JMSModelDescriber.php b/src/ModelDescriber/JMSModelDescriber.php index c98186ee3..bdebc5112 100644 --- a/src/ModelDescriber/JMSModelDescriber.php +++ b/src/ModelDescriber/JMSModelDescriber.php @@ -120,6 +120,7 @@ public function describe(Model $model, OA\Schema $schema): void $context = $this->getSerializationContext($model); $context->pushClassMetadata($metadata); foreach ($metadata->propertyMetadata as $item) { + $propertyContext = $model->getSerializationContext(); // filter groups if (null !== $context->getExclusionStrategy() && $context->getExclusionStrategy()->shouldSkipProperty($item, $context)) { continue; @@ -176,7 +177,7 @@ public function describe(Model $model, OA\Schema $schema): void $property = Util::getProperty($schema, $name); foreach ($reflections as $reflection) { - $annotationsReader->updateProperty($reflection, $property, $groups); + $annotationsReader->updateProperty($reflection, $property, $propertyContext, $groups); } if (Generator::UNDEFINED !== $property->type || Generator::UNDEFINED !== $property->ref) { @@ -197,7 +198,7 @@ public function describe(Model $model, OA\Schema $schema): void continue; } - $this->describeItem($item->type, $property, $context, $model->getSerializationContext()); + $this->describeItem($item->type, $property, $context, $propertyContext); $context->popPropertyMetadata(); } $context->popClassMetadata(); diff --git a/src/ModelDescriber/ObjectModelDescriber.php b/src/ModelDescriber/ObjectModelDescriber.php index 09f69c6cf..55319ce43 100644 --- a/src/ModelDescriber/ObjectModelDescriber.php +++ b/src/ModelDescriber/ObjectModelDescriber.php @@ -113,6 +113,7 @@ public function describe(Model $model, OA\Schema $schema): void $propertyInfoProperties = array_intersect($propertyInfoProperties, $this->propertyInfo->getProperties($class, []) ?? []); foreach ($propertyInfoProperties as $propertyName) { + $propertyContext = []; $serializedName = null !== $this->nameConverter ? $this->nameConverter->normalize($propertyName, $class, null, $model->getSerializationContext()) : $propertyName; $reflections = $this->getReflections($reflClass, $propertyName); @@ -134,7 +135,7 @@ public function describe(Model $model, OA\Schema $schema): void $groups = $model->getGroups()[$propertyName]; } foreach ($reflections as $reflection) { - $annotationsReader->updateProperty($reflection, $property, $groups); + $annotationsReader->updateProperty($reflection, $property, $propertyContext, $groups); } // If type manually defined @@ -152,7 +153,7 @@ public function describe(Model $model, OA\Schema $schema): void throw new \LogicException(\sprintf('The PropertyInfo component was not able to guess the type of %s::$%s. You may need to add a `@var` annotation or use `#[OA\Property(type="")]` to make its type explicit.', $class, $propertyName)); } - $this->describeProperty($types, $model, $property, $propertyName); + $this->describeProperty($types, $model, $property, $propertyName, $propertyContext); } $this->markRequiredProperties($schema); @@ -187,15 +188,17 @@ private function camelize(string $string): string } /** - * @param LegacyType[]|Type $types + * @param LegacyType[]|Type $types + * @param array $context */ - private function describeProperty(array|Type $types, Model $model, OA\Schema $property, string $propertyName): void + private function describeProperty(array|Type $types, Model $model, OA\Schema $property, string $propertyName, array $context): void { if ($this->propertyDescriber instanceof ModelRegistryAwareInterface) { $this->propertyDescriber->setModelRegistry($this->modelRegistry); } - if ($this->propertyDescriber->supports($types, $model->getSerializationContext())) { - $this->propertyDescriber->describe($types, $property, $model->getSerializationContext()); + $context = array_merge($context, $model->getSerializationContext()); + if ($this->propertyDescriber->supports($types, $context)) { + $this->propertyDescriber->describe($types, $property, $context); return; } diff --git a/src/PropertyDescriber/DateTimePropertyDescriber.php b/src/PropertyDescriber/DateTimePropertyDescriber.php index f605a2961..055d96b46 100644 --- a/src/PropertyDescriber/DateTimePropertyDescriber.php +++ b/src/PropertyDescriber/DateTimePropertyDescriber.php @@ -23,6 +23,12 @@ public function describe(array $types, OA\Schema $property, array $context = []) { $property->type = 'string'; $property->format = 'date-time'; + if ( + \array_key_exists('symfony_context', $context) + && 'Y-m-d' === ($context['symfony_context']['datetime_format'] ?? null) + ) { + $property->format = 'date'; + } } public function supports(array $types, array $context = []): bool diff --git a/tests/Functional/Entity/SymfonyContext.php b/tests/Functional/Entity/SymfonyContext.php new file mode 100644 index 000000000..7d99912fa --- /dev/null +++ b/tests/Functional/Entity/SymfonyContext.php @@ -0,0 +1,26 @@ + 'Y-m-d'])] + public $date; + + #[Context(['datetime_format' => 'Y-m-d'])] + public ?\DateTime $nullableDate = null; +} diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php index 7d65956d1..a2fc0c12e 100644 --- a/tests/Functional/FunctionalTest.php +++ b/tests/Functional/FunctionalTest.php @@ -780,6 +780,29 @@ public function testPrivateProtectedExposure(): void $this->assertNotHasProperty('protected', $model); } + public function testContextSupport(): void + { + self::assertEquals( + [ + 'schema' => 'SymfonyContext', + 'type' => 'object', + 'required' => ['date'], + 'properties' => [ + 'date' => [ + 'type' => 'string', + 'format' => 'date', + ], + 'nullableDate' => [ + 'type' => 'string', + 'format' => 'date', + 'nullable' => true, + ], + ], + ], + json_decode($this->getModel('SymfonyContext')->toJson(), true) + ); + } + public function testModelsWithDiscriminatorMapAreLoadedWithOpenApiPolymorphism(): void { $model = $this->getModel('SymfonyDiscriminator'); diff --git a/tests/Functional/TestKernel.php b/tests/Functional/TestKernel.php index 6312626d9..611ce7e0f 100644 --- a/tests/Functional/TestKernel.php +++ b/tests/Functional/TestKernel.php @@ -22,6 +22,7 @@ use Nelmio\ApiDocBundle\Tests\Functional\Entity\NestedGroup\JMSPicture; use Nelmio\ApiDocBundle\Tests\Functional\Entity\PrivateProtectedExposure; use Nelmio\ApiDocBundle\Tests\Functional\Entity\SymfonyConstraintsWithValidationGroups; +use Nelmio\ApiDocBundle\Tests\Functional\Entity\SymfonyContext; use Nelmio\ApiDocBundle\Tests\Functional\ModelDescriber\NameConverter; use Nelmio\ApiDocBundle\Tests\Functional\ModelDescriber\VirtualTypeClassDoesNotExistsHandlerDefinedDescriber; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; @@ -177,6 +178,11 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'type' => BazingaUser::class, 'groups' => ['foo'], ], + [ + 'alias' => 'SymfonyContext', + 'type' => SymfonyContext::class, + 'groups' => null, + ], [ 'alias' => 'SymfonyConstraintsTestGroup', 'type' => SymfonyConstraintsWithValidationGroups::class, diff --git a/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php b/tests/ModelDescriber/Annotations/SymfonyAnnotationReaderTest.php similarity index 77% rename from tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php rename to tests/ModelDescriber/Annotations/SymfonyAnnotationReaderTest.php index d74509685..803c2554a 100644 --- a/tests/ModelDescriber/Annotations/SymfonyConstraintAnnotationReaderTest.php +++ b/tests/ModelDescriber/Annotations/SymfonyAnnotationReaderTest.php @@ -11,7 +11,7 @@ namespace Nelmio\ApiDocBundle\Tests\ModelDescriber\Annotations; -use Nelmio\ApiDocBundle\ModelDescriber\Annotations\SymfonyConstraintAnnotationReader; +use Nelmio\ApiDocBundle\ModelDescriber\Annotations\SymfonyAnnotationReader; use Nelmio\ApiDocBundle\Tests\ModelDescriber\Annotations\Fixture as CustomAssert; use OpenApi\Annotations as OA; use OpenApi\Context; @@ -21,7 +21,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraints as Assert; -class SymfonyConstraintAnnotationReaderTest extends TestCase +class SymfonyAnnotationReaderTest extends TestCase { public function testUpdatePropertyFix1283(): void { @@ -38,11 +38,11 @@ public function testUpdatePropertyFix1283(): void $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property2'])]); - $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(); - $symfonyConstraintAnnotationReader->setSchema($schema); + $symfonyAnnotationReader = new SymfonyAnnotationReader(); + $symfonyAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property2'), $schema->properties[1]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property2'), $schema->properties[1]); // expect required to be numeric array with sequential keys (not [0 => ..., 2 => ...]) self::assertEquals($schema->required, ['property1', 'property2']); @@ -58,11 +58,11 @@ public function testOptionalProperty($entity): void $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property2'])]); - $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(); - $symfonyConstraintAnnotationReader->setSchema($schema); + $symfonyAnnotationReader = new SymfonyAnnotationReader(); + $symfonyAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property2'), $schema->properties[1]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property2'), $schema->properties[1]); // expect required to be numeric array with sequential keys (not [0 => ..., 2 => ...]) self::assertEquals($schema->required, ['property2']); @@ -88,10 +88,10 @@ public function testAssertChoiceResultsInNumericArray($entity): void $schema = $this->createObj(OA\Schema::class, []); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); - $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(); - $symfonyConstraintAnnotationReader->setSchema($schema); + $symfonyAnnotationReader = new SymfonyAnnotationReader(); + $symfonyAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); // expect enum to be numeric array with sequential keys (not [1 => "active", 2 => "active"]) self::assertEquals($schema->properties[0]->enum, ['active', 'blocked']); @@ -120,10 +120,10 @@ public function testMultipleChoiceConstraintsApplyEnumToItems($entity): void $schema = $this->createObj(OA\Schema::class, []); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); - $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(); - $symfonyConstraintAnnotationReader->setSchema($schema); + $symfonyAnnotationReader = new SymfonyAnnotationReader(); + $symfonyAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); self::assertInstanceOf(OA\Items::class, $schema->properties[0]->items); self::assertEquals($schema->properties[0]->items->enum, ['one', 'two']); @@ -146,10 +146,10 @@ public function testLengthConstraintDoesNotSetMaxLengthIfMaxIsNotSet($entity): v $schema = $this->createObj(OA\Schema::class, []); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); - $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(); - $symfonyConstraintAnnotationReader->setSchema($schema); + $symfonyAnnotationReader = new SymfonyAnnotationReader(); + $symfonyAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); self::assertSame(Generator::UNDEFINED, $schema->properties[0]->maxLength); self::assertSame(1, $schema->properties[0]->minLength); @@ -172,10 +172,10 @@ public function testLengthConstraintDoesNotSetMinLengthIfMinIsNotSet($entity): v $schema = $this->createObj(OA\Schema::class, []); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); - $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(); - $symfonyConstraintAnnotationReader->setSchema($schema); + $symfonyAnnotationReader = new SymfonyAnnotationReader(); + $symfonyAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); self::assertSame(Generator::UNDEFINED, $schema->properties[0]->minLength); self::assertSame(100, $schema->properties[0]->maxLength); @@ -200,10 +200,10 @@ public function testCompoundValidationRules(): void $schema = $this->createObj(OA\Schema::class, []); $schema->merge([$this->createObj(OA\Property::class, ['property' => $propertyName])]); - $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(); - $symfonyConstraintAnnotationReader->setSchema($schema); + $symfonyAnnotationReader = new SymfonyAnnotationReader(); + $symfonyAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, $propertyName), $schema->properties[0]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, $propertyName), $schema->properties[0]); self::assertSame([$propertyName], $schema->required); self::assertSame(0, $schema->properties[0]->minimum); @@ -221,10 +221,10 @@ public function testCountConstraintDoesNotSetMinItemsIfMinIsNotSet($entity): voi $schema = $this->createObj(OA\Schema::class, []); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); - $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(); - $symfonyConstraintAnnotationReader->setSchema($schema); + $symfonyAnnotationReader = new SymfonyAnnotationReader(); + $symfonyAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); self::assertSame(Generator::UNDEFINED, $schema->properties[0]->minItems); self::assertSame(10, $schema->properties[0]->maxItems); @@ -247,10 +247,10 @@ public function testCountConstraintDoesNotSetMaxItemsIfMaxIsNotSet($entity): voi $schema = $this->createObj(OA\Schema::class, []); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); - $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(); - $symfonyConstraintAnnotationReader->setSchema($schema); + $symfonyAnnotationReader = new SymfonyAnnotationReader(); + $symfonyAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); self::assertSame(Generator::UNDEFINED, $schema->properties[0]->maxItems); self::assertSame(10, $schema->properties[0]->minItems); @@ -273,10 +273,10 @@ public function testRangeConstraintDoesNotSetMaximumIfMaxIsNotSet($entity): void $schema = $this->createObj(OA\Schema::class, []); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); - $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(); - $symfonyConstraintAnnotationReader->setSchema($schema); + $symfonyAnnotationReader = new SymfonyAnnotationReader(); + $symfonyAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); self::assertSame(Generator::UNDEFINED, $schema->properties[0]->maximum); self::assertSame(10, $schema->properties[0]->minimum); @@ -299,10 +299,10 @@ public function testRangeConstraintDoesNotSetMinimumIfMinIsNotSet($entity): void $schema = $this->createObj(OA\Schema::class, []); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); - $symfonyConstraintAnnotationReader = new SymfonyConstraintAnnotationReader(); - $symfonyConstraintAnnotationReader->setSchema($schema); + $symfonyAnnotationReader = new SymfonyAnnotationReader(); + $symfonyAnnotationReader->setSchema($schema); - $symfonyConstraintAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); + $symfonyAnnotationReader->updateProperty(new \ReflectionProperty($entity, 'property1'), $schema->properties[0]); self::assertSame(Generator::UNDEFINED, $schema->properties[0]->minimum); self::assertSame(10, $schema->properties[0]->maximum); @@ -325,7 +325,7 @@ public function testReaderWithValidationGroupsEnabledChecksForDefaultGroupWhenNo { $schema = $this->createObj(OA\Schema::class, []); $schema->merge([$this->createObj(OA\Property::class, ['property' => 'property1'])]); - $reader = new SymfonyConstraintAnnotationReader(true); + $reader = new SymfonyAnnotationReader(true); $reader->setSchema($schema); // no serialization groups passed here @@ -344,7 +344,7 @@ public function testReaderWithValidationGroupsEnabledDoesNotReadAnnotationsWitho $schema->merge([ $this->createObj(OA\Property::class, ['property' => 'property1']), ]); - $reader = new SymfonyConstraintAnnotationReader(true); + $reader = new SymfonyAnnotationReader(true); $reader->setSchema($schema); // no serialization groups passed here @@ -364,13 +364,15 @@ public function testReaderWithValidationGroupsEnabledReadsOnlyConstraintsWithGro $schema->merge([ $this->createObj(OA\Property::class, ['property' => 'property1']), ]); - $reader = new SymfonyConstraintAnnotationReader(true); + $reader = new SymfonyAnnotationReader(true); $reader->setSchema($schema); + $context = []; // no serialization groups passed here $reader->updateProperty( new \ReflectionProperty($entity, 'property1'), $schema->properties[0], + $context, ['other'] ); @@ -385,13 +387,15 @@ public function testReaderWithValidationGroupsEnabledCanReadFromMultipleValidati $schema->merge([ $this->createObj(OA\Property::class, ['property' => 'property1']), ]); - $reader = new SymfonyConstraintAnnotationReader(true); + $reader = new SymfonyAnnotationReader(true); $reader->setSchema($schema); + $context = []; // no serialization groups passed here $reader->updateProperty( new \ReflectionProperty($entity, 'property1'), $schema->properties[0], + $context, ['other', Constraint::DEFAULT_GROUP] );