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

Annotation inheritance from interfaces broken #2644

Closed
eradford opened this issue Jan 31, 2018 · 2 comments
Closed

Annotation inheritance from interfaces broken #2644

eradford opened this issue Jan 31, 2018 · 2 comments

Comments

@eradford
Copy link
Contributor

eradford commented Jan 31, 2018

Q A
Bug or feature request? Bug
Which Swagger-Core version? 2.0
Which Java version? 8
Which JAX-RS framework & version? Apache CXF 3.1.6

The class scanning logic in swagger-jaxrs2 does not properly process annotations which should be inherited from an interface.

The conditional here is the root cause of the issue:

Since annotations is ultimately defined a few lines above as:

A[] annotations = cls.getAnnotationsByType(annotationClass);

and Class#getAnnotationsByType(Class) defines it's return value to be:

Returns: all this element's annotations for the specified annotation type if associated with this element, else an array of length zero

the above condition will never be true, and implemented interfaces will never be scanned for annotations, even if no classes in the hierarchy contain any Swagger or jax-rs annotations.

The basic flow of the problem method is:

annotations = get annotations for the provided class
if annotations is null or empty
    annotations = get annotations for the provided class's super class
if annotations is still **strictly** null
    annotations = get annotations from the interfaces that the provided class implements
if annotations is still **strictly** null
    return null
return annotations

It appears as though it was a mere oversight that the second and third conditional do not check for an empty array in addition to null.

To sum things up:

Given this interface:

@Path("resources")
@Tag(name = "resource")
public interface AnnotatedInterface {
    @GET
    Response getResource();
}
public class ConcreteImplementation implements AnnotatedInterface {
    public Response getResource() {
        // Get the resource
    }
}

Observed behavior: GET /resources appears only under the default tag, and nowhere else
Expected behavior: GET /resources appears under the 'resource' tag

@eradford
Copy link
Contributor Author

I've already crafted a test that stresses the bad logic and implemented the code fix. I will be submitting a pull request for this shortly.

Just wanted to create this issue to document the problem and track work on it.

frantuma added a commit that referenced this issue Feb 1, 2018
frantuma added a commit that referenced this issue Feb 1, 2018
…ion_inheritance

refs #2644 -  2.0 issue/interface annotation inheritance
@frantuma
Copy link
Member

frantuma commented Feb 1, 2018

Thanks for reporting and for the fix! Included in merged #2650, closing ticket, please reopen if you're still experiencing issues

@frantuma frantuma closed this as completed Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants