I have to document 2 rest endpoints which are mapped to the same controller based on some part of path but are actually separate APIs depending on path variable.
REST APIs: HTTP POST to /user/create and /user/update
/user is mapped to UserController and the request handler method has a switch based on path variable action.
The whole thing looks like this (heavily redacted)
@RestController
@Api(value = "User APIs")
@RequestMapping("/user")
public class UserController {
private static final String ACTION = "/{action}";
@ApiOperation(value = "User create/update")
@RequestMapping(value = ACTION,
method = RequestMethod.POST,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE},
headers = "Accept=application/json")
public ResponseEntity<String> userApi(
@PathVariable String action,
HttpServletRequest httpRequest
) {
try {
switch (action.toLowerCase()) {
case "create":
return UserService.create(httpRequest);
case "update":
return UserService.update(httpRequest);
}
} catch (Exception e) {
// log
}
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
I know this is not a good design, but for now I have to live with it and get it documented somehow
Currently swagger documents only one API, HTTP POST to /user/{action}.
I want the output to have both the APIs and {action} replaced with create and update.
So I want to know if it's possible to have swagger generate output for these 2 APIs and if yes, how to do it?