在OpenAPI中指定集合
我正在使用OpenAPI / Swagger来指定我的API。
我找不到的一件事是如何指定集合。
我正在使用 https://editor.swagger.io/ 我在整个API中输入。对于我想指定为集合的属性,我编写了以下内容:
myProperty:
uniqueItems: true
type: array
description: some description
items:
type: string
我会猜测 uniqueItems 可以生成技巧和集合,但事实并非如此。相反,生成以下代码:
@JsonProperty("myProperty")
private List<String> myProperty = null;
有没有办法生成类似的东西
@JsonProperty("myProperty")
private Set<String> myProperty = null;
?
我找到了一个可能的解决方案在这里这需要pom.xml中的某些配置。但是,我正在使用的在线编辑器只为我提供了为不同平台生成代码的选项,但不接受POM文件。
I am using OpenAPI / Swagger to specify my API.
One thing that I could not find out is how to specify a Set.
I am using https://editor.swagger.io/ and I typed in the whole API. For a property that I want to specify as Set I wrote the following:
myProperty:
uniqueItems: true
type: array
description: some description
items:
type: string
I would have guessed that uniqueItems does the trick and a Set is generated, but this is not the case. Instead the following code is generated:
@JsonProperty("myProperty")
private List<String> myProperty = null;
Is there a way to generate something like
@JsonProperty("myProperty")
private Set<String> myProperty = null;
instead?
I found a possible solution here in SO, but this requires some configuration in a pom.xml. However, the online editor that I am using gives me only the option to generate code for different platforms but does not accept a pom file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenAPI(版本3)支持以下数据类型:
在OpenAPI V3中不支持SET数据类型。最接近的数据类型是具有属性 uniqueItems 设置为true的数组(如您所建议)。但这仍然是一个数组,对其项目的独特性有限制,而不是集合。
因此,您的请求无法在OpenAPI级别上解决。
但是,代码生成器级别可能有一个选项,您需要将问题解决到您选择的代码生成器。
OpenAPI (version 3) supports the following data types:
There is no support for set data type in OpenAPI v3. The closest data type is an array with property uniqueItems set to true (as you've suggested). But it's still an array with a constraint on the uniqueness of its items, not a set.
So, your request cannot be resolved on the OpenAPI level.
However, there might be an option on the code generator level, and you would need to address the issue to the code generator of your choice.