简体   繁体   English

如何告诉 Swagger 用字符串完全替换集合类型?

[英]How to tell Swagger to replace collection type entirely with string?

I have problems with automatically generated model schema by Swagger.我遇到了由 Swagger 自动生成的 model 架构的问题。 I have a collection field of type List<String> which I want to serialize as plain string and I have separate serializer for that.我有一个List<String>类型的集合字段,我想将其序列化为纯字符串,并且为此我有单独的序列化程序。 Jackson is doing its job well, but not schema generator. Jackson 做得很好,但不是模式生成器。 It resolves type of the field as object despite of explictly set attribute dataType :尽管明确设置了属性dataType ,但它将字段类型解析为 object :

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

Generated properties definition (excerpt):生成的属性定义(摘录):

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

I need string in schema definition, not object , how it's possible?我需要模式定义中的string ,而不是object ,这怎么可能? I'm using io.springfox:springfox-boot-starter:3.0.0 in my project.我在我的项目中使用io.springfox:springfox-boot-starter:3.0.0

I had to specify fully qualified type name for string我必须为string指定完全限定的类型名称

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM