Forum Discussion

julienQc's avatar
julienQc
Occasional Contributor
6 years ago
Solved

@ApiResponse messages inheritance

Hi,   I'm facing a problem that I don't know if it's an issue or a normal behaviour of swagger. And if it's a normal behaviour, maybe it could be improved   I'm defining interfaces and swag...
  • frantuma's avatar
    6 years ago

    this is not supported atm as the container annotation ApiRepsonses is overriden in full, and there are no short term plans to change this behaviour; however you can possibly achieve what you need, more as a side effect, by including your ApiResponse annotations of "base interface" (first and second enpoint) within `@Operation` annotation, and keeping controller as is; as responses within Operation are resolved first, and responses defined on method are then merged with these, this match your desired behaviour.

     

    e.g.

     

    public interface FirstEndpoint<C> {
    
        @POST
        @Path("/")
        @Operation(responses = {
                @ApiResponse(responseCode = "201", description = "Created"),
                @ApiResponse(responseCode = "400", description = "Bad Request"),
                @ApiResponse(responseCode = "403", description = "Forbidden"),
                @ApiResponse(responseCode = "404", description = "Not Found")})
        default String firstEndpoint(C param) {
            return "firstEndpoint-ok";
        }
    }
    public interface SecondEndpoint<C> {
    
        @GET
        @Path("/{id}")
        @Operation(responses = {
                @ApiResponse(responseCode = "200", description = "OK"),
                @ApiResponse(responseCode = "400", description = "Bad Request"),
                @ApiResponse(responseCode = "403", description = "Forbidden"),
                @ApiResponse(responseCode = "404", description = "Not Found")})
        default String secondEnpoint(C param) {
            return "secondEnpoint-ok";
        }