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;
// read property options from Swagger Property annotation if it exists
try {
$reflections = [];
if (true === $isJmsV1 && property_exists($item, 'reflection') && null !== $item->reflection) {
$reflection = $item->reflection;
} else {
$reflection = new \ReflectionProperty($item->class, $item->name);
$reflections[] = $item->reflection;
} elseif (\property_exists($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);
@ -110,10 +118,14 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
continue;
}
$property = Util::getProperty($schema, $annotationsReader->getPropertyName($reflection, $name));
$annotationsReader->updateProperty($reflection, $property, $groups);
} catch (\ReflectionException $e) {
foreach ($reflections as $reflection) {
$name = $annotationsReader->getPropertyName($reflection, $name);
}
$property = Util::getProperty($schema, $name);
foreach ($reflections as $reflection) {
$annotationsReader->updateProperty($reflection, $property, $groups);
}
if (OA\UNDEFINED !== $property->type || OA\UNDEFINED !== $property->ref) {