Skip to content

Commit dad9b16

Browse files
committed
fix(crystal): follow up #22545
1 parent 9d4abe3 commit dad9b16

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CrystalClientCodegen.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,19 @@ private String constructExampleCode(CodegenModel codegenModel, HashMap<String, C
777777
} else if (codegenModel.oneOf != null && !codegenModel.oneOf.isEmpty()) {
778778
String subModel = (String) codegenModel.oneOf.toArray()[0];
779779
if (modelMaps.get(subModel) == null) {
780-
LOGGER.warn("Cannot find codegen for SubModel: {} (model: {})", subModel, model);
781-
return "";
780+
if (subModel.startsWith("Array(")) {
781+
subModel = StringUtils.removeEnd(subModel.substring(6), ")");
782+
if (modelMaps.get(subModel) == null) {
783+
LOGGER.warn("Cannot find codegen for SubModel: {} (model: {})", subModel, model);
784+
return "";
785+
} else {
786+
LOGGER.info("Found Array codegen for SubModel: {} (model: {})", subModel, model);
787+
String oneOf = "[" + constructExampleCode(modelMaps.get(subModel), modelMaps, processedModelMap) + "]";
788+
return oneOf;
789+
}
790+
}
782791
} else {
792+
LOGGER.info("Found codegen for SubModel: {} (model: {})", subModel, model);
783793
String oneOf = constructExampleCode(modelMaps.get(subModel), modelMaps, processedModelMap);
784794
return oneOf;
785795
}
@@ -794,7 +804,7 @@ private String constructExampleCode(CodegenModel codegenModel, HashMap<String, C
794804
}
795805
String example = moduleName + "::" + toModelName(model) + ".new";
796806
if (!propertyExamples.isEmpty()) {
797-
example += "({" + StringUtils.join(propertyExamples, ", ") + "})";
807+
example += "(" + StringUtils.join(propertyExamples, ", ") + ")";
798808
}
799809
return example;
800810
}

0 commit comments

Comments
 (0)