cancel
Showing results for 
Search instead for 
Did you mean: 

How to Inject dynamic object in response class of @ApiOperation for Swagger

Highlighted
New Contributor

How to Inject dynamic object in response class of @ApiOperation for Swagger

Am developing a project to handle CRUD operation for 50+ entities using Spring boot REST api with Swagger documentation.

For all the CRUD operation i have a common response which can handle GET,UPDATE,POST and DELETE.

Am using @ApiOperation as shown below for swagger documentation, Below is just an example for Client entity,

 

 

@ApiOperation(value = "Get Client details API", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE, httpMethod = "GET", response = InternalApiResponse.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = HttpStatusMessages.MESSAGE_200), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = HttpStatusMessages.MESSAGE_401), @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = HttpStatusMessages.MESSAGE_403), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = HttpStatusMessages.MESSAGE_404) }) @RequestMapping(value = "/clients", headers = "Accept=application/json", method = RequestMethod.GET) public ResponseEntity<InternalApiResponse> getClients(@ModelAttribute RequestParams requestParams, @ModelAttribute Client client) throws InternalApiException { }

 

InternalApiResponse.class is as shown,

 

InternalApiResponse.class

{

   private Status status;

   private Error error;

   private Object entityObject;

}

 

in the above class, entityObject needs to be dynamically considered based on input entity (ex: @ModelAttribute Client client)

Swagger UI is as shown : 

image.png

 

From Java side i can inject required object in response at run time, But how i can inject the required object to InternalApiResponse for Swagger @ApiOperation, so that can i see the Api response with particular entity details in Swagger UI...Please help

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors