Skip to content

fix(csharp): use numeric JSON operations for integer enum converters#22917

Open
alexaka1 wants to merge 5 commits intoOpenAPITools:masterfrom
alexaka1:copilot/fix-enum-string-generation
Open

fix(csharp): use numeric JSON operations for integer enum converters#22917
alexaka1 wants to merge 5 commits intoOpenAPITools:masterfrom
alexaka1:copilot/fix-enum-string-generation

Conversation

@alexaka1
Copy link

@alexaka1 alexaka1 commented Feb 7, 2026

Integer enums now correctly use reader.GetInt32()/GetInt64() and writer.WriteNumberValue() instead of reader.GetString() and writer.WriteStringValue(value ?? "null") in the generated JsonConverter classes.

This fixes System.InvalidOperationException when deserializing integer enum values from JSON numbers.

Fixes #21618

All CI passes in my fork against master: https://github.com/alexaka1/openapi-generator/pull/1/checks

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Mentioning @mandrean @shibayan @Blackclaws @lucamazzanti @iBicha


Summary by cubic

Generated C# generichost enum JsonConverters now read/write numbers for numeric enums (int32/int64/float/double/decimal) instead of strings, and validate integer/long values during deserialization. This fixes InvalidOperationException for integers, corrects floating-point values, tightens input validation, and cleans up generated converter formatting.

  • Bug Fixes
    • Generate numeric read/write for non-string enums in modelEnum.mustache; new EnumJsonReaderMethod picks GetInt32/GetInt64/GetSingle/GetDouble/GetDecimal; use WriteNumberValue.
    • Float/double/decimal enums: ToJsonValue returns exact numeric literals; Read uses numeric getters with InvariantCulture; Write uses WriteNumberValue.
    • Integer/long enums: Read validates via FromStringOrDefault so invalid numbers throw JsonException instead of silent casts.
    • Mustache cleanup: swap triple-negation for positive flags (isInteger, isLong) to avoid blank lines/indent issues.
    • Added test and OpenAPI fixture; updated LongEnum values (2147483648, 9223372036854775807); regenerated C# generichost samples. Fixes [BUG][CSHARP] Enums are always generated as strings, even if type is integer #21618.

Written for commit 5233c7c. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

