Вы можете использовать следующее в верхней части вашего метода в v2
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = YourObject.class),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 403, message="Forbidden"),
@ApiResponse(code = 404, message = "Not Found"),
@ApiResponse(code = 500, message = "Failure")
})
Для V3 вы можете попробовать что-то подобное в случае, если ваш метод возвращает некоторый объект
@Operation(summary = "Add a new object", description = "", tags = { "yourObject" })
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Object created",content = @Content(schema = @Schema(implementation = YourObject.class))),
@ApiResponse(responseCode = "400", description = "Invalid input"),
@ApiResponse(responseCode = "409", description = "Object already exists") })
@PostMapping(value = "/your-url", consumes = {"application/json","application/xml" })
public ResponseEntity<YourObject> addObject(
...
return ...
}
Если ваш метод возвращает void, попробуйте этот
@Operation(summary = "Update an existing object", description = "", tags = { "yourObject" })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "successful operation"),
@ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
@ApiResponse(responseCode = "404", description = "Object not found"),
@ApiResponse(responseCode = "405", description = "Validation exception") })
@PutMapping(value = "/your-url/{id}", consumes = { "application/json", "application/xml" })
public ResponseEntity<Void> addObject(
...
return ...
}