forked from loafle/openapi-generator-original
fix(avro-schema): fix NPE for null
enum values (#19771)
This commit is contained in:
parent
817da39124
commit
cfe6520283
@ -6648,7 +6648,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
for (Object value : values) {
|
for (Object value : values) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
// raw null values in enums are unions for nullable
|
// raw null values in enums are unions for nullable
|
||||||
// atttributes, not actual enum values, so we remove them here
|
// attributes, not actual enum values, so we remove them here
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Map<String, Object> enumVar = new HashMap<>();
|
Map<String, Object> enumVar = new HashMap<>();
|
||||||
|
@ -199,8 +199,11 @@ public class AvroSchemaCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<Map<String, Object>> buildEnumVars(List<Object> values, String dataType) {
|
protected List<Map<String, Object>> buildEnumVars(List<Object> values, String dataType) {
|
||||||
List<Object> sanitizedValues = values.stream().map(Object::toString).map(this::sanitizeEnumValue)
|
List<Object> sanitizedValues = values.stream()
|
||||||
.collect(Collectors.toList());
|
.filter(x -> x != null)
|
||||||
|
.map(Object::toString)
|
||||||
|
.map(this::sanitizeEnumValue)
|
||||||
|
.collect(Collectors.toList());
|
||||||
removeEnumValueCollisions(sanitizedValues);
|
removeEnumValueCollisions(sanitizedValues);
|
||||||
return super.buildEnumVars(sanitizedValues, dataType);
|
return super.buildEnumVars(sanitizedValues, dataType);
|
||||||
}
|
}
|
||||||
|
@ -27,4 +27,16 @@ components:
|
|||||||
# The next two is to make sure collisions are resolved properly
|
# The next two is to make sure collisions are resolved properly
|
||||||
- 'coll-ision'
|
- 'coll-ision'
|
||||||
- 'coll_ision'
|
- 'coll_ision'
|
||||||
type: 'string'
|
type: 'string'
|
||||||
|
another:
|
||||||
|
enum:
|
||||||
|
- 'x'
|
||||||
|
- 'y'
|
||||||
|
- null
|
||||||
|
type: 'string'
|
||||||
|
equivalent:
|
||||||
|
enum:
|
||||||
|
- 'x'
|
||||||
|
- 'y'
|
||||||
|
type: 'string'
|
||||||
|
nullable: true
|
@ -20,6 +20,32 @@
|
|||||||
}],
|
}],
|
||||||
"doc": "",
|
"doc": "",
|
||||||
"default": null
|
"default": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "another",
|
||||||
|
"type": ["null", {
|
||||||
|
"type": "enum",
|
||||||
|
"name": "Sample_another",
|
||||||
|
"symbols": [
|
||||||
|
"x",
|
||||||
|
"y"
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
"doc": "",
|
||||||
|
"default": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "equivalent",
|
||||||
|
"type": ["null", {
|
||||||
|
"type": "enum",
|
||||||
|
"name": "Sample_equivalent",
|
||||||
|
"symbols": [
|
||||||
|
"x",
|
||||||
|
"y"
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
"doc": "",
|
||||||
|
"default": null
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user