【问题标题】:How to hide datatypes displaying as json values of @RequestBody example value in swagger-ui?如何在 swagger-ui 中隐藏显示为 @RequestBody 示例值的 json 值的数据类型?
【发布时间】:2019-07-23 16:39:49
【问题描述】:

我的 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;
}

请求获取活动:

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;
  • 如果您解决了自己的问题,请answer your own question

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


【解决方案1】:

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

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

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

Ans Screenshot here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    • 2020-09-21
    • 2016-12-11
    • 1970-01-01
    相关资源
    最近更新 更多