smallrye-open-api icon indicating copy to clipboard operation
smallrye-open-api copied to clipboard

Adding a custom AnnotationScanner

Open Raptoer opened this issue 2 years ago • 9 comments

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.

Raptoer avatar Sep 13 '22 00:09 Raptoer

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.

MikeEdgar avatar Sep 13 '22 08:09 MikeEdgar

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.

Raptoer avatar Sep 13 '22 09:09 Raptoer

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

phillip-kruger avatar Sep 13 '22 10:09 phillip-kruger

@Raptoer , what type of annotations are you dealing with? Something entirely custom to your application domain?

MikeEdgar avatar Sep 13 '22 20:09 MikeEdgar

So I'm trying to read @PreAuthorize, the spring security annotation, to somehow indicate on the openAPI document about the permissions required

Raptoer avatar Sep 13 '22 23:09 Raptoer

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.

phillip-kruger avatar Sep 13 '22 23:09 phillip-kruger

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.

Raptoer avatar Sep 14 '22 00:09 Raptoer

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.

MikeEdgar avatar Sep 14 '22 15:09 MikeEdgar

@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?

codespearhead avatar Jun 08 '24 19:06 codespearhead