diff --git a/src/Analysers/AttributeAnnotationFactory.php b/src/Analysers/AttributeAnnotationFactory.php index bd689a5e7..9202bb6a5 100644 --- a/src/Analysers/AttributeAnnotationFactory.php +++ b/src/Analysers/AttributeAnnotationFactory.php @@ -74,6 +74,18 @@ public function build(\Reflector $reflector, Context $context): array } } } + + if ($reflector instanceof \ReflectionClass) { + foreach ($reflector->getReflectionConstants() as $rc) { + foreach ($rc->getAttributes(Property::class) as $attribute) { + $instance = $attribute->newInstance(); + if (Generator::isDefault($instance->property)) { + $instance->property = $rc->getName(); + } + $annotations[] = $instance; + } + } + } } finally { Generator::$context = null; } diff --git a/src/Attributes/Property.php b/src/Attributes/Property.php index 595b2bcc3..393240b85 100644 --- a/src/Attributes/Property.php +++ b/src/Attributes/Property.php @@ -8,7 +8,7 @@ use OpenApi\Generator; -#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_PARAMETER)] +#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_PARAMETER | \Attribute::TARGET_CLASS_CONSTANT)] class Property extends \OpenApi\Annotations\Property { /**