diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index a67cd98cfdc2..dee8caaadd30 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -1831,7 +1831,7 @@ public class DefaultCodegen { currentProperty = currentProperty.items; } - return currentProperty.isEnum; + return currentProperty == null ? false : currentProperty.isEnum; } protected Map getInnerEnumAllowableValues(CodegenProperty property) { @@ -1841,7 +1841,7 @@ public class DefaultCodegen { currentProperty = currentProperty.items; } - return currentProperty.allowableValues; + return currentProperty == null ? new HashMap() : currentProperty.allowableValues; } @@ -1855,16 +1855,18 @@ public class DefaultCodegen { || Boolean.TRUE.equals(baseItem.isListContainer))) { baseItem = baseItem.items; } - // set both datatype and datetypeWithEnum as only the inner type is enum - property.datatypeWithEnum = property.datatypeWithEnum.replace(baseItem.baseType, toEnumName(baseItem)); + if (baseItem != null) { + // set both datatype and datetypeWithEnum as only the inner type is enum + property.datatypeWithEnum = property.datatypeWithEnum.replace(baseItem.baseType, toEnumName(baseItem)); - // naming the enum with respect to the language enum naming convention - // e.g. remove [], {} from array/map of enum - property.enumName = toEnumName(property); + // naming the enum with respect to the language enum naming convention + // e.g. remove [], {} from array/map of enum + property.enumName = toEnumName(property); - // set default value for variable with inner enum - if (property.defaultValue != null) { - property.defaultValue = property.defaultValue.replace(baseItem.baseType, toEnumName(baseItem)); + // set default value for variable with inner enum + if (property.defaultValue != null) { + property.defaultValue = property.defaultValue.replace(baseItem.baseType, toEnumName(baseItem)); + } } } @@ -1878,16 +1880,19 @@ public class DefaultCodegen { || Boolean.TRUE.equals(baseItem.isListContainer))) { baseItem = baseItem.items; } - // set both datatype and datetypeWithEnum as only the inner type is enum - property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + baseItem.baseType, ", " + toEnumName(baseItem)); - // naming the enum with respect to the language enum naming convention - // e.g. remove [], {} from array/map of enum - property.enumName = toEnumName(property); + if (baseItem != null) { + // set both datatype and datetypeWithEnum as only the inner type is enum + property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + baseItem.baseType, ", " + toEnumName(baseItem)); - // set default value for variable with inner enum - if (property.defaultValue != null) { - property.defaultValue = property.defaultValue.replace(", " + property.items.baseType, ", " + toEnumName(property.items)); + // naming the enum with respect to the language enum naming convention + // e.g. remove [], {} from array/map of enum + property.enumName = toEnumName(property); + + // set default value for variable with inner enum + if (property.defaultValue != null) { + property.defaultValue = property.defaultValue.replace(", " + property.items.baseType, ", " + toEnumName(property.items)); + } } }