prevent NPE in constructing oneOf example (#9231)

This commit is contained in:
William Cheng 2021-04-20 15:05:34 +08:00 committed by GitHub
parent aa5adbf3f5
commit 51028f0c1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -748,8 +748,14 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
return moduleName + "::" + codegenModel.classname + "::" + enumVars.get(0).get("name");
} else if (codegenModel.oneOf != null && !codegenModel.oneOf.isEmpty()) {
String subModel = (String) codegenModel.oneOf.toArray()[0];
String oneOf = constructExampleCode(modelMaps.get(subModel), modelMaps, processedModelMap);
return oneOf;
if (modelMaps.containsKey(subModel)) {
// oneOf models
return constructExampleCode(modelMaps.get(subModel), modelMaps, processedModelMap);
} else {
// TODO oneOf primitive type not supported at the moment
LOGGER.warn("oneOf example value not supported at the moment.");
return "nil";
}
} else {
processedModelMap.put(model, 1);
}