我将 Swagger2 与 Springfox 和 Spring Boot 一起使用。我有一个这样定义的端点:
@ApiOperation(value = "save", nickname = "Save Store")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Created"),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 403, message = "Forbidden"),
@ApiResponse(code = 500, message = "Failure", response = ErrorResource.class)})
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void save(@Valid @RequestBody Store store, BindingResult bindingResult, HttpServletRequest request, HttpServletResponse response) {
if (bindingResult.hasErrors()) {
throw new InvalidRequestException("Invalid Store", bindingResult);
}
this.storeService.save(store);
response.setHeader("Location", request.getRequestURL().append("/").append(store.getId()).toString());
}
生成的 API 文档在模型模式中显示id
。Store
从技术上讲,创建Store
JSON 时不应包含id
. 我试图弄清楚如何告诉 Swagger/Springfox 忽略id
但仅针对此端点。