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

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

我的 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 之外的任何值

引用这里: https://github.com/springfox/springfox/issues/1473

Ans Screenshot here

关于java - 如何在 swagger-ui 中隐藏显示为 @RequestBody 示例值的 json 值的数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57168728/

相关文章:

java - 如何在 Java 中表示字符串 A > 字符串 B

java - Camel junit 使用bean组件测试http组件

java - 如何加入多个验证注解

spring-boot - 我得到 404 的 https ://localhost:8080/swagger-ui. html

java - 使用 Java 解密使用 Objective-C 加密的 AES 数据

java - 如果在此期间满足特定条件,如何每半小时发送一次电子邮件?

go - 生产中 Swagger UI 的最佳实践

reactjs - 使用 Angular 10 添加 swagger-UI

java - 单击表格行中的textView时出错

java - 如何在 Spring Boot 中启用 HTTP 响应缓存