Skip to content

Commit e9f55c0

Browse files
authored
[Bug][Go] consider allOf schemas for rendering string default vaules (#14684)
1 parent 7968349 commit e9f55c0

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,29 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
387387
}
388388
}
389389

390+
/**
391+
* Determines if at least one of the allOf pieces of a schema are of type string
392+
*
393+
* @param p
394+
* @return
395+
*/
396+
private boolean isAllOfStringSchema(Schema schema) {
397+
if (schema.getAllOf() != null) {
398+
Iterator<Schema> it = schema.getAllOf().iterator();
399+
while (it.hasNext()) {
400+
Schema childSchema = ModelUtils.getReferencedSchema(this.openAPI, it.next());
401+
if (ModelUtils.isStringSchema(childSchema)) {
402+
return true;
403+
}
404+
}
405+
}
406+
return false;
407+
}
408+
390409
@Override
391410
public String toDefaultValue(Schema p) {
392411
p = ModelUtils.getReferencedSchema(this.openAPI, p);
393-
if (ModelUtils.isStringSchema(p)) {
412+
if (ModelUtils.isStringSchema(p) || isAllOfStringSchema(p)) {
394413
Object defaultObj = p.getDefault();
395414
if (defaultObj != null) {
396415
if (defaultObj instanceof java.lang.String) {

0 commit comments

Comments
 (0)