-
Notifications
You must be signed in to change notification settings - Fork 941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[attributes] add support for class constants #1147
Conversation
ec991ff
to
b3da10a
Compare
b3da10a
to
8b2bf92
Compare
107d9b4
to
230399d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an awesone PR! Thanks for taking the time to be so thorough.
If I could perhaps ask for a couple more (small) things:
- Add a little test
- I wonder if your great PR description could be used to add to the docs somewhere?
For now the cookbook might be best I think. (If not that is also fine, I can do that later)
Other than that this looks good to go once the question about type = 'const'
is sorted.
230399d
to
87549c5
Compare
@DerManoMann whilst trying to add a test I found out that class constant annotations are surprisingly not supported by |
87549c5
to
fcc66b2
Compare
Hmm, not sure that is relevant here as we pull docblocks ourself and stuff them into doctrine. I had a quick play around and ended up with this near the bottom of foreach ($rc->getReflectionConstants() as $constant) {
foreach ($this->annotationFactories as $annotationFactory) {
$definition['constants'][$constant->getName()] = $ctx = new Context([
'constant' => $constant->getName(),
'comment' => $constant->getDocComment() ?: Generator::UNDEFINED,
'annotations' => [],
], $context);
foreach ($annotationFactory->build($constant, $ctx) as $annotation) {
if ($annotation instanceof Property) {
if (Generator::isDefault($annotation->property)) {
$annotation->property = $constant->getName();
}
if (Generator::isDefault($annotation->const)) {
$annotation->const = $constant->getValue();
}
$analysis->addAnnotation($annotation, $ctx);
}
}
}
} |
For testing you could add a const to the three basic.php under |
@cdaguerre Are you still going to work on this? Happy to clean up if it feels like it is too much. |
@DerManoMann it'd be great if you could take over ;) |
No problem. It would be a shame to throw away your work. |
Replaced by #1193 |
This PR :
related to Is annotation of class constants supported in v4? #1082)
const
keyword to attributesconst
to single-valued enums in OAS versionw < 3.1 through a dedicated processor1. Attributes on class constants
2. Support the
const
keyword in attributesThis ^^code is equivalent to the example above in terms of generated documentation.
3. Backport
const
type properties for versions < 3.1The
const
keyword was introduced in OAS 3.1, eg.In OAS < 3.1, the recommended way of doing this was to declare a single-valued enum instead, eg.
I added a processor that will transform
const
toenum
when the given OpenApi version is < 3.1.