40 issues found across 78 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs:108">
P2: Directly casting the JSON double to the enum breaks the required mapping for values like -1.2; it truncates to -1 and yields an undefined enum instead of NUMBER_MINUS_1_DOT_2.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:119">
P2: Enum deserialization no longer validates that the integer is a defined enum member; casting allows invalid values, so undefined integers will deserialize without error.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs:108">
P2: Directly casting the JSON double to the enum truncates values like -1.2, producing invalid or unintended enum values instead of using the defined mapping for 1.1/-1.2.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:119">
P2: Directly casting the JSON int to OuterEnumInteger removes enum validation and allows undefined values to deserialize without error.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumIntegerOnly.cs:107">
P2: Enum JSON deserialization no longer validates that the integer value is defined in EnumTestEnumIntegerOnly, so unknown values deserialize silently instead of raising JsonException.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs:108">
P2: Deserializing the mapped double enum by casting the raw JSON double to the enum truncates values like -1.2 to -1, producing an invalid enum instead of NUMBER_MINUS_1_DOT_2. This bypasses the defined mapping and corrupts data.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs:108">
P2: Directly casting the JSON double to the enum bypasses the 1.1/-1.2 mapping; values like -1.2 become an undefined enum value (-1). This breaks deserialization for the negative floating-point enum member.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumIntegerOnly.cs:108">
P2: The updated Read method casts raw integers directly to the enum without validating that the value is defined. C# allows undefined enum values via int cast, so invalid JSON values (e.g., 3) will now deserialize successfully, regressing prior validation that threw JsonException. This can break downstream logic that assumes only defined enum members.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs:108">
P2: Enum deserialization no longer validates that the JSON integer is a defined enum member, so undefined values deserialize silently instead of throwing JsonException.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumIntegerOnly.cs:108">
P2: Enum deserialization now accepts any integer value without validation, allowing invalid enum values to be deserialized silently.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs:108">
P2: Deserialization no longer validates enum values; casting from int allows undefined values (e.g., 0, 2) to be accepted instead of throwing, which is a regression from the previous validation behavior.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:119">
P2: Enum deserialization no longer validates that the integer matches a defined enum value, so invalid values deserialize silently.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs:119">
P2: Enum deserialization no longer validates that the integer is a defined enum member, allowing undefined values to be accepted silently.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net8/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs:119">
P2: Enum deserialization no longer validates defined values; invalid integers now cast to the enum without throwing, allowing undefined values into the model.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:119">
P2: Enum deserialization no longer validates that the numeric value is one of the defined enum members; invalid integers will deserialize without error.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumInteger.cs:108">
P2: Enum deserialization no longer validates that the integer value maps to a defined enum member, so invalid values are accepted silently.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs:107">
P2: Enum validation regression: direct int cast allows undefined values to deserialize without error, whereas the previous implementation rejected invalid values.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs:108">
P2: Enum deserialization no longer validates values; any integer is cast to the enum, allowing undefined values that previously raised JsonException.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs:108">
P2: Enum deserialization no longer validates that the integer value is one of the defined enum members, so undefined values will now be accepted instead of rejected.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs:108">
P2: Enum deserialization no longer validates that the integer value maps to a defined EnumTestEnumInteger member, allowing undefined values to deserialize silently (regression from previous JsonException behavior).</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs:108">
P2: Directly casting the JSON integer to the enum removes validation and allows undefined enum values to deserialize without error, which is a behavioral regression from the prior validation logic.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumInteger.cs:108">
P2: The new integer enum converter no longer validates values against defined enum members, so undefined integers deserialize without error.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:119">
P2: Deserialization now accepts undefined integer values for OuterEnumInteger without validation, losing the prior enum contract enforcement and allowing invalid values to flow through silently.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs:108">
P2: Directly casting the JSON integer to the enum removes validation of allowed enum values; undefined values will deserialize without error, which is a regression from the prior behavior that rejected invalid values.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs:108">
P2: Enum deserialization no longer validates that the numeric value is a defined enum member, allowing invalid values to deserialize silently.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs:108">
P2: Directly casting the JSON integer to EnumTestEnumInteger skips validation and allows undefined enum values to deserialize without error, weakening data integrity compared to the previous behavior that threw JsonException for invalid values.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs:108">
P2: Enum deserialization no longer validates that incoming integer values match defined enum members, allowing undefined values to pass through without error.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumIntegerOnly.cs:107">
P2: Enum deserialization no longer validates that the integer value is a defined enum member, so undefined values will deserialize into invalid enum states instead of failing.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumIntegerOnly.cs:107">
P2: Direct enum casting allows undefined integer values to deserialize without validation, regressing the previous strict check and allowing invalid enum states.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs:119">
P2: Enum deserialization no longer validates that the integer value is a defined member, allowing invalid values to deserialize silently.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumInteger.cs:108">
P2: Enum deserialization no longer validates that the integer value matches a defined enum member, so undefined values will be accepted instead of throwing.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs:107">
P2: Enum deserialization no longer validates that the JSON integer matches a defined enum member, so undefined values now deserialize silently.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:118">
P2: Enum deserialization no longer validates that the JSON integer matches a defined enum member; any integer now casts to OuterEnumInteger, allowing invalid values to slip through instead of throwing JsonException.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs:119">
P2: Enum deserialization no longer validates that the integer value is defined; invalid values (e.g., 99) will be accepted and propagated instead of throwing, which is a regression from the previous validation logic.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumIntegerOnly.cs:107">
P2: Enum deserialization no longer validates membership, so undefined integer values now deserialize silently into the enum, bypassing the previous JsonException behavior for unknown values.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:120">
P2: Enum deserialization no longer validates that JSON integers map to defined enum members, allowing invalid values to deserialize silently.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumIntegerOnly.cs:108">
P2: Integer enum deserialization no longer validates that the value is defined in the enum, so invalid values now deserialize silently instead of throwing JsonException.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs:108">
P2: Directly casting the JSON integer to EnumTestEnumInteger removes validation and allows undefined enum values (e.g., 0 or 2) to deserialize without error, unlike the previous implementation which threw JsonException for invalid values.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/csharp/modelEnum.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/csharp/modelEnum.mustache:126">
P2: Numeric enum deserialization now accepts any integer by direct cast, bypassing the enum validation enforced for string values. This allows undefined enum values to be deserialized without error.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs:120">
P2: Serialization writes the enum's underlying integer values (1/2) instead of the documented wire values (1.1/-1.2), so the JSON output is incorrect for this double enum.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

…in C# generichost

Integer enums now correctly use reader.GetInt32()/GetInt64() and
writer.WriteNumberValue() instead of reader.GetString() and
writer.WriteStringValue() in the generated JsonConverter classes.

This fixes System.InvalidOperationException when deserializing integer
enum values from JSON numbers.

Co-authored-by: copilot-swe-agent[bot] <198982749+copilot@users.noreply.github.com>
@alexaka1 alexaka1 force-pushed the copilot/fix-enum-string-generation branch from e6700bf to 29ce4b6 Compare February 7, 2026 10:12
For floating-point enums (double, float, decimal), C# enums can't have
non-integral underlying types, so:
- ToJsonValue now returns actual enum values via switch-case instead of
  casting (which gave wrong values like 2.0 instead of -1.2)
- Read method uses reader.GetDouble() etc. and converts to string with
  InvariantCulture for matching via FromStringOrDefault
- Write method uses WriteNumberValue with the corrected ToJsonValue

Integer enums (int32, int64) still use direct cast as before.

Co-authored-by: alexaka1 <22166651+alexaka1@users.noreply.github.com>
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 77 files (changes from recent commits).

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="modules/openapi-generator/src/main/resources/csharp/modelEnum.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/csharp/modelEnum.mustache:163">
P2: Invariant-culture formatting in Read conflicts with FromStringOrDefault’s culture-sensitive numeric ToString(), so float/double/decimal enum deserialization can fail in non-US locales (e.g., "1.5" vs "1,5").</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copilot AI and others added 3 commits February 7, 2026 11:08
Use 2147483648 (int32 max + 1) and 9223372036854775807 (int64 max) to
ensure the int64 branch is properly exercised with values that exceed
int32 range.

