Skip to content

Commit b559692

Browse files
author
Swapneswar Sundar Ray
committed
Fix protobuf enum reference for wrapped enums
1 parent 2917ce8 commit b559692

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,24 @@ public ModelsMap postProcessModels(ModelsMap objs) {
731731
}
732732
}
733733

734+
// Fix for enum wrapping when NOT extracting enums to separate files
735+
// Since v7.20.0, all enums are wrapped in messages but field references
736+
// weren't updated to use .Enum suffix when not extracted
737+
boolean isDirectEnumForFix = property.isEnum;
738+
boolean isArrayOfEnumsForFix = property.isArray && property.items != null && property.items.isEnum;
739+
740+
if ((isDirectEnumForFix || isArrayOfEnumsForFix) && !this.extractEnumsToSeparateFiles) {
741+
// For enums that are wrapped but not extracted, update the data type to use .Enum suffix
742+
CodegenProperty enumPropertyForFix = isArrayOfEnumsForFix ? property.items : property;
743+
String enumTypeName = enumPropertyForFix.dataType;
744+
745+
if (StringUtils.isNotBlank(enumTypeName)) {
746+
// Update x-protobuf-data-type to reference the wrapped enum's inner Enum
747+
String wrappedEnumType = enumTypeName + "." + ENUM_WRAPPER_INNER_NAME;
748+
property.vendorExtensions.put("x-protobuf-data-type", wrappedEnumType);
749+
}
750+
}
751+
734752
// Check if this property is an enum or an array of enums.
735753
//
736754
// This handles two distinct cases:

0 commit comments

Comments
 (0)