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

时间:2019-07-23 16:39:49

标签: java spring-boot swagger-ui swagger-2.0 openapi

我的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中显示请求模型,如下所示: swagger-ui-screenshot.png

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

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

P.s:我只使用swagger批注在swagger-ui中显示

1 个答案:

答案 0 :(得分:0)

我已经使用@ApiModelProperty设置了所需的值,以将其更改为所需的值。 @ApiModelProperty(example =“ [ExampleTitle]”)private String ReportTitle;

即,我可以设置“”或null以外的任何值

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

Ans Screenshot here