forked from loafle/openapi-generator-original
fix npe when array item missing (#2247)
This commit is contained in:
parent
f47af5e6f0
commit
24f20941e5
@ -621,12 +621,16 @@ public class CodegenModel {
|
||||
*/
|
||||
public void removeSelfReferenceImport() {
|
||||
for (CodegenProperty cp : allVars) {
|
||||
if (cp == null) {
|
||||
// TODO cp shouldn't be null. Show a warning message instead
|
||||
} else {
|
||||
// detect self import
|
||||
if (cp.dataType.equalsIgnoreCase(this.classname) ||
|
||||
(cp.isContainer && cp.items.dataType.equalsIgnoreCase(this.classname))) {
|
||||
if (this.classname.equalsIgnoreCase(cp.dataType) ||
|
||||
(cp.isContainer && cp.items != null && this.classname.equalsIgnoreCase(cp.items.dataType))) {
|
||||
this.imports.remove(this.classname); // remove self import
|
||||
cp.isSelfReference = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
for (CodegenProperty cp : cm.allVars) {
|
||||
// detect self import
|
||||
if (cp.dataType.equalsIgnoreCase(cm.classname) ||
|
||||
(cp.isContainer && cp.items.dataType.equalsIgnoreCase(cm.classname))) {
|
||||
(cp.isContainer && cp.items != null && cp.items.dataType.equalsIgnoreCase(cm.classname))) {
|
||||
cm.imports.remove(cm.classname); // remove self import
|
||||
cp.isSelfReference = true;
|
||||
}
|
||||
@ -1507,10 +1507,16 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @return a string presentation of the property type
|
||||
*/
|
||||
public String getTypeDeclaration(Schema schema) {
|
||||
if (schema == null) {
|
||||
LOGGER.warn("Null schema found. Default type to `NULL_SCHMEA_ERR`");
|
||||
return "NULL_SCHMEA_ERR";
|
||||
}
|
||||
|
||||
String oasType = getSchemaType(schema);
|
||||
if (typeMapping.containsKey(oasType)) {
|
||||
return typeMapping.get(oasType);
|
||||
}
|
||||
|
||||
return oasType;
|
||||
}
|
||||
|
||||
|
@ -329,12 +329,19 @@ public class ModelUtils {
|
||||
if (schema instanceof MapSchema) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (schema == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (schema.getAdditionalProperties() instanceof Schema) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (schema.getAdditionalProperties() instanceof Boolean && (Boolean) schema.getAdditionalProperties()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -343,7 +350,7 @@ public class ModelUtils {
|
||||
return true;
|
||||
}
|
||||
// assume it's an array if maxItems, minItems is set
|
||||
if (schema.getMaxItems() != null || schema.getMinItems() != null) {
|
||||
if (schema != null && (schema.getMaxItems() != null || schema.getMinItems() != null)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user