swagger-core – 在地图上声明的模式会针对键和值重复

huangapple 未分类评论45阅读模式
英文:

swagger-core - Schemas declared on maps are repeated for the key and value

问题

如果我为一个@Schema定义了一个Map,生成的OpenAPI规范会出现重复。

例如:

@Schema(description = "Contents of the bag", 
		example="{\"Apple\":\"Braeburn\",\"Pear\":\"Conference\",\"Melon\":\"Honeydew\"}",
		allowableValues= {
				"Apple", "Pear", "Melon", "Plum"
		})
public final Map<String, Object> properties;

这将生成:

"properties" : {
  "otherProp" : {
    "type" : "string",
    "description" : "..."
  },
  "properties" : {
    "type" : "object",
    "additionalProperties" : {
      "type" : "object",
      "description" : "Contents of the bag",
      "example" : "{\"Apple\":\"Braeburn\",\"Pear\":\"Conference\",\"Melon\":\"Honeydew\"}",
      "enum" : [ "Apple", "Pear", "Melon", "Plum" ]
    },
    "description" : "Contents of the bag",
    "example" : "{\"Apple\":\"Braeburn\",\"Pear\":\"Conference\",\"Melon\":\"Honeydew\"}",
    "enum" : [ "Apple", "Pear", "Melon", "Plum" ]
  }
}

descriptionexampleenum 都是重复的。

有没有办法分别记录键和值?

英文:

If I define a @Schema for a Map, the generated OpenAPI spec has duplications.

For example:

@Schema(description = &quot;Contents of the bag&quot;, 
		example=&quot;{\&quot;Apple\&quot;:\&quot;Braeburn\&quot;,\&quot;Pear\&quot;:\&quot;Conference\&quot;\&quot;Melon\&quot;:\&quot;Honeydew\&quot;}&quot;,
		allowableValues= {
				&quot;Apple&quot;, &quot;Pear&quot;, &quot;Melon&quot;, &quot;Plum&quot;
		})
public final Map&lt;String, Object&gt; properties;

This generates:

    &quot;properties&quot; : {
      &quot;otherProp&quot; : {
        &quot;type&quot; : &quot;string&quot;,
        &quot;description&quot; : &quot;...&quot;,
      },
      &quot;properties&quot; : {
        &quot;type&quot; : &quot;object&quot;,
        &quot;additionalProperties&quot; : {
          &quot;type&quot; : &quot;object&quot;,
          &quot;description&quot; : &quot;Contents of the bag&quot;,
          &quot;example&quot; : &quot;{\&quot;Apple\&quot;:\&quot;Braeburn\&quot;,\&quot;Pear\&quot;:\&quot;Conference\&quot;\&quot;Melon\&quot;:\&quot;Honeydew\&quot;}&quot;,
          &quot;enum&quot; : [ &quot;Apple&quot;, &quot;Pear&quot;, &quot;Melon&quot;, &quot;Plum&quot; ]
        },
        &quot;description&quot; : &quot;Contents of the bag&quot;,
        &quot;example&quot; : &quot;{\&quot;Apple\&quot;:\&quot;Braeburn\&quot;,\&quot;Pear\&quot;:\&quot;Conference\&quot;\&quot;Melon\&quot;:\&quot;Honeydew\&quot;}&quot;,
        &quot;enum&quot; : [ &quot;Apple&quot;, &quot;Pear&quot;, &quot;Melon&quot;, &quot;Plum&quot; ]
      }
    }

description, example and enum are duplicated.

Is there any way to document the key and value separately?

huangapple
  • 本文由 发表于 2020年4月7日 19:24:05
  • 转载请务必保留本文链接:https://java.coder-hub.com/61078899.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定