Skip to content

Commit b0b2835

Browse files
Copilotalexaka1
andcommitted
fix: emit : long for int64 enum declarations and add test assertions
The enum declaration template now checks `{{#isLong}}` to emit `: long` as the underlying type, preventing overflow for int64 enum values. Added test assertions verifying: - LongEnum has `: long` in its declaration - IntegerEnum does NOT have `: long` or `: byte` Co-authored-by: alexaka1 <22166651+alexaka1@users.noreply.github.com>
1 parent 383ea38 commit b0b2835

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

modules/openapi-generator/src/main/resources/csharp/modelEnum.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{{/-first}}
2222
{{/enumVars}}
2323
{{/allowableValues}}
24-
{{>visibility}} enum {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}{{#vendorExtensions.x-enum-byte}}: byte{{/vendorExtensions.x-enum-byte}}
24+
{{>visibility}} enum {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}{{#vendorExtensions.x-enum-byte}}: byte{{/vendorExtensions.x-enum-byte}}{{#isLong}}: long{{/isLong}}
2525
{
2626
{{#allowableValues}}
2727
{{#enumVars}}

modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcore/CSharpClientCodegenTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ public void testIntegerEnumJsonConverterUsesNumericOperations() throws IOExcepti
293293
);
294294
assertFileNotContains(intEnumFile.toPath(),
295295
"reader.GetString()",
296-
"writer.WriteStringValue("
296+
"writer.WriteStringValue(",
297+
": long",
298+
": byte"
297299
);
298300

299301
// Verify long enum uses int64 reader with validation and actual int64 values
@@ -303,6 +305,7 @@ public void testIntegerEnumJsonConverterUsesNumericOperations() throws IOExcepti
303305
);
304306
assertNotNull(longEnumFile, "Could not find file for model: LongEnum");
305307
assertFileContains(longEnumFile.toPath(),
308+
"enum LongEnum: long",
306309
"reader.GetInt64().ToString()",
307310
"FromStringOrDefault(rawValue)",
308311
"throw new JsonException()",

0 commit comments

Comments
 (0)