Skip to content
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

oasfilter IndexView contains duplicate annotations #2191

Open
Postremus opened this issue Feb 6, 2025 · 5 comments
Open

oasfilter IndexView contains duplicate annotations #2191

Postremus opened this issue Feb 6, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@Postremus
Copy link
Contributor

Postremus commented Feb 6, 2025

I have an OASFilter which uses the provided IndexView:

    private final IndexView index;

    public WolfOASFilterImpl(IndexView index) {
        this.index = index;
    }

While scanning through the index using e.g. index.getAnnotations(Annotation.class), I get the AnnotationInstance's returned duplicated.

https://smallrye.io/blog/jandex-3-2-0/
Jandex has a stacked index view, which only returns the first result.

@MikeEdgar
Copy link
Member

I see how this could happen and yes, a StackedIndexed would help. I'm curious which annotation is giving you duplicates? My guess would be one of the MP OpenAPI annotations, but I just want to confirm.

@MikeEdgar MikeEdgar added the bug Something isn't working label Feb 8, 2025
@Postremus
Copy link
Contributor Author

Postremus commented Feb 8, 2025

actually, it is an annotation from our custom security framework (dont ask..).

We annotate our resource methods like this:

@Allow({"user_mange", "user_read"})
@GET
public User read(...) {
...
}

In my OASFilter, I match all declarations of @Allow to their coresponding location in the openapi document using the methodref (and generate security requirements, api responses, and operation descriptions)
I retrieve the declarations using index.getAnnotations(Allow.class), which returns duplicates.

If I remember correctly, i worked around this problem by wrapping the annotationinstances in a HashSet.

@MikeEdgar
Copy link
Member

MikeEdgar commented Feb 8, 2025

Oh that's interesting. Do you know what Jandex version the runtime you're using includes? Or are you using either the Maven or Gradle plugin?

The reason is that if the runtime (e.g. Quarkus) is passing a composite index to smallrye-open-api, then using the stacked index here will not help.

@Postremus
Copy link
Contributor Author

Quarkus 3.18.2

If I remember correctly, i worked around this problem by wrapping the annotationinstances in a HashSet.

I just looked at the code again, I use a Map<String, MethodInfo> operationMethods, where the key is the methodref to filter out duplicates.

@MikeEdgar
Copy link
Member

It looks like Quarkus 3.18 may still be using the CompositeIndex itself, which would be passed to the OpenAPI scanner as well. Until that's updated (if it's even planned) there may not be much we can do about it in this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants