fix(csharp): make generated Serialize/Converter classes partial#3022
Merged
Conversation
Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
quicktype's C# generator emits data classes (e.g.
Something) aspublic partial class, but the generatedSerializeandConverterhelper classes were emitted as plainpublic static class/internal static class— missing thepartialkeyword.This matters because a common workflow generates quicktype output for multiple JSON samples into the same
--namespaceas separate files (e.g. running quicktype once per sample, all sharing--namespace QuickType). Each generated file redefinesSerializeandConverter; withoutpartial, C# fails to compile with duplicate-type-definition errors, even though the data classes themselves compile fine because they already usepartial.Root cause
In both
NewtonSoftCSharpRenderer.tsandSystemTextJsonCSharpRenderer.ts,emitSerializeClassandemitConverterClasscalledthis.emitType(..., "static class", ...)with the literal string"static class", instead of"static partial class"like the data-class emission path uses.The fix
Changed the
"static class"literal to"static partial class"in both renderers'emitSerializeClass(producesSerialize) andemitConverterClass(producesConverter) methods — 4 one-line changes total, matching how data classes already getpartial.Test coverage
test/unit/csharp-partial-helpers.test.ts: generates C# for both the NewtonSoft and SystemTextJson frameworks and asserts the output containspublic static partial class Serializeandinternal static partial class Converter. Verified this test fails against the pre-fix code and passes after the fix.test/fixtures/csharp/Issue1520.csandtest/fixtures/csharp-SystemTextJson/Issue1520.cs: added to the C# driver project directories (copied into every C# fixture test run, since the.csprojglobs all.csfiles). Each declares emptypublic static partial class Serialize { }/internal static partial class Converter { }stubs in theQuickTypenamespace, simulating a second generated file sharing the namespace. If the generatedSerialize/Converterclasses ever regress to non-partial, every C# JSON/schema fixture test will fail to compile with a "missing partial modifier" error, giving durable end-to-end coverage of this exact bug (not just a single named fixture).Verification performed locally
npm run buildpasses with no TypeScript errors.node dist/index.js --lang cs --namespace QuickType something.json, both frameworks) and confirmed the generated output now readspublic static partial class Serializeandinternal static partial class Converter.npx vitest run test/unit/csharp-partial-helpers.test.ts) — passes on the fix, and confirmed it fails (by stashing the renderer changes, rebuilding, and re-running) against the unfixed code.dotnettoolchain is available in this environment, so the C# fixture suite (which compiles/runs the generated + driver.csfiles) could not be executed locally; CI will exerciseFIXTURE=csharp/FIXTURE=csharp-SystemTextJsonand the schema variants, which will compile the newIssue1520.csfiles alongside every generated sample.Fixes #1520
🤖 Generated with Claude Code