swagger @ApiModelProperty List< String>的示例值属性 [英] swagger @ApiModelProperty example value for List<String> property
问题描述
我有一个类,其中有一个属性是 List< String>
I have one class in which there is one property which is List<String>
public class MyClass {
....
@ApiModelProperty(position = 2)
private List<String> productIdentifiers;
....
}
此代码生成以下示例值:
This code generates the example values as following:
{
"customerId": "1001",
"productIdentifiers": [
"string"
],
"statuses": [
"NEW"
]
}
此处显示的示例值无效。我的预期示例值应该是:
The example values here shown are not valid. My expected example values should be like :
{
"customerId": "1001",
"productIdentifiers": [
"PRD1",
"PRD2",
"PRD3"
],
"statuses": [
"NEW"
]
}
我试过传递示例属性如下,但它不是生成适当的值:
I have tried passing example attribute as following but it is not generating proper value:
@ApiModelProperty(position = 2, example = "PRD1, PRD2, PRD3")
// This generates -> "productIdentifiers": "PRD1, PRD2, PRD3" // Its not json array
@ApiModelProperty(position = 2, example = "[\"PRD1\", \"PRD2\", \"PRD3\"]")
// This generates -> "productIdentifiers": "[\"PRD1\", \"PRD2\", \"PRD3\"]" // Its too not json array
有什么方法可以为List属性生成正确的示例值吗?
Is there any way I can generate proper example value for List property ?
更新:
我尝试过@nullpointer和@Zeeshan Arif建议的解决方案
I have tried the solutions suggested by @nullpointer and @Zeeshan Arif
@ApiModelProperty(position = 2, dataType="List", example = "PRD1, PRD2, PRD3")
private List<String> productIdentifiers;
//This generates -> `"productIdentifiers": "PRD1, PRD2, PRD3"`
更新2:
尝试以下方法没有生成正确的回复
Tried following approach which did not generate proper response
@ApiModelProperty(position = 2, dataType="java.util.List<String>", example = "PRD1, PRD2, PRD3")
// This generates -> "productIdentifiers": "PRD1, PRD2, PRD3"
@ApiModelProperty(position = 2, dataType="String[]", example = "PRD1, PRD2, PRD3")
// This generates -> "productIdentifiers": "PRD1, PRD2, PRD3"
我对swagger jar的maven依赖是:
my maven dependency for swagger jar is :
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.5.0</version>
<exclusions>
<exclusion>
<artifactId>mapstruct</artifactId>
<groupId>org.mapstruct</groupId>
</exclusion>
</exclusions>
</dependency>
更新
此问题的github票据
推荐答案
TLDR:Swagger-API的贡献者之一已经开发了这个功能,可以在3.0.0版本中添加它,但是它还不确定何时发布。目前它位于Swagger-API GitHub上的功能/ 3.0.0-rc2分支
我已经与Swagger合作了将近两个月现在,随着我们的项目进展,这样的问题出现了。现在我做了一些研究并阅读了Swagger-API的GitHub页面,这个功能根本不起作用。(
I've been working with Swagger for almost two months now and as our project progressed issues like this showed up. Now I did some research and read on the GitHub pages for the Swagger-API that this feature simply doesn't work (yet).
如上所述这里和 [这里将是另一个链接但我的声誉不够高,不能发布超过2个链接] 自2015年8月以来已经多次请求此功能但运气不佳。
As described here and [here would be an other link but my reputation is not high enough to post more than 2 links] this feature has been requested several times since August 2015 with not much luck.
现在开启其中一位撰稿人评论说: Swagger-API github上的这个问题:
Now on this issue on the Swagger-API github, one of the contributors commented:
这需要对模型进行重大重构,这正在进行中。 2017年3月3日
导致稍后评论:
3.0.0支持将支持,有关详细信息,请参阅功能/ 3.0.0-rc2分支。 2017年6月27日
2017年8月9日 有人询问发布时间版本3.0.0将没有进一步的响应。
And on 9 August 2017 someone asked when the release of version 3.0.0 would be with no further response.
总而言之,支持数组/列表的示例已经开始工作,应该可以在3.0.0版本中使用,但是没有更多关于被释放。
这篇关于swagger @ApiModelProperty List< String>的示例值属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!