add warning message for null inner type (map/array) (#4408)

This commit is contained in:
wing328 2016-12-16 19:41:54 +08:00 committed by GitHub
parent 6af43dc720
commit 2172cfef84

View File

@ -462,12 +462,19 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
ArrayProperty ap = (ArrayProperty) p; ArrayProperty ap = (ArrayProperty) p;
Property inner = ap.getItems(); Property inner = ap.getItems();
if (inner == null) { if (inner == null) {
return null; LOGGER.warn(ap.getName() + "(array property) does not have a proper inner type defined");
// TODO maybe better defaulting to StringProperty than returning null
return null;
} }
return getSwaggerType(p) + "<" + getTypeDeclaration(inner) + ">"; return getSwaggerType(p) + "<" + getTypeDeclaration(inner) + ">";
} else if (p instanceof MapProperty) { } else if (p instanceof MapProperty) {
MapProperty mp = (MapProperty) p; MapProperty mp = (MapProperty) p;
Property inner = mp.getAdditionalProperties(); Property inner = mp.getAdditionalProperties();
if (inner == null) {
LOGGER.warn(mp.getName() + "(map property) does not have a proper inner type defined");
// TODO maybe better defaulting to StringProperty than returning null
return null;
}
return getSwaggerType(p) + "<String, " + getTypeDeclaration(inner) + ">"; return getSwaggerType(p) + "<String, " + getTypeDeclaration(inner) + ">";
} }
return super.getTypeDeclaration(p); return super.getTypeDeclaration(p);
@ -484,7 +491,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
pattern = "new ArrayList<%s>()"; pattern = "new ArrayList<%s>()";
} }
if (ap.getItems() == null) { if (ap.getItems() == null) {
return null; return null;
} }
return String.format(pattern, getTypeDeclaration(ap.getItems())); return String.format(pattern, getTypeDeclaration(ap.getItems()));
} else if (p instanceof MapProperty) { } else if (p instanceof MapProperty) {
@ -495,6 +502,9 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
} else { } else {
pattern = "new HashMap<String, %s>()"; pattern = "new HashMap<String, %s>()";
} }
if (ap.getAdditionalProperties() == null) {
return null;
}
return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties())); return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties()));
} else if (p instanceof IntegerProperty) { } else if (p instanceof IntegerProperty) {
IntegerProperty dp = (IntegerProperty) p; IntegerProperty dp = (IntegerProperty) p;