【问题标题】:How to tell Swagger to replace collection type entirely with string?如何告诉 Swagger 用字符串完全替换集合类型?
【发布时间】:2021-03-24 13:24:51
【问题描述】:

我对 Swagger 自动生成的模型架构有疑问。我有一个 List<String> 类型的集合字段,我想将其序列化为纯字符串,并且为此我有单独的序列化程序。杰克逊的工作做得很好,但模式生成器做得不好。尽管明确设置了属性dataType,但它将字段的类型解析为对象:

public class FilialDetails {
  @ApiModelProperty(dataType = "string", example = "10000101010")
  @JsonInclude(JsonInclude.Include.NON_NULL)
  // custom serializer treats collection as subset of known, pre-populated list
  // and serializes it as series of 0 and 1
  @JsonSerialize(using = ServicesSerializer.class)
  private List<String> services;
}

生成的属性定义(摘录):

  "properties": {
    "services": {
      "type": "object",
      "example": 10000101010
    }
  }

我在架构定义中需要string,而不是object,这怎么可能?我在我的项目中使用io.springfox:springfox-boot-starter:3.0.0

【问题讨论】:

    标签: java swagger springfox


    【解决方案1】:

    我必须为 string 指定完全限定的类型名称

      @ApiModelProperty(dataType = "java.lang.String", example = "10000101010")
      private List<String> services;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-23
      • 1970-01-01
      • 1970-01-01
      • 2017-12-28
      • 2021-10-27
      • 1970-01-01
      相关资源
      最近更新 更多