-
Notifications
You must be signed in to change notification settings - Fork 938
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
Support ::class notation #360
Comments
What is not possible with the |
As I told you previously, i'm using a custom annotation on top of the library which requires a FQCN: use App\Foo;
/**
* @Model(Foo::bar)
*/ But this example doesn't work |
This looks more like a doctrine issue than a swagger-php issue. Swagger-php is designed to parse (but not execute) any php codebase and extract swagger documentation. Therefore we can't generate warnings on undeclared annotations, if doctrine has a strict mode let me know, that could be useful as an optional cli parameter |
I think the issue here isn't the annotation class, but the class constant |
@mpajunen indeed you're right, we can't use constants at all. Having a reader based on reflection would be a good move imo but maybe too big at once. The part of your PR I'd like to see is:
It sounds weird to me to consider annotations in invalid files. Imo we should either throw a warning or silently ignore them. |
Reflection must execute a script before it can reflect. How would swagger-php know that "my-reset-database-script.php" and "deploy-to-production-script.php" are "invalid" files? Normal php constants work when they are defined before scanning, thats why the cli has a |
Class constants work only when they are fully qualified which is obviously not convenient.
The subject here is about invalid annotations, not especially about reflection. |
I've researched the issue and you're right, the Swagger\StaticAnalyser only reads the I've added a new Sadly reading all use statements can result in It isn't possible to whitelist annotations in the DocParser, but it is possible to blacklist annotations. |
I'm thinking of a way to use More globally, after thinking again about it, I think having a reflection based reader could be a good move.
In fact I just realized #214 do not use reflection unless a file name is found, and reflection only works if the class is in the autoloader (and there is no reason to put Imo the only thing missing to #214 is a way to silently ignore invalid classes (missing parent, missing annotations, etc) |
Well this issue is fixed for me (I have my workaround thanks to fca06ec). |
Thanks for the reminder, i've just released 2.0.9. |
Thanks ! |
It is currently not possible to use the
::class
syntax as the Parser limits the allowed class of theDocBlockParser
.Wdyt about trying to parse the doc blocks with all namespaces supported and fallback to a limited subset of namespaces when the parsing fails?
Imo we should not support having undeclared annotations in files (eventually silently fail? or trigger a notice?), and it should be deprecated.
I can submit a PR if you agree with this.
The text was updated successfully, but these errors were encountered: