I define OpenAPI 3.0 documents and use openapi-generator-cli-3.3.4.jar to generate Java code (DTO).
But I can't solve this case: List<Map<Integer, Set<String>>>
.
In Map<Integer, String>
issue:
As I know I can use schema object: additionalProperties define map type.
OpenAPI Specification additionalProperties: Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
According above, I can't set Map key to an integer, right? Have any suggestions on this issue?
In set<String>
or set<List<String>>
issue: I have to try some effort:
Testing1: set "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"
}
}
}
}
}
}
}
Generate Java DTO: not 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: edit the properties test type to Set
"test": {
"type": "Set"
}
Warn
[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
Generate Java DTO: Have syntax error
/**
* Get test
* @return test
**/
@ApiModelProperty(value = "")
public java.util.* getTest() {
return test;
}
public void setTest(java.util.* test) {
this.test = test;
}
Testing3: edit the properties test type to set
"test": {
"type": "set"
}
Warn
[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
Generate Java DTO: Have java Set type but no idea to setting generic
/**
* Get test
* @return test
**/
@ApiModelProperty(value = "")
public Set getTest() {
return test;
}
public void setTest(Set test) {
this.test = test;
}
Map<Integer, String>
and java Set generic issue in openapi-generator?For openapi version 3.0.3 this example of Java generic set works
yaml definition:
mapOfSets:
type: object
additionalProperties:
type: setOfStrings
maven pom.xml configuration for openapi-generator-maven-plugin:
<typeMappings>
<typeMapping>setOfStrings=Set<String></typeMapping>
</typeMappings>
<importMappings>
<importMapping>Set<String>=java.util.Set</importMapping>
</importMappings>
Generated Java code:
private Map<String, Set<String>> mapOfSets = null;
Here setOfStrings is a custom openapi type that has custom mappings defined in pom.xml and will generate Set<String> Java type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With