Skip to content

fix(csharp): register the generic string enum converter last in generichost - #25702

Open
Inf1mum wants to merge 1 commit into
OpenAPITools:masterfrom
Inf1mum:fix/25206-generichost-enum-converter-order
Open

Inf1mum wants to merge 1 commit into
OpenAPITools:masterfrom
Inf1mum:fix/25206-generichost-enum-converter-order

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

In the C# generichost client, HostConfiguration registered the generic JsonStringEnumConverter before the generated schema-specific enum converters. JsonStringEnumConverter.CanConvert matches every enum type and System.Text.Json uses the first matching converter registered in JsonSerializerOptions.Converters, so the generated XJsonConverter/XNullableJsonConverter converters were never selected for standalone enums or enum arrays. Integer enum arrays were serialized as C# member names and string enum arrays whose wire values differ from the member names violated the schema.

Fixes #25206

Fix

Register the generic JsonStringEnumConverter after the generated per-schema converters, so specific converters take precedence and the generic one still covers enums without a generated converter. This is the same mechanism as the workaround verified in the issue (removing and re-adding the generic converter to move it last), now applied at the template level.

Related: #21393 reports the same converter registration order (this fix addresses its root cause), and #22917 previously corrected the generated numeric enum converters' read/write implementation, which the ordering problem prevented from being selected for array elements.

Tests

  • Added testGenericHostRegistersGenericStringEnumConverterLast asserting the generated per-enum converters appear before new JsonStringEnumConverter() in the generated HostConfiguration.cs (33 tests in CSharpClientCodegenTest, 0 failures).
  • Regenerated all csharp-generichost samples (51 configs); the only generated change is the moved registration with a short comment.

PR checklist

  • Read the contribution guidelines.
  • Ran the relevant tests locally.
  • Filed the PR against the correct branch: master.

Summary by cubic

Fixes the C# generichost client's enum serialization by registering the generic JsonStringEnumConverter after the generated schema-specific converters, so the generated converters are used for enums and enum arrays. Previously the generic converter shadowed them, causing enum arrays and standalone enums to serialize with C# member names instead of the wire values defined by the schema. Also adds a regression test asserting the registration order and regenerates the affected samples.

Written for commit c9ebf04. Summary will update on new commits.

View guided diff

JsonStringEnumConverter matches every enum type and System.Text.Json
uses the first matching converter registered in
JsonSerializerOptions.Converters, so registering it before the
generated schema-specific enum converters shadowed them. Enum arrays
and standalone enums were serialized with C# member names instead of
the wire values declared by the schema.

Register the generic converter after the generated per-schema
converters, add a generator regression test asserting the order, and
regenerate the csharp-generichost samples.

Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 53 files

View guided diff | Re-trigger cubic

@wing328

wing328 commented Nov 16, 2026

Copy link
Copy Markdown
Member

thanks for the PR

cc @devhl-labs

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][C#][generichost] Generic enum converter overrides schema-specific converters for arrays

2 participants