fix(csharp): register the generic string enum converter last in generichost
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
testGenericHostRegistersGenericStringEnumConverterLastasserting the generated per-enum converters appear beforenew JsonStringEnumConverter()in the generatedHostConfiguration.cs(33 tests inCSharpClientCodegenTest, 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.