在 spring boot swagger 中手动指定 POST 请求主体
Manually specify POST request body in spring boot swagger
下面这段代码是我写的:
@PostMapping(path = "/process", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get process with given ID", produces = MediaType.APPLICATION_JSON_VALUE,
response = ProcessType.class)
public ResponseEntity<ProcessType> createProcessType(
@RequestBody
@DTO(ProcessTypeDto.class) ProcessType processType
) {
log.info("POST called on /process");
ProcessType processTypeResult;
...
...
}
效果很好。但我的问题是招摇。我制作了一个自定义注释 @DTO
,它会自动将一个 class 映射到另一个。但是,swagger 看到了我的 ProcessType
请求正文,并在 class 的 UI 中显示了示例,而不是 ProcessTypeDto
。如果我删除 swagger 显示的内容并且 POST ProcessTypeDto
代码有效,我只想 swagger 显示 ProcessTypeDto
作为该端点的默认示例,因为它会破坏代码生成。
有没有办法手动指定我想要从 swaggers POV 覆盖我的 @Requestbody
的请求主体?
看来你运气不太好,2.0版本会发布
这是您要查找的内容https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations#requestbody
或者至少您可以开始使用候选版本
https://mvnrepository.com/artifact/io.swagger/swagger-core
下面这段代码是我写的:
@PostMapping(path = "/process", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get process with given ID", produces = MediaType.APPLICATION_JSON_VALUE,
response = ProcessType.class)
public ResponseEntity<ProcessType> createProcessType(
@RequestBody
@DTO(ProcessTypeDto.class) ProcessType processType
) {
log.info("POST called on /process");
ProcessType processTypeResult;
...
...
}
效果很好。但我的问题是招摇。我制作了一个自定义注释 @DTO
,它会自动将一个 class 映射到另一个。但是,swagger 看到了我的 ProcessType
请求正文,并在 class 的 UI 中显示了示例,而不是 ProcessTypeDto
。如果我删除 swagger 显示的内容并且 POST ProcessTypeDto
代码有效,我只想 swagger 显示 ProcessTypeDto
作为该端点的默认示例,因为它会破坏代码生成。
有没有办法手动指定我想要从 swaggers POV 覆盖我的 @Requestbody
的请求主体?
看来你运气不太好,2.0版本会发布
这是您要查找的内容https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations#requestbody
或者至少您可以开始使用候选版本 https://mvnrepository.com/artifact/io.swagger/swagger-core