James
James

Reputation: 11

Swagger with Dropwizard APIs that use Generic types

I have a generic response object in my Dropwizard API with Response which is a wrapper containing a status enum and a value. The API operations have a reponse like Response or Response>.

I have been trying to find a way to handle this and saw some mentions that this is handled for Spring Rest / Swagger?

I am using: com.wordnik swagger-jaxrs_2.10 1.3.5

Has anyone resolved this in a nice generic way?

Upvotes: 1

Views: 908

Answers (2)

Ronny Shapiro
Ronny Shapiro

Reputation: 421

Came around this old question as I was looking for a solution for the same issue. Here is my workaround :

  1. Create a wrapper class :

    @ApiModel
    public class PetListResponse extends Response<List<Pet>> {
    
        @Override
        @ApiModelProperty
        public List<Pet> getValue() {
            return super.getValue()
        }
    }
    
  2. Override the response in the API :

    @GET
    @Path("/pets")
    @ApiOperation(value = "Get all pets.", response = PetListResponse.class)
    public Response<List<Pet>> getPets() {
     ...
    }
    
  3. Success :)

Upvotes: 0

condit
condit

Reputation: 10962

I think you might be looking for something like this:

@GET
@Path("/pets")
@ApiOperation(value = "Get all pets.", response = Pet.class)
public Response<List<Pet>> getPets() {
  ...
}

Upvotes: 1

Related Questions