您可以在 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 ...
}