Search code examples
javaswaggerswagger-2.0spring-rest

Having parametrized class in swagger annotations


From my spring rest service, I am returning response as -

return new ResponseEntity<ExampleOutputData>(exampleService.exampleServiceCall(inputData), responseHeaders, HttpStatus.ACCEPTED);

And I am mentioning response in annotaion as -

 @ApiResponses(value = { 
            @ApiResponse(code = 202, message = "Success", response = ResponseEntity.class)}) 

And I am getting yaml doc response as -

  responses:
    202:
      description: "Success"
      schema:
        $ref: "#/definitions/ResponseEntity"

My question is how do I mention ExampleOutputData in the response as actually my response is ResponseEntity<ExampleOutputData>

Or is it not required and the current implementation and swagger definition is perfect?


Solution

  • In order to have ExampleOutputData in the response you should simply change ResponseEntity.class to ExampleOutputData.class:

    @ApiResponses(value = {@ApiResponse(code = 202, message = "Success", response = ExampleOutputData.class)})
    

    See documentation here.