我的 Spring Boot 应用程序有一个模型类 ReqGetActive
用作 @PostMapping
请求正文中的请求模型。
Controller :
@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;
}
请求获取 Activity :
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 中显示请求模型,如下所示: swagger-ui-screenshot.png
现在我的疑问是,如上图所示类 ReqGetActive 字段的数据类型显示为 json 字段的值。
是否可以在 json 模型中仅将键和值显示为 ""
?
P.s:我只使用 swagger 注释在 swagger-ui 中显示
最佳答案
我已设法使用 @ApiModelProperty 设置所需的值,将其更改为我想要的值。 @ApiModelProperty(example = "[ExampleTitle]") private String ReportTitle;
即,我可以设置除“”或 null 之外的任何值
关于java - 如何在 swagger-ui 中隐藏显示为 @RequestBody 示例值的 json 值的数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57168728/