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

@ApiResponse cannot infer parametrised type with Java Generics

Open kliarist opened this issue 2 years ago • 4 comments

I have the following code snippet

public class ApiStandardResponse<T> {
    T data;
}

and use that to annotate my endpoint

@Operation(
   ...
      responses = {
          @ApiResponse(
              responseCode = "200",
              description = "Success",
              content = {@Content(
                  mediaType = "application/json",
                  schema = @Schema(implementation = ApiStandardResponse.class)
              )}
          )
      }
   ...
  )

It turns out that there is no way to specify the parametrised type and thus swagger ui cannot infer it making it impossible for contract clients to generate the appropriate stubs

image

Is there an elegant way to specify the parametrised type somehow without using workarounds such as subclasses?

kliarist avatar Jan 26 '23 12:01 kliarist