smallrye-open-api
smallrye-open-api copied to clipboard
Adding a custom AnnotationScanner
Is is possible to add a custom AnnotationScanner in the project we're working with?
I know I could add it as a java service if I packaged it into a jar, but I want it to load from the project that the maven plugin is currently running on.
Hi @Raptoer, what is your requirement? There may be better-supported alternate approaches that rely on standard interfaces intended for application use. The AnnotationScanner
interface is an internal type and shouldn't necessarily be considered for use by applications.
I’m trying to read nonstandard annotations in order to alter the open api output. I’ve tried using filters, but by the time you’re at that stage you’ve lost the association to the original method you’re reading from.
On Sep 13, 2022, at 1:44 AM, Michael Edgar @.***> wrote:
Hi @Raptoer, what is your requirement? There may be better-supported alternate approaches that rely on standard interfaces intended for application use. The AnnotationScanner interface is an internal type and shouldn't necessarily be considered for use by applications.
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.
There are ways in that you can get the original method. We do it in Quarkus. See https://github.com/quarkusio/quarkus/blob/b60ad38c41ed42d34ec1fe86cc5934647c92440f/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/filter/AutoTagFilter.java#L51
as an example
@Raptoer , what type of annotations are you dealing with? Something entirely custom to your application domain?
So I'm trying to read @PreAuthorize, the spring security annotation, to somehow indicate on the openAPI document about the permissions required
This sounds similar to https://github.com/quarkusio/quarkus/blob/main/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/filter/AutoRolesAllowedFilter.java
If you create a small reproducer and the expected entries in the schema document, I can maybe build it in the above filter.
The problem with these filters is that I'm using the maven plugin, and I'd rather not duplicate the expansive SmallRyeOpenApiProcessor that the quarkus extension uses. The way the maven plugin works I don't get a constructor to hand in extra data. I tried just using the class loader in the filter when it get activated, but I don't seem to have access to my application classes at that time.
I tried just using the class loader in the filter when it get activated, but I don't seem to have access to my application classes at that time.
How did you obtain the class loader? I would expect if you use the class load of your filter, the application classes will be available.
@Raptor Can you check if the problem still occurs with the latest release (v3.11.0)?
If so, can you provide a minimal reproducible example as asked above?