如何隐藏在 swagger-ui 中显示为示例值@RequestBody json 值的数据类型?



我的 Spring Boot 应用程序有一个模型类ReqGetActive用作@PostMapping请求正文中的请求模型。

控制器:

@PostMapping(value = "/api/getActive",
consumes = "application/JSON",
produces = "application/JSON")
public ResponseEntity<String> getActive(
@ApiParam(value = "Consumer's request body", required = true)
@RequestBody ReqGetActive jsonPojo) throws Exception {
return null;
}

ReqGetActive:

import lombok.*;
import com.fasterxml.jackson.annotation.*;
public class ReqGetActive {
@JsonProperty("RequestData")
@JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
private RequestData RequestData;
@Getter @Setter @ToString
@JsonIgnoreProperties(ignoreUnknown = true)
private static class RequestData{
@JsonProperty("ReportTitle")
@JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
private String ReportTitle;
}
}

它以 swagger-ui 显示请求模型,如下所示: 招摇-UI-截图.png

现在我的疑问是,正如您在上图中看到的,类 ReqGetActive 字段的数据类型显示为 json 字段的值。

是否可以在 json 模型中仅显示""的键和值?

PS:我只使用大摇大摆的注释来显示 swagger-ui

我已经设法使用@ApiModelProperty设置所需的值,以将其更改为我想要的值。 @ApiModelProperty(示例 = "[示例标题]") 私有字符串报告标题;

即,我可以设置除" "或 null 以外的任何值

参考这里: https://github.com/springfox/springfox/issues/1473

截图在这里

最新更新