Skip to content

Commit

Permalink
Merge pull request #465 from ryanheath/issue-459-IgnoreUnrecognizedTy…
Browse files Browse the repository at this point in the history
…peDiscriminators

added IgnoreUnrecognizedTypeDiscriminators = true
  • Loading branch information
christianhelle authored Sep 11, 2024
2 parents 1cddab6 + 72e42a9 commit 01a0d15
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Refitter.Core/Templates/Class.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{%- if HasDiscriminator -%}
{%- if UseSystemTextJson -%}
{%- if UsePolymorphicSerialization -%}
[System.Text.Json.Serialization.JsonPolymorphic(TypeDiscriminatorPropertyName = "{{ Discriminator }}", UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType)]
[System.Text.Json.Serialization.JsonPolymorphic(TypeDiscriminatorPropertyName = "{{ Discriminator }}", UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType, IgnoreUnrecognizedTypeDiscriminators = true)]
{%- else -%}
[JsonInheritanceConverter(typeof({{ ClassName }}), "{{ Discriminator }}")]
{%- endif -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public partial class Metadata

}

[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type", UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType)]
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type", UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType, IgnoreUnrecognizedTypeDiscriminators = true)]
[JsonDerivedType(typeof(Warehouse), typeDiscriminator: "Warehouse")]
[JsonDerivedType(typeof(WarehouseResponse), typeDiscriminator: "WarehouseResponse")]
[JsonDerivedType(typeof(LoadingAddress), typeDiscriminator: "LoadingAddress")]
Expand Down Expand Up @@ -197,7 +197,7 @@ public partial class UserComponent2 : UserComponent

}

[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type", UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType)]
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type", UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType, IgnoreUnrecognizedTypeDiscriminators = true)]
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class ProblemDetails
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public async Task Use_Polymorphic_Serialization()
generateCode.Should().NotContain("JsonInheritanceConverter");
generateCode.Should().NotContain("JsonInheritanceAttribute");

generateCode.Should().Contain("[JsonPolymorphic(TypeDiscriminatorPropertyName = \"$type\", UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType)]");
generateCode.Should().Contain("[JsonPolymorphic(TypeDiscriminatorPropertyName = \"$type\", UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType, IgnoreUnrecognizedTypeDiscriminators = true)]");
generateCode.Should().Contain("[JsonDerivedType(typeof(Warehouse), typeDiscriminator: \"Warehouse\")]");
generateCode.Should().Contain("[JsonDerivedType(typeof(WarehouseResponse), typeDiscriminator: \"WarehouseResponse\")]");
generateCode.Should().Contain("[JsonDerivedType(typeof(LoadingAddress), typeDiscriminator: \"LoadingAddress\")]");
Expand Down

0 comments on commit 01a0d15

Please sign in to comment.