swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Interface level @Consumes, @Produces annotations ignored

Open mksplg opened this issue 4 years ago • 1 comments

I'm building an API with JaxRS on Sprig Boot. I'm using http://cxf.apache.org/docs/swaggerfeature-swagger2feature.html to generate a swagger file from the API Interfaces.

When I add a @Consumes or @Produces annotation to the interface it is ignored. When I add them to the methods they are taken into account. This however means I have to duplicate them on all methods.

I've opened an issue with CXF and the developers there advised that the problem may be in swagger-core.

For example, this does not produce the correct swagger.json:

@Path("/v1")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
interface ThingWsV1 {

    @GET
    @Path("/things/{uuid}")
    @ApiResponses(ApiResponse(code = 200, message = "OK", response = ThingDto::class))
    fun getThing(@PathParam("uuid") uuid: UUID): Response

}

mksplg avatar Feb 18 '21 19:02 mksplg

This is probably a regression. We recently upgraded from 1.5.7 to 1.6.4 and the swagger no longer contains: "produces" : [ "application/json" ]

We use the same interface level annotation: @Path("/v1/foo/bar") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)

ccosentino avatar Mar 17 '22 15:03 ccosentino