forked from loafle/openapi-generator-original
Fix example generation when missing models (#11805)
For some buggy configurations, a warning is emitted indicating that for a given request body the corresponding CodegenModel could not be found. When this happens, some generators produce NPEs when writing out example code. This change avoids the NPEs by providing a stub value instead.
This commit is contained in:
@@ -489,6 +489,9 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
if (modelMaps.containsKey(dataType)) {
|
||||
prefix = "map[string][]" + goImportAlias + "." + dataType;
|
||||
}
|
||||
if (codegenParameter.items == null) {
|
||||
return prefix + "{ ... }";
|
||||
}
|
||||
return prefix + "{\"key\": " + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "}";
|
||||
} else if (codegenParameter.isPrimitiveType) { // primitive type
|
||||
if (codegenParameter.isString) {
|
||||
|
||||
@@ -1182,7 +1182,9 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
example.append(constructExampleCode(codegenParameter.items, modelMaps, processedModelMap, requiredOnly));
|
||||
}
|
||||
} else if (codegenParameter.isMap) {
|
||||
if (codegenParameter.items.isModel) {
|
||||
if (codegenParameter.items == null) {
|
||||
example.append("@{ key_example = ... }");
|
||||
} else if (codegenParameter.items.isModel) {
|
||||
String modelExample = constructExampleCode(codegenParameter.items, modelMaps, processedModelMap, requiredOnly);
|
||||
if (!StringUtils.isEmpty(modelExample)) {
|
||||
example.append(modelExample).append("\n");
|
||||
|
||||
@@ -614,6 +614,9 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
||||
if (codegenParameter.isArray) { // array
|
||||
return "[" + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "]";
|
||||
} else if (codegenParameter.isMap) {
|
||||
if (codegenParameter.items == null) {
|
||||
return "{ ... }";
|
||||
}
|
||||
return "{ key: " + constructExampleCode(codegenParameter.items, modelMaps, processedModelMap) + "}";
|
||||
} else if (codegenParameter.isPrimitiveType) { // primitive type
|
||||
if (codegenParameter.isEnum) {
|
||||
|
||||
Reference in New Issue
Block a user