Fix examples for request body with array to not raise java.lang.NullPointerException (#11170)

This commit is contained in:
Yohei Kitamura 2022-01-04 01:36:28 -05:00 committed by GitHub
parent 0a09f1faa3
commit 5a616757e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 3 deletions

View File

@ -657,7 +657,11 @@ public class CrystalClientCodegen extends DefaultCodegen {
if (codegenProperty.isArray) { // array if (codegenProperty.isArray) { // array
return "[" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "]"; return "[" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "]";
} else if (codegenProperty.isMap) { } else if (codegenProperty.isMap) {
if (codegenProperty.items != null) {
return "{ key: " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}"; return "{ key: " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}";
} else {
return "{ ... }";
}
} else if (codegenProperty.isPrimitiveType) { // primitive type } else if (codegenProperty.isPrimitiveType) { // primitive type
if (codegenProperty.isEnum) { if (codegenProperty.isEnum) {
// When inline enum, set example to first allowable value // When inline enum, set example to first allowable value

View File

@ -555,6 +555,9 @@ public class GoClientCodegen extends AbstractGoCodegen {
if (modelMaps.containsKey(dataType)) { if (modelMaps.containsKey(dataType)) {
prefix = "map[string][]" + goImportAlias + "." + dataType; prefix = "map[string][]" + goImportAlias + "." + dataType;
} }
if (codegenProperty.items == null) {
return prefix + "{ ... }";
}
return prefix + "{\"key\": " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}"; return prefix + "{\"key\": " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}";
} else if (codegenProperty.isPrimitiveType) { // primitive type } else if (codegenProperty.isPrimitiveType) { // primitive type
if (codegenProperty.isString) { if (codegenProperty.isString) {

View File

@ -1230,7 +1230,11 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
example.append(constructExampleCode(codegenProperty.items, modelMaps, processedModelMap, requiredOnly)); example.append(constructExampleCode(codegenProperty.items, modelMaps, processedModelMap, requiredOnly));
} else if (codegenProperty.isMap) { } else if (codegenProperty.isMap) {
example.append("@{ key_example = "); example.append("@{ key_example = ");
if (codegenProperty.items != null) {
example.append(constructExampleCode(codegenProperty.items, modelMaps, processedModelMap, requiredOnly)); example.append(constructExampleCode(codegenProperty.items, modelMaps, processedModelMap, requiredOnly));
} else {
example.append(" ... ");
}
example.append(" }"); example.append(" }");
} else if (codegenProperty.isEnum || (codegenProperty.allowableValues != null && !codegenProperty.allowableValues.isEmpty())) { } else if (codegenProperty.isEnum || (codegenProperty.allowableValues != null && !codegenProperty.allowableValues.isEmpty())) {
example.append(constructEnumExample(codegenProperty.allowableValues)); example.append(constructEnumExample(codegenProperty.allowableValues));

View File

@ -680,7 +680,11 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
} }
return "[" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "]"; return "[" + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "]";
} else if (codegenProperty.isMap) { } else if (codegenProperty.isMap) {
if (codegenProperty.items != null) {
return "{ key: " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}"; return "{ key: " + constructExampleCode(codegenProperty.items, modelMaps, processedModelMap) + "}";
} else {
return "{ ... }";
}
} else if (codegenProperty.isPrimitiveType) { // primitive type } else if (codegenProperty.isPrimitiveType) { // primitive type
if (codegenProperty.isEnum) { if (codegenProperty.isEnum) {
// When inline enum, set example to first allowable value // When inline enum, set example to first allowable value