Reputation: 1817
I have created controller which returns json by string, so as I'm using @RestController annotation it transforms it to correct json and it works totally fine.
@Api(tags = "Controller")
@RestController
@RequestMapping(value = "/controller", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
public class MyController {
private final MyService myService;
@Autowired
public MyController (MyService MyService ) {
this.MyService = MyService ;
}
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Bad request", response = ErrorDto.class),
@ApiResponse(code = 404, message = "Location id not found", response = ErrorDto.class),
@ApiResponse(code = 500, message = "Internal error")
})
@ApiOperation(value = "....", tags = {"Alarms"})
@PostMapping(value = "")
public String getValuesByJsonString(@RequestBody Request request) {
eturn MyService.getMyData(request);
}
}
By problem that in swagger I see response as "string" and I would like to see json structure which is returned by jackson after conversion.
Is it possible to specify this structure directly???
Upvotes: 1
Views: 2344
Reputation: 3260
You can declare a Response
class as per your response structure e.g.
public class Response {
private int status;
private String data;
// setter getter
}
Now refer this Response
class in @ApiOperation
as
@ApiOperation(value = "....", tags = {"Alarms"}, response = Response.class)
Now response schema corresponding to Response
class will be generated instead of string.
Upvotes: 1