我正在使用springfox-swagger2版本2.6.1,并且它会自动为PUT和POST操作插入HTTP 200响应消息,尽管我尝试将其配置为不这样做(我不对POST或PUT使用响应状态200,但是201和204);见下面的截图:
我已经看到了类似问题的答案,作者建议@ResponseStatus在控制器中添加注释以“修复”它,但这种方法变得不灵活,并且与Spring自己的文档(关于ResponseEntityvs @ResponseStatusfor rest API)的使用背道而驰。例子:
和
https://github.com/springfox/springfox/issues/908
还有其他方法可以强制Springfox Swagger不添加此200 OK状态代码吗?
我的资料夹配置:
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.select().
apis(RequestHandlerSelectors.any()).
paths(paths()).
build()
.pathMapping("/")
.apiInfo(apiInfo())
.genericModelSubstitutes(ResponseEntity.class)
.alternateTypeRules(newRule(
typeResolver.resolve(DeferredResult.class, typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
typeResolver.resolve(WildcardType.class)
));
Run Code Online (Sandbox Code Playgroud)
...以及实际的API端点声明:
@RequestMapping(method = RequestMethod.POST, produces = "application/json")
@ApiOperation(value = "Create a new enrolment", code = 201)
@ApiResponses(value = {
@ApiResponse(code = 201, message = "New enrolment created",
responseHeaders = @ResponseHeader(name = "Location", description = "The resulting URI of the newly-created …Run Code Online (Sandbox Code Playgroud)