Support annotations for virtual properties

This commit is contained in:
Guilhem Niot 2020-07-18 10:10:37 +02:00
parent fa3158ce67
commit 545432f7ec

View File

@ -90,11 +90,19 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
$name = true === $isJmsV1 ? $this->namingStrategy->translateName($item) : $item->serializedName; $name = true === $isJmsV1 ? $this->namingStrategy->translateName($item) : $item->serializedName;
// read property options from Swagger Property annotation if it exists // read property options from Swagger Property annotation if it exists
try {
$reflections = [];
if (true === $isJmsV1 && property_exists($item, 'reflection') && null !== $item->reflection) { if (true === $isJmsV1 && property_exists($item, 'reflection') && null !== $item->reflection) {
$reflection = $item->reflection; $reflections[] = $item->reflection;
} else { } elseif (\property_exists($item->class, $item->name)) {
$reflection = new \ReflectionProperty($item->class, $item->name); $reflections[] = new \ReflectionProperty($item->class, $item->name);
}
if (null !== $item->getter) {
$reflections[] = new \ReflectionMethod($item->class, $item->getter);
}
if (null !== $item->setter) {
$reflections[] = new \ReflectionMethod($item->class, $item->setter);
} }
$groups = $this->computeGroups($context, $item->type); $groups = $this->computeGroups($context, $item->type);
@ -110,10 +118,14 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
continue; continue;
} }
$property = Util::getProperty($schema, $annotationsReader->getPropertyName($reflection, $name)); foreach ($reflections as $reflection) {
$annotationsReader->updateProperty($reflection, $property, $groups); $name = $annotationsReader->getPropertyName($reflection, $name);
} catch (\ReflectionException $e) { }
$property = Util::getProperty($schema, $name); $property = Util::getProperty($schema, $name);
foreach ($reflections as $reflection) {
$annotationsReader->updateProperty($reflection, $property, $groups);
} }
if (OA\UNDEFINED !== $property->type || OA\UNDEFINED !== $property->ref) { if (OA\UNDEFINED !== $property->type || OA\UNDEFINED !== $property->ref) {