【发布时间】:2019-11-15 21:41:37
【问题描述】:
我定义了 OpenAPI 3.0 文档并使用 openapi-generator-cli-3.3.4.jar 生成 Java 代码 (DTO)。
但是我解决不了这个案子:List<Map<Integer, Set<String>>>.
-
在
Map<Integer, String>问题中:据我所知,我可以使用schema object: additionalProperties 定义地图类型。
OpenAPI 规范additionalProperties:值可以是布尔值或对象。内联或引用架构必须是架构对象,而不是标准 JSON 架构。
根据上面,我不能将 Map 键设置为整数,对吗?对这个问题有什么建议吗?
在
set<String>或set<List<String>>问题中:我必须尝试一些努力:
Testing1:设置“uniqueItems”:true
{
"openapi": "3.0",
"info": {
"version": "1.0.0",
"title": "Dr.First Schema",
"license": {
"name": "MIT"
}
},
"components": {
"schemas": {
"Question": {
"type": "object",
"properties": {
"test": {
"type": "array",
"items":{
"type":"string"
}
}
}
}
}
}
}
生成 Java DTO:不 Set is List
/**
* Get test
* @return test
**/
@ApiModelProperty(value = "")
public List<String> getTest() {
return test;
}
public void setTest(List<String> test) {
this.test = test;
}
Testing2:将属性测试类型编辑为 Set
"test": {
"type": "Set"
}
警告
[main] WARN o.o.codegen.DefaultCodegen - Unknown type found in the schema: Set
[main] WARN o.o.codegen.DefaultCodegen - Unknown type found in the schema: Set
[main] WARN o.o.codegen.DefaultCodegen - Unknown type found in the schema: Set
生成 Java DTO:有语法错误
/**
* Get test
* @return test
**/
@ApiModelProperty(value = "")
public java.util.* getTest() {
return test;
}
public void setTest(java.util.* test) {
this.test = test;
}
Testing3:编辑要设置的属性测试类型
"test": {
"type": "set"
}
警告
[main] WARN o.o.codegen.DefaultCodegen - Unknown type found in the schema: set
[main] WARN o.o.codegen.DefaultCodegen - Unknown type found in the schema: set
[main] WARN o.o.codegen.DefaultCodegen - Unknown type found in the schema: set
生成 Java DTO:有 java 设置类型但不知道设置泛型
/**
* Get test
* @return test
**/
@ApiModelProperty(value = "")
public Set getTest() {
return test;
}
public void setTest(Set test) {
this.test = test;
}
- 有什么建议可以修复
Map<Integer, String>和 java Set generic issue in openapi-generator?
【问题讨论】:
-
嗨,Eddie,您找到解决问题的方法了吗?
标签: java generics hashmap hashset openapi-generator