From 7db0201a8959efdd32e8dae2ce585d6e9ee5bd5a Mon Sep 17 00:00:00 2001 From: delenius Date: Sat, 26 May 2018 02:42:02 -0700 Subject: [PATCH] Fix NPEs in Java generator (#154) --- .../java/org/openapitools/codegen/DefaultCodegen.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 471b8c7122..d3e211aabb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -1459,7 +1459,7 @@ public class DefaultCodegen implements CodegenConfig { } // parent model final String parentName = getParentName(composed, allDefinitions); - final Schema parent = StringUtils.isBlank(parentName) ? null : allDefinitions.get(parentName); + final Schema parent = StringUtils.isBlank(parentName) || allDefinitions == null ? null : allDefinitions.get(parentName); List interfaces = getInterfaces(composed); @@ -4097,7 +4097,12 @@ public class DefaultCodegen implements CodegenConfig { codegenParameter.isListContainer = true; codegenParameter.description = s.getDescription(); codegenParameter.dataType = getTypeDeclaration(s); - codegenParameter.datatypeWithEnum = codegenParameter.dataType.replace(codegenParameter.baseType, codegenParameter.enumName); + if (codegenParameter.baseType != null && codegenParameter.enumName != null){ + codegenParameter.datatypeWithEnum = codegenParameter.dataType.replace(codegenParameter.baseType, codegenParameter.enumName); + } + else { + LOGGER.warn("Could not compute datatypeWithEnum from " + codegenParameter.baseType + ", " + codegenParameter.enumName); + } //TODO fix collectformat for form parameters //collectionFormat = getCollectionFormat(s); // default to csv: