Use NSwag's built-in System.Text.Json polymorphic serialization#772
Conversation
WalkthroughRefactors the template factory to a single-parameter Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller as Caller
participant Factory as CSharpClientGeneratorFactory
participant TFactory as CustomTemplateFactory
participant Base as Embedded Template Provider
participant Gen as CSharpClientGenerator
Caller->>Factory: Create generator(document, settings)
Factory->>Factory: Determine JsonPolymorphicSerializationStyle
Factory->>TFactory: Instantiate with settings
Gen->>TFactory: Request template "Class"
TFactory->>Base: Get embedded "Class" template
Base-->>TFactory: Return base template
TFactory->>TFactory: Inject JsonPolymorphic flags into "Class" template
TFactory-->>Gen: Return processed template
Gen-->>Caller: Generate client & DTOs (polymorphic converters/templates removed)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (5)
src/Refitter.SourceGenerator/Refitter.SourceGenerator.csproj (1)
33-34: Remove stale EmbeddedResource for Templates/*.liquid.
These templates appear to be removed/unused after switching to NSwag’s built-in STJ polymorphism. Keeping this block may package nothing or confuse future maintainers.Apply:
- <ItemGroup> - <EmbeddedResource Include="../Refitter.Core/Templates/*.liquid" LinkBase="Templates" /> - </ItemGroup>src/Refitter.Core/CustomCSharpClientGenerator.cs (1)
10-11: Prefer explicit base call for clarity and future-proofing.
Qualifying the call avoids any accidental recursion if overloads change.- internal CSharpOperationModel CreateOperationModel(OpenApiOperation operation) => - CreateOperationModel(operation, Settings); + internal CSharpOperationModel CreateOperationModel(OpenApiOperation operation) => + base.CreateOperationModel(operation, Settings);src/Refitter.Core/CSharpClientGeneratorFactory.cs (3)
50-50: Avoid overriding a user-provided TemplateFactory and gate to STJ-only.If a user supplies a TemplateFactory via
settings.CodeGeneratorSettings,MapCSharpGeneratorSettingscan overwrite this assignment. Also, post-processing is only needed for STJ style.- csharpClientGeneratorSettings.CSharpGeneratorSettings.TemplateFactory = new CustomTemplateFactory(csharpClientGeneratorSettings.CSharpGeneratorSettings); + if (csharpClientGeneratorSettings.CSharpGeneratorSettings.JsonPolymorphicSerializationStyle + == CSharpJsonPolymorphicSerializationStyle.SystemTextJson + && csharpClientGeneratorSettings.CSharpGeneratorSettings.TemplateFactory is null) + { + csharpClientGeneratorSettings.CSharpGeneratorSettings.TemplateFactory = + new CustomTemplateFactory(csharpClientGeneratorSettings.CSharpGeneratorSettings); + }Confirm whether
MapCSharpGeneratorSettings(...)can overwrite this; if yes, consider setting the factory after the mapping step or warning when a custom factory is supplied.
99-101: Doc: note STJ version requirement and future-removal condition.Consider adding that this tweak requires STJ’s polymorphism (net7+) and is temporary until NSwag exposes
UnknownDerivedTypeHandlingandIgnoreUnrecognizedTypeDiscriminatorsas settings.
104-108: Use array literal instead of C# 12 collection expression for wider compatibility
No<LangVersion>is set andRefitter.Coretargetsnetstandard2.0, so builds may use C# versions < 12. Replace the C# 12 collection expression with a traditional array literal, or alternatively pin to C# 12 via<LangVersion>12.- : base(settings, [typeof(CSharpGenerator).Assembly, typeof(CSharpGeneratorBaseSettings).Assembly]) + : base(settings, new[] { typeof(CSharpGenerator).Assembly, typeof(CSharpGeneratorBaseSettings).Assembly })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (6)
src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/Refitter.g.csis excluded by!**/generated/**src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreOptionalParameters.g.csis excluded by!**/generated/**src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreSingleInterfaceWithHttpResilience.g.csis excluded by!**/generated/**src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreSingleInterfaceWithPolly.g.csis excluded by!**/generated/**src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/UseJsonInheritanceConverter.g.csis excluded by!**/generated/**src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/UsePolymorphicSerialization.g.csis excluded by!**/generated/**
📒 Files selected for processing (7)
src/Refitter.Core/CSharpClientGeneratorFactory.cs(3 hunks)src/Refitter.Core/CustomCSharpClientGenerator.cs(1 hunks)src/Refitter.Core/Refitter.Core.csproj(1 hunks)src/Refitter.Core/Templates/Class.liquid(0 hunks)src/Refitter.Core/Templates/JsonInheritanceAttribute.liquid(0 hunks)src/Refitter.Core/Templates/JsonInheritanceConverter.liquid(0 hunks)src/Refitter.SourceGenerator/Refitter.SourceGenerator.csproj(1 hunks)
💤 Files with no reviewable changes (3)
- src/Refitter.Core/Templates/Class.liquid
- src/Refitter.Core/Templates/JsonInheritanceConverter.liquid
- src/Refitter.Core/Templates/JsonInheritanceAttribute.liquid
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.cs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
src/**/*.cs: Follow existing C# coding conventions defined in .editorconfig
Use PascalCase for public members
Use camelCase for parameters and local variables
Include XML documentation for public APIs
Use meaningful variable and method names
Files:
src/Refitter.Core/CSharpClientGeneratorFactory.cssrc/Refitter.Core/CustomCSharpClientGenerator.cs
🧠 Learnings (2)
📚 Learning: 2025-09-17T20:15:55.708Z
Learnt from: CR
PR: christianhelle/refitter#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-17T20:15:55.708Z
Learning: Applies to src/Refitter.Core/Settings/RefitGeneratorSettings.cs : Add corresponding property to src/Refitter.Core/Settings/RefitGeneratorSettings.cs for new CLI options
Applied to files:
src/Refitter.Core/CSharpClientGeneratorFactory.cs
📚 Learning: 2025-09-17T20:15:55.708Z
Learnt from: CR
PR: christianhelle/refitter#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-17T20:15:55.708Z
Learning: Applies to src/Refitter.Core/RefitInterfaceGenerator.cs : Implement generation logic for new options in src/Refitter.Core/RefitInterfaceGenerator.cs (or related generator classes)
Applied to files:
src/Refitter.Core/CSharpClientGeneratorFactory.cssrc/Refitter.Core/CustomCSharpClientGenerator.cs
🧬 Code graph analysis (2)
src/Refitter.Core/CSharpClientGeneratorFactory.cs (1)
src/Refitter.Core/CustomCSharpClientGenerator.cs (1)
CustomCSharpClientGenerator(7-12)
src/Refitter.Core/CustomCSharpClientGenerator.cs (1)
src/Refitter.Core/CSharpClientGeneratorFactory.cs (1)
CustomCSharpClientGenerator(11-61)
🔇 Additional comments (5)
src/Refitter.Core/Refitter.Core.csproj (1)
15-16: All NSwag references are now 14.6.0 in both Core and SourceGenerator csproj files. No older versions detected.src/Refitter.Core/CustomCSharpClientGenerator.cs (1)
7-9: Confirm SDK supports C# 12 primary constructors or revert to an explicit ctor. Noglobal.jsonor<LangVersion>was found, so the default SDK controls the C# version—ensure your CI uses an SDK with C# 12 support or replace the primary‐constructor syntax with a classic constructor.src/Refitter.SourceGenerator/Refitter.SourceGenerator.csproj (1)
19-20: All NSwag package references are consistently updated to 14.6.0 across Refitter.Core and Refitter.SourceGenerator; no stale Template EmbeddedResource entries remain.src/Refitter.Core/CSharpClientGeneratorFactory.cs (2)
54-54: LGTM on generator wiring.Constructor usage aligns with the simplified
CustomCSharpClientGeneratorsignature.
32-32: Polymorphism style gate is correct. CLI targets net8.0/net9.0, so System.Text.Json-based polymorphic attributes are available at runtime, and the project references NSwag.CodeGeneration.CSharp 14.6.0, which includes the JsonPolymorphicSerializationStyle enum. No changes needed.
| /// <inheritdoc /> | ||
| protected override string GetEmbeddedLiquidTemplate(string language, string template) | ||
| { | ||
| template = template.TrimEnd('!'); | ||
| var assembly = Assembly.GetExecutingAssembly(); // this code is running in Refitter.Core and Refitter.SourceGenerator | ||
| var resourceName = $"{assembly.GetName().Name}.Templates.{template}.liquid"; | ||
|
|
||
| var resource = assembly.GetManifestResourceStream(resourceName); | ||
| if (resource != null) | ||
| var templateText = base.GetEmbeddedLiquidTemplate(language, template); | ||
| return template switch | ||
| { | ||
| using (var reader = new StreamReader(resource)) | ||
| { | ||
| return reader.ReadToEnd(); | ||
| } | ||
| } | ||
|
|
||
| return base.GetEmbeddedLiquidTemplate(language, template); | ||
| "Class" => templateText | ||
| .Replace( | ||
| "[System.Text.Json.Serialization.JsonPolymorphic(TypeDiscriminatorPropertyName = \"{{ Discriminator }}\")]", | ||
| "[System.Text.Json.Serialization.JsonPolymorphic(TypeDiscriminatorPropertyName = \"{{ Discriminator }}\", UnknownDerivedTypeHandling = System.Text.Json.Serialization.JsonUnknownDerivedTypeHandling.FallBackToBaseType, IgnoreUnrecognizedTypeDiscriminators = true)]") | ||
| _ => templateText, | ||
| }; | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Template patch is brittle to upstream formatting changes; make it resilient and idempotent.
Exact Replace(...) can silently fail if NSwag alters spacing/ordering, undermining the PR’s goal to ease future upgrades. Use a regex that:
- Detects
[JsonPolymorphic(...)]regardless of whitespace/arg order, - Adds the two arguments only if missing.
- protected override string GetEmbeddedLiquidTemplate(string language, string template)
- {
- var templateText = base.GetEmbeddedLiquidTemplate(language, template);
- return template switch
- {
- "Class" => templateText
- .Replace(
- "[System.Text.Json.Serialization.JsonPolymorphic(TypeDiscriminatorPropertyName = \"{{ Discriminator }}\")]",
- "[System.Text.Json.Serialization.JsonPolymorphic(TypeDiscriminatorPropertyName = \"{{ Discriminator }}\", UnknownDerivedTypeHandling = System.Text.Json.Serialization.JsonUnknownDerivedTypeHandling.FallBackToBaseType, IgnoreUnrecognizedTypeDiscriminators = true)]")
- _ => templateText,
- };
- }
+ protected override string GetEmbeddedLiquidTemplate(string language, string template)
+ {
+ var text = base.GetEmbeddedLiquidTemplate(language, template);
+ if (!string.Equals(template, "Class", StringComparison.Ordinal))
+ return text;
+
+ // Patch [JsonPolymorphic(...)] robustly
+ const string pattern = @"\[\s*System\.Text\.Json\.Serialization\.JsonPolymorphic\s*\((?<args>[^)]*)\)\s*\]";
+ return System.Text.RegularExpressions.Regex.Replace(text, pattern, m =>
+ {
+ var args = m.Groups["args"].Value;
+ // Idempotent: if either arg already present, do nothing
+ if (args.Contains("UnknownDerivedTypeHandling") || args.Contains("IgnoreUnrecognizedTypeDiscriminators"))
+ return m.Value;
+
+ var insert = string.IsNullOrWhiteSpace(args) ? string.Empty : args.Trim() + ", ";
+ insert += "UnknownDerivedTypeHandling = System.Text.Json.Serialization.JsonUnknownDerivedTypeHandling.FallBackToBaseType, IgnoreUnrecognizedTypeDiscriminators = true";
+ return $"[System.Text.Json.Serialization.JsonPolymorphic({insert})]";
+ });
+ }Add once at the top of the file:
using System.Text.RegularExpressions;- Confirm the enum member spelling in STJ (Fallback vs. FallBack).
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/Refitter.Core/CSharpClientGeneratorFactory.cs (1)
50-51: Gate the template patch to when STJ polymorphism is enabled.Avoid touching templates when
UsePolymorphicSerialization == false. SetTemplateFactoryonly in that case.- csharpClientGeneratorSettings.CSharpGeneratorSettings.TemplateFactory = new CustomTemplateFactory(csharpClientGeneratorSettings.CSharpGeneratorSettings); + if (settings.UsePolymorphicSerialization) + { + csharpClientGeneratorSettings.CSharpGeneratorSettings.TemplateFactory = + new CustomTemplateFactory(csharpClientGeneratorSettings.CSharpGeneratorSettings); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
src/Refitter.Core/CSharpClientGeneratorFactory.cs(3 hunks)src/Refitter.Core/CustomCSharpClientGenerator.cs(1 hunks)src/Refitter.Core/Refitter.Core.csproj(1 hunks)src/Refitter.Core/Templates/Class.liquid(0 hunks)src/Refitter.Core/Templates/JsonInheritanceAttribute.liquid(0 hunks)src/Refitter.Core/Templates/JsonInheritanceConverter.liquid(0 hunks)src/Refitter.SourceGenerator/Refitter.SourceGenerator.csproj(1 hunks)
💤 Files with no reviewable changes (3)
- src/Refitter.Core/Templates/JsonInheritanceConverter.liquid
- src/Refitter.Core/Templates/JsonInheritanceAttribute.liquid
- src/Refitter.Core/Templates/Class.liquid
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.cs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
src/**/*.cs: Follow existing C# coding conventions defined in .editorconfig
Use PascalCase for public members
Use camelCase for parameters and local variables
Include XML documentation for public APIs
Use meaningful variable and method names
Files:
src/Refitter.Core/CSharpClientGeneratorFactory.cssrc/Refitter.Core/CustomCSharpClientGenerator.cs
🧠 Learnings (2)
📚 Learning: 2025-09-17T20:15:55.708Z
Learnt from: CR
PR: christianhelle/refitter#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-17T20:15:55.708Z
Learning: Applies to src/Refitter.Core/Settings/RefitGeneratorSettings.cs : Add corresponding property to src/Refitter.Core/Settings/RefitGeneratorSettings.cs for new CLI options
Applied to files:
src/Refitter.Core/CSharpClientGeneratorFactory.cs
📚 Learning: 2025-09-17T20:15:55.708Z
Learnt from: CR
PR: christianhelle/refitter#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-17T20:15:55.708Z
Learning: Applies to src/Refitter.Core/RefitInterfaceGenerator.cs : Implement generation logic for new options in src/Refitter.Core/RefitInterfaceGenerator.cs (or related generator classes)
Applied to files:
src/Refitter.Core/CSharpClientGeneratorFactory.cssrc/Refitter.Core/CustomCSharpClientGenerator.cs
🧬 Code graph analysis (2)
src/Refitter.Core/CSharpClientGeneratorFactory.cs (1)
src/Refitter.Core/CustomCSharpClientGenerator.cs (1)
CustomCSharpClientGenerator(7-12)
src/Refitter.Core/CustomCSharpClientGenerator.cs (2)
src/Refitter.Core/CSharpClientGeneratorFactory.cs (1)
CustomCSharpClientGenerator(11-61)src/Refitter/Settings.cs (1)
Settings(7-256)
🔇 Additional comments (7)
src/Refitter.Core/CSharpClientGeneratorFactory.cs (4)
32-32: Good: toggle built‑in STJ polymorphism via settings.Nice use of
JsonPolymorphicSerializationStyleto switch STJ/NJsonSchema based onUsePolymorphicSerialization.Please confirm this property name/API exists in 14.6.0 (build should catch if it moved/renamed).
97-101: Doc comment is clear and actionable.Keeping this as a temporary shim with a removal note is good hygiene.
114-122: Make the JsonPolymorphic patch resilient and idempotent (prior feedback).Exact
Replace(...)is brittle to whitespace/argument ordering changes in upstream templates. Prefer a Regex that adds the two arguments only if missing. Also keeps future NSwag upgrades safer.- return template switch - { - "Class" => templateText - .Replace( - "[System.Text.Json.Serialization.JsonPolymorphic(TypeDiscriminatorPropertyName = \"{{ Discriminator }}\")]", - "[System.Text.Json.Serialization.JsonPolymorphic(TypeDiscriminatorPropertyName = \"{{ Discriminator }}\", UnknownDerivedTypeHandling = System.Text.Json.Serialization.JsonUnknownDerivedTypeHandling.FallBackToBaseType, IgnoreUnrecognizedTypeDiscriminators = true)]") - _ => templateText, - }; + return template == "Class" + ? System.Text.RegularExpressions.Regex.Replace( + templateText, + @"\[\s*System\.Text\.Json\.Serialization\.JsonPolymorphic\s*\((?<args>[^)]*)\)\s*\]", + m => { + var args = m.Groups["args"].Value; + if (args.Contains("UnknownDerivedTypeHandling") || args.Contains("IgnoreUnrecognizedTypeDiscriminators")) + return m.Value; // idempotent + var insert = string.IsNullOrWhiteSpace(args) ? string.Empty : args.Trim() + ", "; + insert += "UnknownDerivedTypeHandling = System.Text.Json.Serialization.JsonUnknownDerivedTypeHandling.FallBackToBaseType, IgnoreUnrecognizedTypeDiscriminators = true"; + return $"[System.Text.Json.Serialization.JsonPolymorphic({insert})]"; + }) + : templateText;Add at file top if missing:
using System.Text.RegularExpressions;
107-108: Template assembly list is sufficient. NSwag’s embedded CSharp templates are covered by the currenttypeof(CSharpGenerator).Assemblyandtypeof(CSharpGeneratorBaseSettings).Assembly, andTemplateFactoryis correctly set inCSharpClientGeneratorFactory.cs. No additional assemblies needed.src/Refitter.SourceGenerator/Refitter.SourceGenerator.csproj (1)
19-20: Analyzer packaging path intact
Verified thatRefitter.SourceGenerator.csprojstill includes<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" …/>, ensuring the generator DLL is packed underanalyzers/dotnet/csas before.src/Refitter.Core/CustomCSharpClientGenerator.cs (1)
7-12: Verified no remaining 3-argument constructor calls. All instantiations of CustomCSharpClientGenerator use the updated two-parameter signature.src/Refitter.Core/Refitter.Core.csproj (1)
15-16: Verify NSwag 14.6.0 TFM compatibility and codegen outputEnsure NSwag.CodeGeneration.CSharp 14.6.0 ships
lib/netstandard2.0assets (inspect the nupkg) and that generated DTO code (JsonPolymorphic attributes, inheritance converters, discriminators) remains unchanged for your supported OpenAPI features.
With tweaks to the polymorphic serialization attribute * UnknownDerivedTypeHandling = System.Text.Json.Serialization.JsonUnknownDerivedTypeHandling.FallBackToBaseType * IgnoreUnrecognizedTypeDiscriminators = true
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/Refitter.Core/CSharpClientGeneratorFactory.cs (1)
104-108: Avoid C# 12 collection expressions
Replace the collection-expression syntax with an explicit array initializer to ensure compatibility with older compilers:- public CustomTemplateFactory(CodeGeneratorSettingsBase settings) - : base(settings, [typeof(CSharpGenerator).Assembly, typeof(CSharpGeneratorBaseSettings).Assembly]) + public CustomTemplateFactory(CodeGeneratorSettingsBase settings) + : base(settings, new[] { typeof(CSharpGenerator).Assembly, typeof(CSharpGeneratorBaseSettings).Assembly })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (5)
src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/Refitter.g.csis excluded by!**/generated/**src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreOptionalParameters.g.csis excluded by!**/generated/**src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreSingleInterfaceWithHttpResilience.g.csis excluded by!**/generated/**src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreSingleInterfaceWithPolly.g.csis excluded by!**/generated/**src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/UseJsonInheritanceConverter.g.csis excluded by!**/generated/**
📒 Files selected for processing (7)
src/Refitter.Core/CSharpClientGeneratorFactory.cs(3 hunks)src/Refitter.Core/CustomCSharpClientGenerator.cs(1 hunks)src/Refitter.Core/Refitter.Core.csproj(1 hunks)src/Refitter.Core/Templates/Class.liquid(0 hunks)src/Refitter.Core/Templates/JsonInheritanceAttribute.liquid(0 hunks)src/Refitter.Core/Templates/JsonInheritanceConverter.liquid(0 hunks)src/Refitter.SourceGenerator/Refitter.SourceGenerator.csproj(1 hunks)
💤 Files with no reviewable changes (3)
- src/Refitter.Core/Templates/JsonInheritanceAttribute.liquid
- src/Refitter.Core/Templates/JsonInheritanceConverter.liquid
- src/Refitter.Core/Templates/Class.liquid
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Refitter.SourceGenerator/Refitter.SourceGenerator.csproj
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.cs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
src/**/*.cs: Follow existing C# coding conventions defined in .editorconfig
Use PascalCase for public members
Use camelCase for parameters and local variables
Include XML documentation for public APIs
Use meaningful variable and method names
Files:
src/Refitter.Core/CSharpClientGeneratorFactory.cssrc/Refitter.Core/CustomCSharpClientGenerator.cs
🧠 Learnings (2)
📚 Learning: 2025-09-17T20:15:55.708Z
Learnt from: CR
PR: christianhelle/refitter#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-17T20:15:55.708Z
Learning: Applies to src/Refitter.Core/Settings/RefitGeneratorSettings.cs : Add corresponding property to src/Refitter.Core/Settings/RefitGeneratorSettings.cs for new CLI options
Applied to files:
src/Refitter.Core/CSharpClientGeneratorFactory.cs
📚 Learning: 2025-09-17T20:15:55.708Z
Learnt from: CR
PR: christianhelle/refitter#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-17T20:15:55.708Z
Learning: Applies to src/Refitter.Core/RefitInterfaceGenerator.cs : Implement generation logic for new options in src/Refitter.Core/RefitInterfaceGenerator.cs (or related generator classes)
Applied to files:
src/Refitter.Core/CSharpClientGeneratorFactory.cssrc/Refitter.Core/CustomCSharpClientGenerator.cs
🧬 Code graph analysis (2)
src/Refitter.Core/CSharpClientGeneratorFactory.cs (1)
src/Refitter.Core/CustomCSharpClientGenerator.cs (1)
CustomCSharpClientGenerator(7-12)
src/Refitter.Core/CustomCSharpClientGenerator.cs (2)
src/Refitter.Core/CSharpClientGeneratorFactory.cs (1)
CustomCSharpClientGenerator(11-61)src/Refitter/Settings.cs (1)
Settings(7-256)
🔇 Additional comments (5)
src/Refitter.Core/CSharpClientGeneratorFactory.cs (3)
32-32: Polymorphic style toggle: LGTM.Switching based on UsePolymorphicSerialization aligns with the PR goal. No change requested.
111-122: Make the JsonPolymorphic patch resilient and idempotent.Exact Replace() is brittle to upstream whitespace/arg-order changes and can silently fail. Use a Regex and only add args if missing.
+using System.Text.RegularExpressions; @@ - protected override string GetEmbeddedLiquidTemplate(string language, string template) - { - var templateText = base.GetEmbeddedLiquidTemplate(language, template); - return template switch - { - "Class" => templateText - .Replace( - "[System.Text.Json.Serialization.JsonPolymorphic(TypeDiscriminatorPropertyName = \"{{ Discriminator }}\")]", - "[System.Text.Json.Serialization.JsonPolymorphic(TypeDiscriminatorPropertyName = \"{{ Discriminator }}\", UnknownDerivedTypeHandling = System.Text.Json.Serialization.JsonUnknownDerivedTypeHandling.FallBackToBaseType, IgnoreUnrecognizedTypeDiscriminators = true)]"), - _ => templateText, - }; - } + protected override string GetEmbeddedLiquidTemplate(string language, string template) + { + var text = base.GetEmbeddedLiquidTemplate(language, template); + if (!string.Equals(template, "Class", StringComparison.Ordinal)) + return text; + + const string pattern = @"\[\s*System\.Text\.Json\.Serialization\.JsonPolymorphic\s*\((?<args>[^)]*)\)\s*\]"; + return Regex.Replace(text, pattern, m => + { + var args = m.Groups["args"].Value; + // Idempotent: if either argument already exists, return original + if (args.Contains("UnknownDerivedTypeHandling") || args.Contains("IgnoreUnrecognizedTypeDiscriminators")) + return m.Value; + var insert = string.IsNullOrWhiteSpace(args) ? string.Empty : args.Trim() + ", "; + insert += "UnknownDerivedTypeHandling = System.Text.Json.Serialization.JsonUnknownDerivedTypeHandling.FallBackToBaseType, IgnoreUnrecognizedTypeDiscriminators = true"; + return $"[System.Text.Json.Serialization.JsonPolymorphic({insert})]"; + }); + }Confirm: 1) Official docs for System.Text.Json.Serialization.JsonUnknownDerivedTypeHandling member spelling ("FallBackToBaseType"). 2) In which System.Text.Json version was JsonPolymorphicAttribute.IgnoreUnrecognizedTypeDiscriminators introduced? 3) Does NSwag 14.6.0’s "Class" template still emit [JsonPolymorphic(TypeDiscriminatorPropertyName = "{{ Discriminator }}")] exactly, or did formatting change?
50-50: Verify TemplateFactory coverageCustomTemplateFactory override is fine, but manually confirm it probes NSwag’s template assemblies (e.g., the “Class” template). If NSwag reorganizes templates, fall back to the base TemplateFactory defaults.
src/Refitter.Core/Refitter.Core.csproj (1)
15-16: NSwag 14.6.0 upgrade verified: no 14.4.x references remain across the solution.src/Refitter.Core/CustomCSharpClientGenerator.cs (1)
7-12: Confirm no boolean parameter in constructor calls
Allnew CustomCSharpClientGeneratorinvocations pass onlydocumentandsettings; the removed boolean argument is not used.
| /// solely for the purpose of tweaking the JsonPolymorphic attribute with UnknownDerivedTypeHandling = FallBackToBaseType and IgnoreUnrecognizedTypeDiscriminators = true | ||
| /// This class should be removed if NSwag eventually supports setting UnknownDerivedTypeHandling and IgnoreUnrecognizedTypeDiscriminators. | ||
| /// </summary> |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Doc comment intent is clear. Add a safety note about STJ version requirement.
Generated attributes with IgnoreUnrecognizedTypeDiscriminators may require STJ v8+. Consider documenting the minimum required STJ version to avoid consumer build breaks.
🌐 Web query:
Which minimum System.Text.Json package version exposes JsonPolymorphicAttribute.IgnoreUnrecognizedTypeDiscriminators?
💡 Result:
The property appears starting in System.Text.Json package version 9.0.0. [1][2]
Sources:
[1] Microsoft Docs — JsonPolymorphicAttribute.IgnoreUnrecognizedTypeDiscriminators (shows Package: System.Text.Json v9.0.0).
[2] Microsoft Docs — JsonPolymorphicAttribute class (includes the property).
Doc comment intent is clear. Document minimum STJ version. Generated attributes with IgnoreUnrecognizedTypeDiscriminators require System.Text.Json v9.0.0 or later; include this in the doc comment to prevent consumer build breaks. cite12
🤖 Prompt for AI Agents
In src/Refitter.Core/CSharpClientGeneratorFactory.cs around lines 99 to 101, the
XML doc comment describing why the helper class exists should also state the
minimum required System.Text.Json version; update the comment to mention that
generated attributes using IgnoreUnrecognizedTypeDiscriminators require
System.Text.Json v9.0.0 or later (or specify exact minimum supported version),
so consumers know to upgrade their STJ package to avoid build breaks.
|
@0xced thanks for taking the time to implement this. The changes look good to me and the tests pass so I'm ok with this That said, I never used this feature myself, and it was @ryanheath who drove the implementation of this feature. Are you ok with these changes @ryanheath ? |
|
@all-contributors please add @0xced for code |
|
I've put up a pull request to add @0xced! 🎉 |
Yes, changes looks great! |
Updated [refitter](https://github.com/christianhelle/refitter) from 1.4.0 to 1.7.0. <details> <summary>Release notes</summary> _Sourced from [refitter's releases](https://github.com/christianhelle/refitter/releases)._ ## 1.7.0 ## What's Changed * Fix Multipart file array support by @christianhelle in christianhelle/refitter#784 * Add option to remove `[JsonConverter(typeof(JsonStringEnumConverter))]` from generated contracts by @christianhelle in christianhelle/refitter#786 * Improve OpenAPI Description handling by @christianhelle in christianhelle/refitter#787 * Update Smoke Tests workflow trigger by @christianhelle in christianhelle/refitter#791 * Add support for customizing the default Integer format by @christianhelle in christianhelle/refitter#792 * NSwag v14.6.2 by @christianhelle in christianhelle/refitter#800 ## New Contributors: - @christophdebaene - @7amou3 - @HGCollier **Full Changelog**: christianhelle/refitter@1.6.5...1.7.0 ## 1.6.5 ## What's Changed * Do not remove colon from url paths, verify they're not present in operation names by @eoma-knowit in christianhelle/refitter#765 * Add ability to skip-validation + simplify Unicode logging by @david-pw in christianhelle/refitter#767 * Use NSwag's built-in System.Text.Json polymorphic serialization by @0xced in christianhelle/refitter#772 ## New Contributors * @eoma-knowit made their first contribution in christianhelle/refitter#765 * @david-pw made their first contribution in christianhelle/refitter#767 * @0xced made their first contribution in christianhelle/refitter#772 **Full Changelog**: christianhelle/refitter@1.6.4...1.6.5 ## 1.6.4 ## What's Changed * Fix SonarCloud maintainability issues - eliminate code duplication and improve code quality in christianhelle/refitter#753 * Update --operation-name-template implementation to replace all {operationName} instances with Execute by @christianhelle in christianhelle/refitter#759 **Full Changelog**: christianhelle/refitter@1.6.3...1.6.4 ## 1.6.3 ## What's Changed * Fix MSBuild task so that the generated code is included in the compilation by @christianhelle in christianhelle/refitter#745 * Add support for systems running only .NET 9.0 (without .NET 8.0) in Refitter.MSBuild by @christianhelle in christianhelle/refitter#746 * Introduce --simple-output CLI argument by @christianhelle in christianhelle/refitter#751 **Full Changelog**: christianhelle/refitter@1.6.2...1.6.3 ## 1.6.2 ## What's Changed * docs: add @SWarnberg as a contributor for bug by @allcontributors[bot] in christianhelle/refitter#714 * docs: add @lilinus as a contributor for bug by @allcontributors[bot] in christianhelle/refitter#717 * Fix missing namespace import by @christianhelle in christianhelle/refitter#718 * Fix match path on cmd prompt by @christianhelle in christianhelle/refitter#719 * Fix table alignments in CLI Output by @christianhelle in christianhelle/refitter#720 * NSwag v14.5.0 by @renovate[bot] in christianhelle/refitter#722 * Add comprehensive GitHub Copilot instructions for Refitter repository by @Copilot in christianhelle/refitter#725 * Bump actions/checkout from 4 to 5 by @dependabot[bot] in christianhelle/refitter#727 * chore(deps): update dependency polly to 8.6.2 by @renovate[bot] in christianhelle/refitter#716 * chore(deps): update dependency microsoft.extensions.http.resilience to 9.8.0 by @renovate[bot] in christianhelle/refitter#728 * ASCII Art Title by @christianhelle in christianhelle/refitter#729 **Full Changelog**: christianhelle/refitter@1.6.1...1.6.2 ## 1.6.1 ## What's Changed * Update dependency Refitter.SourceGenerator to 1.6.0 by @renovate in christianhelle/refitter#704 * Add console output screenshots to documentation by @christianhelle in christianhelle/refitter#705 * docs: add @sb-chericks as a contributor for ideas, and bug by @allcontributors in christianhelle/refitter#707 * chore(deps): update dependency xunit.runner.visualstudio to 3.1.1 by @renovate in christianhelle/refitter#708 * Ensure that Refit interfaces have a XML docs by @christianhelle in christianhelle/refitter#709 **Full Changelog**: christianhelle/refitter@1.6.0...1.6.1 ## 1.6.0 **Implemented enhancements:** - fix missing schema for dictionary keys [\#697](christianhelle/refitter#697) @kirides - Fancy CLI output using Spectre Console [\#695](christianhelle/refitter#695) @christianhelle **Fixed bugs:** - \[Bug\] Refitter generates invalid \[Range\] attribute for decimal properties starting from v1.5.2 [\#668](christianhelle/refitter#668) @tommieemeli - Generates Content-Type: multipart/form-data Header which breaks Multipart uploads [\#654](christianhelle/refitter#654) @dbhjoh @jaroslaw-dutka **Closed issues:** - Improve documentation [\#700](christianhelle/refitter#700) **Merged pull requests:** - Update dependency Polly to 8.6.1 [\#703](christianhelle/refitter#703) ([renovate[bot]](https://github.com/apps/renovate)) - Update dependency Swashbuckle.AspNetCore to v9 [\#702](christianhelle/refitter#702) ([renovate[bot]](https://github.com/apps/renovate)) - Fix typos and grammar issues in documentation [\#701](christianhelle/refitter#701) ([Copilot](https://github.com/apps/copilot-swe-agent)) - Update dotnet monorepo [\#699](christianhelle/refitter#699) ([renovate[bot]](https://github.com/apps/renovate)) - Update dependency Polly to 8.6.0 [\#698](christianhelle/refitter#698) ([renovate[bot]](https://github.com/apps/renovate)) - Update dependency Refitter.SourceGenerator to 1.5.6 [\#696](christianhelle/refitter#696) ([renovate[bot]](https://github.com/apps/renovate)) - Update dependency Microsoft.NET.Test.Sdk to 17.14.1 [\#692](christianhelle/refitter#692) ([renovate[bot]](https://github.com/apps/renovate)) - Update dependency Swashbuckle.AspNetCore to 8.1.4 [\#691](christianhelle/refitter#691) ([renovate[bot]](https://github.com/apps/renovate)) See [Full Changelog](christianhelle/refitter@1.5.6...1.6.0) ## 1.5.6 ## What's Changed * Use fully qualified type name in Class template by @velvolue in christianhelle/refitter#686 * Add .NET 9.0 to Target Frameworks by @christianhelle in christianhelle/refitter#690 * Do not add both [Multipart] and "Content-Type: multipart/form-data" by @jaroslaw-dutka in christianhelle/refitter#693 ## Merged pull requests * chore(deps): update dependency refitter.sourcegenerator to 1.5.5 by @renovate in christianhelle/refitter#671 * docs: add MrScottyTay as a contributor for bug by @allcontributors in christianhelle/refitter#673 * chore(deps): update dotnet monorepo by @renovate in christianhelle/refitter#674 * chore(deps): update dependency microsoft.build.utilities.core to 17.14.7 by @renovate in christianhelle/refitter#675 * chore(deps): update dependency microsoft.build.utilities.core to 17.14.8 by @renovate in christianhelle/refitter#676 * chore(deps): update dependency microsoft.net.test.sdk to 17.14.0 by @renovate in christianhelle/refitter#680 * Add Contribution Guidelines by @copilot-swe-agent in christianhelle/refitter#679 * chore(deps): update dependency swashbuckle.aspnetcore to 8.1.2 by @renovate in christianhelle/refitter#682 * docs: add velvolue as a contributor for bug by @allcontributors in christianhelle/refitter#687 * Use fully qualified type name in Class template by @velvolue in christianhelle/refitter#686 * Resolve build warnings and add TreatWarningsAsErrors by @copilot-swe-agent in christianhelle/refitter#689 * Add .NET 9.0 to Target Frameworks by @christianhelle in christianhelle/refitter#690 * Do not add both [Multipart] and "Content-Type: multipart/form-data" by @jaroslaw-dutka in christianhelle/refitter#693 **Full Changelog**: christianhelle/refitter@1.5.5...1.5.6 ## 1.5.5 ## What's Changed - Using CollectionFormats other than Multi [\#640](christianhelle/refitter#640) (@ebarnard) - Add collection format option to CLI tool documentation [\#664](christianhelle/refitter#664) (@christianhelle) - Made Security Header Parameters safe for C\# when unsafe characters are present [\#663](christianhelle/refitter#663) (@AragornHL) ## Merged pull requests: - chore\(deps\): update dependency xunit.runner.visualstudio to 3.1.0 [\#670](christianhelle/refitter#670) ([renovate[bot]](https://github.com/apps/renovate)) - docs: add tommieemeli as a contributor for bug [\#669](christianhelle/refitter#669) ([allcontributors[bot]](https://github.com/apps/allcontributors)) - Update nswag monorepo to 14.4.0 [\#665](christianhelle/refitter#665) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dependency refitter.sourcegenerator to 1.5.4 [\#662](christianhelle/refitter#662) ([renovate[bot]](https://github.com/apps/renovate)) **Full Changelog**: christianhelle/refitter@1.5.4...1.5.5 ## 1.5.4 ## What's Changed - Adding security schemes to the api interface generator [\#106](christianhelle/refitter#106) - Response type handling to only use 2XX range [\#661](christianhelle/refitter#661) ([christianhelle](https://github.com/christianhelle)) - Add support for 2XX and Default Response Objects [\#660](christianhelle/refitter#660) ([christianhelle](https://github.com/christianhelle)) - Add Header Parameters for Security Schemes [\#653](christianhelle/refitter#653) ([AragornHL](https://github.com/AragornHL)) ## Merged Pull Requests: * chore(deps): update dependency refitter.sourcegenerator to 1.5.3 by @renovate in christianhelle/refitter#645 * chore(deps): update dependency swashbuckle.aspnetcore to 8.1.0 by @renovate in christianhelle/refitter#646 * chore(deps): update dependency exceptionless to 6.1.0 by @renovate in christianhelle/refitter#647 * chore(deps): update dependency spectre.console.cli to 0.50.0 by @renovate in christianhelle/refitter#649 * chore(deps): update dotnet monorepo to 9.0.4 by @renovate in christianhelle/refitter#648 * chore(deps): update dependency microsoft.extensions.http.resilience to 9.4.0 by @renovate in christianhelle/refitter#650 * chore(deps): update dependency swashbuckle.aspnetcore to 8.1.1 by @renovate in christianhelle/refitter#651 * Add Header Parameters for Security Schemes by @AragornHL in christianhelle/refitter#653 * docs: add @AragornHL as a contributor for code by @allcontributors in christianhelle/refitter#655 * docs: add @kmfd3s as a contributor for code by @allcontributors in christianhelle/refitter#656 * Update smoke tests to generate authentication headers by @christianhelle in christianhelle/refitter#657 * docs: add @pfeigl as a contributor for bug by @allcontributors in christianhelle/refitter#659 * Add support for 2XX and Default Response Objects by @christianhelle in christianhelle/refitter#660 * Response type handling to only use 2XX range by @christianhelle in christianhelle/refitter#661 ## New Contributors * @AragornHL made their first contribution in christianhelle/refitter#653 **Full Changelog**: christianhelle/refitter@1.5.3...1.5.4 ## 1.5.3 **Implemented enhancements:** - Naming properties problem [\#641](christianhelle/refitter#641) - Allow comments in .refitter Configuration [\#631](christianhelle/refitter#631) - NSwag v14.3.0 [\#644](christianhelle/refitter#644) ([renovate[bot]](https://github.com/apps/renovate)) - Convert properties with underscores to PascalCase [\#643](christianhelle/refitter#643) ([christianhelle](https://github.com/christianhelle)) - Add support for deserializing JSON with comments and update tests [\#637](christianhelle/refitter#637) ([sebastian-wachsmuth](https://github.com/sebastian-wachsmuth)) - Temporary fix for Source Generator when running in Visual Studio [\#634](christianhelle/refitter#634) ([christianhelle](https://github.com/christianhelle)) - JSON Schema generator for documentation [\#623](christianhelle/refitter#623) ([christianhelle](https://github.com/christianhelle)) - Fix missing Content-Type \[Headers\] [\#619](christianhelle/refitter#619) ([christianhelle](https://github.com/christianhelle)) - Fix invalid characters in generated XML docs [\#607](christianhelle/refitter#607) ([christianhelle](https://github.com/christianhelle)) - Add support for custom DateTimeFormat [\#604](christianhelle/refitter#604) ([christianhelle](https://github.com/christianhelle)) - Fix ISO date format handling when dateFormat is defined in settings file [\#603](christianhelle/refitter#603) ([christianhelle](https://github.com/christianhelle)) **Fixed bugs:** - Doesn't add Content-Type request header when body is plain JSON string [\#617](christianhelle/refitter#617) - Broken xml doc when swagger descriptions contains "\<" or "\>" characters [\#605](christianhelle/refitter#605) - date-time parameters are encoded as date when iso8601 is used [\#599](christianhelle/refitter#599) **Closed issues:** - OpenAPI Schema and Authorization Attributes [\#629](christianhelle/refitter#629) **Merged pull requests:** - docs: add @lowern1ght as a contributor for bug [\#642](christianhelle/refitter#642) ([allcontributors[bot]](https://github.com/apps/allcontributors)) - docs: add @qrzychu as a contributor for bug [\#639](christianhelle/refitter#639) ([allcontributors[bot]](https://github.com/apps/allcontributors)) - docs: add @sebastian-wachsmuth as a contributor for code [\#638](christianhelle/refitter#638) ([allcontributors[bot]](https://github.com/apps/allcontributors)) - Update dependency Swashbuckle.AspNetCore to v8 [\#633](christianhelle/refitter#633) ([renovate[bot]](https://github.com/apps/renovate)) - Update dotnet monorepo [\#630](christianhelle/refitter#630) ([renovate[bot]](https://github.com/apps/renovate)) - Update dependency Atc.Test to 1.1.18 [\#628](christianhelle/refitter#628) ([renovate[bot]](https://github.com/apps/renovate)) - Update dependency Swashbuckle.AspNetCore to 7.3.1 [\#626](christianhelle/refitter#626) ([renovate[bot]](https://github.com/apps/renovate)) - Update dependency Swashbuckle.AspNetCore to 7.3.0 [\#624](christianhelle/refitter#624) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dependency fluentassertions to 7.2.0 [\#622](christianhelle/refitter#622) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dependency apizr.integrations.fusillade to 6.4.2 [\#621](christianhelle/refitter#621) ([renovate[bot]](https://github.com/apps/renovate)) - docs: add @Metziell as a contributor for bug [\#620](christianhelle/refitter#620) ([allcontributors[bot]](https://github.com/apps/allcontributors)) - docs: add @Fargekritt as a contributor for bug [\#618](christianhelle/refitter#618) ([allcontributors[bot]](https://github.com/apps/allcontributors)) - chore\(deps\): update dependency apizr.integrations.automapper to 6.4.2 [\#616](christianhelle/refitter#616) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dependency apizr.extensions.microsoft.caching to 6.4.2 [\#615](christianhelle/refitter#615) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dependency microsoft.applicationinsights.windowsserver to 2.23.0 [\#614](christianhelle/refitter#614) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dependency microsoft.build.utilities.core to 17.13.9 [\#612](christianhelle/refitter#612) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dotnet monorepo [\#611](christianhelle/refitter#611) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dependency microsoft.net.test.sdk to 17.13.0 [\#610](christianhelle/refitter#610) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dependency xunit.runner.visualstudio to 3.0.2 [\#609](christianhelle/refitter#609) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dependency polly to 8.5.2 [\#608](christianhelle/refitter#608) ([renovate[bot]](https://github.com/apps/renovate)) - docs: add @wocasella as a contributor for bug [\#606](christianhelle/refitter#606) ([allcontributors[bot]](https://github.com/apps/allcontributors)) - chore\(deps\): update dependency refitter.sourcegenerator to 1.5.2 [\#602](christianhelle/refitter#602) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dependency atc.test to 1.1.17 [\#592](christianhelle/refitter#592) ([renovate[bot]](https://github.com/apps/renovate)) - chore\(deps\): update dependency h.generators.extensions to 1.24.2 [\#581](christianhelle/refitter#581) ([renovate[bot]](https://github.com/apps/renovate)) ... (truncated) ## 1.5.2 ## Implemented enhancements: - Fix date formatting for date-time types christianhelle/refitter#600 - Proper support for multipart form christianhelle/refitter#595 ## Fixed bugs: - date-time parameters are encoded as date when iso8601 is used christianhelle/refitter#599 - \[FromForm\] parameter on minimal api doesn't get generated on Interface christianhelle/refitter#515 ## Merged pull requests: * chore(deps): update dependency coverlet.collector to 6.0.4 by @renovate in christianhelle/refitter#594 * Proper support for multipart form by @jaroslaw-dutka in christianhelle/refitter#595 * docs: add jaroslaw-dutka as a contributor for code by @allcontributors in christianhelle/refitter#596 * chore(deps): update dependency refitter.sourcegenerator to 1.5.0 by @renovate in christianhelle/refitter#593 * Remove dependency on System.Text.Json by @christianhelle in christianhelle/refitter#597 * chore(deps): update dependency refitter.sourcegenerator to 1.5.1 by @renovate in christianhelle/refitter#598 * docs: add maksionkin as a contributor for bug by @allcontributors in christianhelle/refitter#601 * Fix date formatting for date-time types by @christianhelle in christianhelle/refitter#600 ## New Contributors * @jaroslaw-dutka made their first contribution in christianhelle/refitter#595 * @maksionkin reported their first issue in christianhelle/refitter#599 **Full Changelog**: christianhelle/refitter@1.5.0...1.5.2 ## 1.5.0 ## Implemented enhancements: - Fix incorrect error message shown due to Spectre.Console parsing [\#585](christianhelle/refitter#585) ([christianhelle](https://github.com/christianhelle)) - Return null when object subtype is not found [\#577](christianhelle/refitter#577) ([velvolue](https://github.com/velvolue)) - Discard unused union types/inheritance types via config [\#575](christianhelle/refitter#575) ([kirides](https://github.com/kirides)) - Show Deserializaton Errors from Source Generator [\#572](christianhelle/refitter#572) ([christianhelle](https://github.com/christianhelle)) - Limit Exceptionless telemetry [\#564](christianhelle/refitter#564) ([christianhelle](https://github.com/christianhelle)) - Added simple logic to make most identifier strings valid [\#562](christianhelle/refitter#562) ([Fargekritt](https://github.com/Fargekritt)) - Fix -v|--version CLI tool argument [\#561](christianhelle/refitter#561) ([christianhelle](https://github.com/christianhelle)) - Less strict OpenAPI Validation rules [\#558](christianhelle/refitter#558) ([christianhelle](https://github.com/christianhelle)) - Added support for custom date format [\#554](christianhelle/refitter#554) ([Fargekritt](https://github.com/Fargekritt)) - Add support for disabling telemetry in MSBuild task [\#550](christianhelle/refitter#550) ([christianhelle](https://github.com/christianhelle)) - MSBuild Custom Task [\#548](christianhelle/refitter#548) ([christianhelle](https://github.com/christianhelle)) - Generate IDisposable Refit Interfaces [\#543](christianhelle/refitter#543) ([christianhelle](https://github.com/christianhelle)) - Clients implementing IDisposable interface [\#541](christianhelle/refitter#541) ([shubinp](https://github.com/shubinp)) - \[Apizr\] Deprecated Optional package removed from code & doc [\#539](christianhelle/refitter#539) ([JeremyBP](https://github.com/JeremyBP)) - Add PropertyNameGenerator as an optional Parameter [\#516](christianhelle/refitter#516) - NSwag v14.2.0 [\#532](christianhelle/refitter#532) ([renovate[bot]](https://github.com/apps/renovate)) - added options for a custom Name Generators [\#517](christianhelle/refitter#517) ([fsamiec](https://github.com/fsamiec)) ## Fixed bugs: - "Error: Could not find color or style 'System.String'." [\#583](christianhelle/refitter#583) - Source generator errors are hidden [\#568](christianhelle/refitter#568) - Refitter -v not showing version number [\#560](christianhelle/refitter#560) - Not so nice behavior when generating client with trim-unused-schema [\#557](christianhelle/refitter#557) - Two almost identical routes that fail at validation. [\#551](christianhelle/refitter#551) - Code Generator creates unsafe interface method names [\#360](christianhelle/refitter#360) ## Closed issues: - How to use in class library? [\#534](christianhelle/refitter#534) - \[ISSUE\]\[1.2.1-preview.54\] Some impediments using CLI version. Is not enough for my needs? [\#450](christianhelle/refitter#450) ## Merged Pull Requests * chore(deps): update dependency refitter.sourcegenerator to 1.4.0 by @renovate in christianhelle/refitter#513 * chore(deps): update dependency swashbuckle.aspnetcore to 6.9.0 by @renovate in christianhelle/refitter#514 * added options for a custom Name Generators by @fsamiec in christianhelle/refitter#517 * docs: add fsamiec as a contributor for code by @allcontributors in christianhelle/refitter#518 * chore(deps): update refit monorepo to v8 (major) by @renovate in christianhelle/refitter#519 * docs: add fabioloreggian as a contributor for bug by @allcontributors in christianhelle/refitter#521 * chore(deps): update dependency fluentassertions to 6.12.2 by @renovate in christianhelle/refitter#523 * chore(deps): update dependency polly to 8.5.0 by @renovate in christianhelle/refitter#525 * chore(deps): update dependency swashbuckle.aspnetcore to v7 by @renovate in christianhelle/refitter#526 * chore(deps): update dependency h.generators.extensions to 1.24.0 by @renovate in christianhelle/refitter#528 * chore(deps): update dotnet monorepo to v9 (major) by @renovate in christianhelle/refitter#527 * NSwag v14.2.0 by @renovate in christianhelle/refitter#532 * chore(deps): update dependency microsoft.net.test.sdk to 17.12.0 by @renovate in christianhelle/refitter#531 * chore(deps): update dependency refitter.sourcegenerator to 1.4.1 by @renovate in christianhelle/refitter#533 * docs: add geometrikal as a contributor for bug by @allcontributors in christianhelle/refitter#535 ... (truncated) Commits viewable in [compare view](christianhelle/refitter@1.4.0...1.7.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>



Simplify the polymorphic serialization code now that NSwag/NJsonSchema.CodeGeneration.CSharp supports it.
Get rid of the custom templates and just tweak what's necessary in code to ease future NSwag upgrades.
Ping @ryanheath who worked on the original implementation in #462.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Documentation
Chores