Co-authored-by: alexaka1 <22166651+alexaka1@users.noreply.github.com>
Replace triple-negation pattern ({{^isFloat}}{{^isDouble}}{{^isDecimal}})
with positive flags ({{#isInteger}}, {{#isLong}}) for integer enum
branches. The triple-negation caused the Java Mustache engine to produce
spurious blank lines and incorrect indentation in the generated C# code.

Co-authored-by: alexaka1 <22166651+alexaka1@users.noreply.github.com>
Use FromStringOrDefault for all numeric enum types (int, long, float,
double, decimal), not just float/double/decimal. This ensures invalid
values throw JsonException instead of being silently cast to the enum.

Co-authored-by: alexaka1 <22166651+alexaka1@users.noreply.github.com>
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

33 issues found across 71 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs:107">
P2: InvariantCulture string conversion in Read can mismatch the CurrentCulture string comparisons in FromStringOrDefault, causing valid negative enum values (e.g., -2) to fail deserialization in some locales.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:121">
P2: InvariantCulture conversion in Read can mismatch FromStringOrDefault’s current-culture comparisons, causing valid numeric enums to deserialize as null/JsonException in locales with non-ASCII digits.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs:118">
P2: InvariantCulture string conversion in Read mismatches culture‑dependent comparisons in FromStringOrDefault, so valid enum values can fail to deserialize in locales with non‑Western digits (returns null and throws JsonException).</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs:118">
P2: Culture mismatch: `Read` converts the enum value to a string using `InvariantCulture`, but `FromStringOrDefault` compares against `(int).ToString()` which uses the current culture. In cultures with non‑Latin digits/custom signs, valid values won't match and deserialization will throw `JsonException`.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs:107">
P2: Invariant-culture string conversion is compared to current-culture integer strings, so enum parsing can fail under non-default cultures and throw JsonException for valid values.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs:108">
P3: Invariant-culture formatting is compared against current-culture string literals in FromStringOrDefault, so deserialization can fail in cultures with non-Western digits or a different negative sign. Consider comparing integer values directly or using invariant culture in FromStringOrDefault.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/csharp/modelEnum.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/csharp/modelEnum.mustache:158">
P2: Integer enum deserialization uses InvariantCulture for the JSON number string but compares against enum values using culture-sensitive ToString(), which can fail in locales with non‑Latin digits or different number formatting, causing JsonException during deserialization.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumIntegerOnly.cs:107">
P2: InvariantCulture formatting for rawValue is compared against current-culture strings in FromStringOrDefault, which can mis-match in cultures with different NegativeSign/native digits, causing deserialization failures.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs:118">
P2: InvariantCulture string conversion mismatches CurrentCulture comparisons in FromStringOrDefault, causing valid enum values to fail deserialization in locales with localized digits.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/NullReferenceTypes/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:120">
P2: InvariantCulture string conversion in the converter mismatches the culture-sensitive comparisons in FromStringOrDefault, so valid enum values can fail to deserialize in non-Western locales.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs:107">
P2: Invariant-culture formatting in the new Read method mismatches FromStringOrDefault’s current-culture comparisons, so valid numeric enum values can fail to deserialize in non-invariant locales.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs:107">
P2: InvariantCulture string conversion is compared against CurrentCulture string values in FromStringOrDefault, which can cause valid enum values to fail deserialization in non-English locales.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs:121">
P2: InvariantCulture string conversion can fail to match FromStringOrDefault’s CurrentCulture comparisons, causing valid JSON integers to throw JsonException in non‑Latin cultures.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs:107">
P2: InvariantCulture is used to format the JSON number, but FromStringOrDefault compares against current-culture ToString() results, so deserialization can fail in cultures with non‑Latin digits or different negative signs. Use a consistent culture (e.g., invariant) on both sides.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs:107">
P2: Invariant-culture string conversion is compared against current-culture numeric strings, so enum deserialization fails in non-English locales with different digit shapes.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumInteger.cs:107">
P2: Invariant-culture string is compared to CurrentCulture enum strings, so deserialization can fail in locales with localized digits/negative sign. Use a consistent culture for both sides.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs:118">
P2: Invariant-culture string conversion is compared against current-culture strings in FromStringOrDefault, causing valid integer enum values to fail in locales with non-ASCII digits and throw JsonException.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs:107">
P2: Invariant-culture string conversion is compared against current-culture `ToString()` values, which can reject valid JSON integers in non‑invariant cultures and adds unnecessary string conversions.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/standard2.0/Petstore/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs:118">
P2: InvariantCulture string conversion in Read can fail to match CurrentCulture-based comparisons in FromStringOrDefault, causing enum deserialization to throw in locales with non-Latin digits.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/Petstore/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:118">
P2: Enum deserialization uses InvariantCulture to stringify the integer but compares against `ToString()` with current culture in `FromStringOrDefault`, so in cultures with localized digits the comparison fails and the new code throws `JsonException`. This is a real culture-dependent bug introduced by the new invariant conversion.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNullableEnumIntegerOnly.cs:107">
P2: InvariantCulture conversion in Read is compared against current-culture strings in FromStringOrDefault, which can fail for negative values in locales with a different negative sign, causing valid JSON numbers to throw JsonException.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:118">
P2: Culture mismatch: Read() uses InvariantCulture to stringify the int, but FromStringOrDefault compares against CurrentCulture strings, so enums fail to deserialize in locales with non‑Latin digits.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs:107">
P2: InvariantCulture formatting in Read is compared against CurrentCulture formatting in FromStringOrDefault, so enum values can fail to deserialize under non‑US locales (e.g., cultures with non‑ASCII digits or different negative signs).</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs:107">
P2: Invariant-culture string conversion is compared to current-culture enum strings, causing valid integer enum values to fail to parse in non‑Latin digit cultures.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs:107">
P2: InvariantCulture conversion in deserialization doesn’t match the current-culture comparisons in `FromStringOrDefault`, which can cause negative enum values to fail to parse in locales with different negative sign/digit formatting.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/EnumTestEnumInteger.cs:107">
P2: InvariantCulture string conversion is compared against current-culture string values, so valid enum values can fail to deserialize in cultures with localized digits/negative signs.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/Petstore/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:118">
P2: Invariant-culture string conversion in Read conflicts with culture-sensitive comparisons in FromStringOrDefault, causing enum deserialization to fail under non-ASCII digit locales.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumIntegerOnly.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumIntegerOnly.cs:107">
P2: Invariant-culture formatting in Read is compared against CurrentCulture formatting in FromStringOrDefault, which can fail for valid values in non‑US locales and throw JsonException during deserialization.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs:118">
P2: InvariantCulture string conversion in deserialization is compared to CurrentCulture strings in FromStringOrDefault, which can reject valid integer enum values under non‑Latin cultures and throw JsonException. Avoid the string round‑trip or use numeric comparison.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs:107">
P2: Invariant-culture formatting in Read can fail to match FromStringOrDefault’s CurrentCulture comparisons, causing valid enum values to throw JsonException in non-ASCII cultures.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:118">
P2: InvariantCulture string conversion is compared against culture-dependent `int.ToString()` results, causing deserialization to fail in locales with non-ASCII digits (e.g., ar-SA).</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Model/OuterEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Model/OuterEnumInteger.cs:121">
P2: InvariantCulture is used to stringify the JSON integer, but FromStringOrDefault compares against CurrentCulture ToString() results. In cultures with non-Latin digits, this mismatch causes valid values to fail parsing and throws JsonException.</violation>
</file>

<file name="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs">

<violation number="1" location="samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs:107">
P2: Invariant-culture formatting in Read is compared against current-culture enum strings in FromStringOrDefault, which can fail for locales with non‑default digits/negative sign, causing valid enum values to deserialize as JsonException.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

? null
: TestEnumParametersEnumQueryIntegerParameterValueConverter.FromStringOrDefault(rawValue);

string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: InvariantCulture string conversion in Read can mismatch the CurrentCulture string comparisons in FromStringOrDefault, causing valid negative enum values (e.g., -2) to fail deserialization in some locales.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs, line 107:

<comment>InvariantCulture string conversion in Read can mismatch the CurrentCulture string comparisons in FromStringOrDefault, causing valid negative enum values (e.g., -2) to fail deserialization in some locales.</comment>

<file context>
@@ -104,9 +104,11 @@ public class TestEnumParametersEnumQueryIntegerParameterJsonConverter : JsonConv
-            int rawValue = reader.GetInt32();
-            TestEnumParametersEnumQueryIntegerParameter result = (TestEnumParametersEnumQueryIntegerParameter)rawValue;
-            return result;
+            string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
+            TestEnumParametersEnumQueryIntegerParameter? result = TestEnumParametersEnumQueryIntegerParameterValueConverter.FromStringOrDefault(rawValue);
+            if (result != null)
</file context>
Fix with Cubic

? null
: OuterEnumIntegerValueConverter.FromStringOrDefault(rawValue);

string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: InvariantCulture conversion in Read can mismatch FromStringOrDefault’s current-culture comparisons, causing valid numeric enums to deserialize as null/JsonException in locales with non-ASCII digits.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/net9/SourceGeneration/src/Org.OpenAPITools/Model/OuterEnumInteger.cs, line 121:

<comment>InvariantCulture conversion in Read can mismatch FromStringOrDefault’s current-culture comparisons, causing valid numeric enums to deserialize as null/JsonException in locales with non-ASCII digits.</comment>

<file context>
@@ -118,9 +118,11 @@ public class OuterEnumIntegerJsonConverter : JsonConverter<OuterEnumInteger>
-            int rawValue = reader.GetInt32();
-            OuterEnumInteger result = (OuterEnumInteger)rawValue;
-            return result;
+            string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
+            OuterEnumInteger? result = OuterEnumIntegerValueConverter.FromStringOrDefault(rawValue);
+            if (result != null)
</file context>
Suggested change
string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
string rawValue = reader.GetInt32().ToString();
Fix with Cubic

? null
: OuterEnumIntegerDefaultValueValueConverter.FromStringOrDefault(rawValue);

string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: InvariantCulture string conversion in Read mismatches culture‑dependent comparisons in FromStringOrDefault, so valid enum values can fail to deserialize in locales with non‑Western digits (returns null and throws JsonException).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs, line 118:

<comment>InvariantCulture string conversion in Read mismatches culture‑dependent comparisons in FromStringOrDefault, so valid enum values can fail to deserialize in locales with non‑Western digits (returns null and throws JsonException).</comment>

<file context>
@@ -115,9 +115,11 @@ public class OuterEnumIntegerDefaultValueJsonConverter : JsonConverter<OuterEnum
-            int rawValue = reader.GetInt32();
-            OuterEnumIntegerDefaultValue result = (OuterEnumIntegerDefaultValue)rawValue;
-            return result;
+            string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
+            OuterEnumIntegerDefaultValue? result = OuterEnumIntegerDefaultValueValueConverter.FromStringOrDefault(rawValue);
+            if (result != null)
</file context>
Fix with Cubic

? null
: OuterEnumIntegerDefaultValueValueConverter.FromStringOrDefault(rawValue);

string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Culture mismatch: Read converts the enum value to a string using InvariantCulture, but FromStringOrDefault compares against (int).ToString() which uses the current culture. In cultures with non‑Latin digits/custom signs, valid values won't match and deserialization will throw JsonException.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs, line 118:

<comment>Culture mismatch: `Read` converts the enum value to a string using `InvariantCulture`, but `FromStringOrDefault` compares against `(int).ToString()` which uses the current culture. In cultures with non‑Latin digits/custom signs, valid values won't match and deserialization will throw `JsonException`.</comment>

<file context>
@@ -115,9 +115,11 @@ public class OuterEnumIntegerDefaultValueJsonConverter : JsonConverter<OuterEnum
-            int rawValue = reader.GetInt32();
-            OuterEnumIntegerDefaultValue result = (OuterEnumIntegerDefaultValue)rawValue;
-            return result;
+            string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
+            OuterEnumIntegerDefaultValue? result = OuterEnumIntegerDefaultValueValueConverter.FromStringOrDefault(rawValue);
+            if (result != null)
</file context>
Fix with Cubic

? null
: RequiredClassRequiredNotnullableEnumIntegerValueConverter.FromStringOrDefault(rawValue);

string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Invariant-culture string conversion is compared to current-culture integer strings, so enum parsing can fail under non-default cultures and throw JsonException for valid values.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/net8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs, line 107:

<comment>Invariant-culture string conversion is compared to current-culture integer strings, so enum parsing can fail under non-default cultures and throw JsonException for valid values.</comment>

<file context>
@@ -104,9 +104,11 @@ public class RequiredClassRequiredNotnullableEnumIntegerJsonConverter : JsonConv
-            int rawValue = reader.GetInt32();
-            RequiredClassRequiredNotnullableEnumInteger result = (RequiredClassRequiredNotnullableEnumInteger)rawValue;
-            return result;
+            string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
+            RequiredClassRequiredNotnullableEnumInteger? result = RequiredClassRequiredNotnullableEnumIntegerValueConverter.FromStringOrDefault(rawValue);
+            if (result != null)
</file context>
Fix with Cubic

? null
: TestEnumParametersEnumQueryIntegerParameterValueConverter.FromStringOrDefault(rawValue);

string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Invariant-culture formatting in Read can fail to match FromStringOrDefault’s CurrentCulture comparisons, causing valid enum values to throw JsonException in non-ASCII cultures.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/net4.7/FormModels/src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs, line 107:

<comment>Invariant-culture formatting in Read can fail to match FromStringOrDefault’s CurrentCulture comparisons, causing valid enum values to throw JsonException in non-ASCII cultures.</comment>

<file context>
@@ -104,9 +104,11 @@ public class TestEnumParametersEnumQueryIntegerParameterJsonConverter : JsonConv
-            int rawValue = reader.GetInt32();
-            TestEnumParametersEnumQueryIntegerParameter result = (TestEnumParametersEnumQueryIntegerParameter)rawValue;
-            return result;
+            string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
+            TestEnumParametersEnumQueryIntegerParameter? result = TestEnumParametersEnumQueryIntegerParameterValueConverter.FromStringOrDefault(rawValue);
+            if (result != null)
</file context>
Suggested change
string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
string rawValue = reader.GetInt32().ToString();
Fix with Cubic

? null
: OuterEnumIntegerValueConverter.FromStringOrDefault(rawValue);

string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: InvariantCulture string conversion is compared against culture-dependent int.ToString() results, causing deserialization to fail in locales with non-ASCII digits (e.g., ar-SA).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/net4.8/Petstore/src/Org.OpenAPITools/Model/OuterEnumInteger.cs, line 118:

<comment>InvariantCulture string conversion is compared against culture-dependent `int.ToString()` results, causing deserialization to fail in locales with non-ASCII digits (e.g., ar-SA).</comment>

<file context>
@@ -115,9 +115,11 @@ public class OuterEnumIntegerJsonConverter : JsonConverter<OuterEnumInteger>
-            int rawValue = reader.GetInt32();
-            OuterEnumInteger result = (OuterEnumInteger)rawValue;
-            return result;
+            string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
+            OuterEnumInteger? result = OuterEnumIntegerValueConverter.FromStringOrDefault(rawValue);
+            if (result != null)
</file context>
Fix with Cubic

? null
: OuterEnumIntegerValueConverter.FromStringOrDefault(rawValue);

string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: InvariantCulture is used to stringify the JSON integer, but FromStringOrDefault compares against CurrentCulture ToString() results. In cultures with non-Latin digits, this mismatch causes valid values to fail parsing and throws JsonException.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/net10/SourceGeneration/src/Org.OpenAPITools/Model/OuterEnumInteger.cs, line 121:

<comment>InvariantCulture is used to stringify the JSON integer, but FromStringOrDefault compares against CurrentCulture ToString() results. In cultures with non-Latin digits, this mismatch causes valid values to fail parsing and throws JsonException.</comment>

<file context>
@@ -118,9 +118,11 @@ public class OuterEnumIntegerJsonConverter : JsonConverter<OuterEnumInteger>
-            int rawValue = reader.GetInt32();
-            OuterEnumInteger result = (OuterEnumInteger)rawValue;
-            return result;
+            string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
+            OuterEnumInteger? result = OuterEnumIntegerValueConverter.FromStringOrDefault(rawValue);
+            if (result != null)
</file context>
Fix with Cubic

? null
: RequiredClassRequiredNotnullableEnumIntegerValueConverter.FromStringOrDefault(rawValue);

string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Invariant-culture formatting in Read is compared against current-culture enum strings in FromStringOrDefault, which can fail for locales with non‑default digits/negative sign, causing valid enum values to deserialize as JsonException.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/net9/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs, line 107:

<comment>Invariant-culture formatting in Read is compared against current-culture enum strings in FromStringOrDefault, which can fail for locales with non‑default digits/negative sign, causing valid enum values to deserialize as JsonException.</comment>

<file context>
@@ -104,9 +104,11 @@ public class RequiredClassRequiredNotnullableEnumIntegerJsonConverter : JsonConv
-            int rawValue = reader.GetInt32();
-            RequiredClassRequiredNotnullableEnumInteger result = (RequiredClassRequiredNotnullableEnumInteger)rawValue;
-            return result;
+            string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
+            RequiredClassRequiredNotnullableEnumInteger? result = RequiredClassRequiredNotnullableEnumIntegerValueConverter.FromStringOrDefault(rawValue);
+            if (result != null)
</file context>
Fix with Cubic

: RequiredClassRequiredNotnullableEnumIntegerValueConverter.FromStringOrDefault(rawValue);

string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
RequiredClassRequiredNotnullableEnumInteger? result = RequiredClassRequiredNotnullableEnumIntegerValueConverter.FromStringOrDefault(rawValue);
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Invariant-culture formatting is compared against current-culture string literals in FromStringOrDefault, so deserialization can fail in cultures with non-Western digits or a different negative sign. Consider comparing integer values directly or using invariant culture in FromStringOrDefault.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/net4.8/FormModels/src/Org.OpenAPITools/Model/RequiredClassRequiredNotnullableEnumInteger.cs, line 108:

<comment>Invariant-culture formatting is compared against current-culture string literals in FromStringOrDefault, so deserialization can fail in cultures with non-Western digits or a different negative sign. Consider comparing integer values directly or using invariant culture in FromStringOrDefault.</comment>

<file context>
@@ -104,9 +104,11 @@ public class RequiredClassRequiredNotnullableEnumIntegerJsonConverter : JsonConv
-            RequiredClassRequiredNotnullableEnumInteger result = (RequiredClassRequiredNotnullableEnumInteger)rawValue;
-            return result;
+            string rawValue = reader.GetInt32().ToString(System.Globalization.CultureInfo.InvariantCulture);
+            RequiredClassRequiredNotnullableEnumInteger? result = RequiredClassRequiredNotnullableEnumIntegerValueConverter.FromStringOrDefault(rawValue);
+            if (result != null)
+                return result.Value;
</file context>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][CSHARP] Enums are always generated as strings, even if type is integer

2 participants