fix NPE with cpp qt5, add logic to avoid NPE with composed schema (#267)

This commit is contained in:
William Cheng
2018-05-01 12:05:57 +08:00
committed by GitHub
parent acb63fd5e8
commit 0b3ec6b1f8
8 changed files with 111 additions and 24 deletions

View File

@@ -1148,6 +1148,18 @@ public class DefaultCodegen implements CodegenConfig {
**/
@SuppressWarnings("static-method")
public String getSchemaType(Schema schema) {
// TODO better logic to handle compose schema
if (schema instanceof ComposedSchema) { // composed schema
ComposedSchema cs = (ComposedSchema) schema;
for (Schema s : cs.getAllOf()) {
if (s != null) {
// using the first schema defined in allOf
schema = s;
break;
}
}
}
if (StringUtils.isNotBlank(schema.get$ref())) { // object
// get the schema/model name from $ref
String schemaName = ModelUtils.getSimpleRef(schema.get$ref());

View File

@@ -345,6 +345,7 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
@Override
public String getSchemaType(Schema p) {
String openAPIType = super.getSchemaType(p);
String type = null;
if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
@@ -362,6 +363,11 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
@Override
public String toModelName(String type) {
if (type == null) {
LOGGER.warn("Model name can't be null. Defaul to 'UnknownModel'.");
type = "UnknownModel";
}
if (typeMapping.keySet().contains(type) ||
typeMapping.values().contains(type) ||
importMapping.values().contains(type) ||