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

ApiResponse from custom meta annotations are ignored in certain case #3926

Closed
SHSolution opened this issue Apr 15, 2021 · 1 comment
Closed

Comments

@SHSolution
Copy link

SHSolution commented Apr 15, 2021

if (annotations == null || annotations.length == 0) {

Why is this only executed when the Array in the line above is null or empty? In this case ApiResponse Annotations made in a custom annotation to centralize error responses or other common responses like for example:

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@ApiResponses(value = {
        @ApiResponse(
                responseCode = "500",
                description = "Returns Object of Type: MyException in case of an error." +
                " Please check the MyException for further details.",
                content = @Content(schema = @Schema(implementation = MyException.class))
        )
})
public @interface CommonResponses {}

Which later is used like this for example:

    @CommonResponses
    @Operation(
            summary = "Inserts a new thing",
            description = "Use this method to insert a new thing",
            operationId = "insertThing",
            tags = {"thing"}
    )
    @ApiResponse(responseCode = "201",
            description = "Returns the the created thing.",
            content = @Content(schema = @Schema(implementation = Result.class)),
            headers = {@Header(name = HttpHeaders.LOCATION, description = "The location of the newly created thing.")}
    )
    @ApiResponse(responseCode = "400",
            description = "Returns 400 if required parameters are missing.",
            content = @Content(schema = @Schema(implementation = Result.class))
    )
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public Response insertThing(
            @Context UriInfo uriInfo,
            @Context SecurityContext securityContext,
             Thing thing) {

        .....
        return Response.created(new URI(locationHeader)).entity(result).build();

    }

When using my CommonResponses like this, the 500 Response (would like to place some more there...) from that is ignored.
If I don't use ApiResponse annotations on the method itself, only then my meta annotation is picked up.

Is it possible to always include meta annotations or what's the point against doing this?

Thanks for reply / fixing this

/Soeren

@SHSolution SHSolution changed the title ApiResponse from from custom meta annotations are ignored in certain case ApiResponse from custom meta annotations are ignored in certain case Apr 15, 2021
@frantuma
Copy link
Member

fixed in #3931

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