Skip to content

Commit

Permalink
fix(csharp): Fixed JsonConverter for discriminators only appearing on…
Browse files Browse the repository at this point in the history
… base classes (#19972)

* fix(csharp): Fixed JsonConverter for discriminators only appearing on base classes

* chore: Updated .NET samples
  • Loading branch information
DaveK-Rocketmakers authored Nov 9, 2024
1 parent 5702751 commit d9229c7
Show file tree
Hide file tree
Showing 24 changed files with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ namespace {{modelPackage}}
[DataContract]
{{#discriminator}}
{{#useNewtonsoft}}
{{#mappedModels.size}}
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]
{{/mappedModels.size}}
{{/useNewtonsoft}}
{{#useSwashbuckle}}
[SwaggerDiscriminator("{{{discriminatorName}}}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
/// </summary>
[DataContract(Name = "{{{name}}}")]
{{#discriminator}}
{{#mappedModels.size}}
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]
{{/mappedModels.size}}
{{#mappedModels}}
[JsonSubtypes.KnownSubType(typeof({{{modelName}}}), "{{^vendorExtensions.x-discriminator-value}}{{{mappingName}}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{.}}}{{/vendorExtensions.x-discriminator-value}}")]
{{/mappedModels}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
[DataContract(Name = "{{{name}}}")]
{{^useUnityWebRequest}}
{{#discriminator}}
{{#mappedModels.size}}
[JsonConverter(typeof(JsonSubtypes), "{{{discriminatorName}}}")]
{{/mappedModels.size}}
{{#mappedModels}}
[JsonSubtypes.KnownSubType(typeof({{{modelName}}}), "{{^vendorExtensions.x-discriminator-value}}{{{mappingName}}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{.}}}{{/vendorExtensions.x-discriminator-value}}")]
{{/mappedModels}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace Org.OpenAPITools.Model
/// Cat
/// </summary>
[DataContract(Name = "Cat")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Cat : Animal, IEquatable<Cat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace Org.OpenAPITools.Model
/// ChildCat
/// </summary>
[DataContract(Name = "ChildCat")]
[JsonConverter(typeof(JsonSubtypes), "PetType")]
public partial class ChildCat : ParentPet, IEquatable<ChildCat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace Org.OpenAPITools.Model
/// Dog
/// </summary>
[DataContract(Name = "Dog")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Dog : Animal, IEquatable<Dog>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Cat
/// </summary>
[DataContract(Name = "Cat")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Cat : Animal, IEquatable<Cat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// ChildCat
/// </summary>
[DataContract(Name = "ChildCat")]
[JsonConverter(typeof(JsonSubtypes), "PetType")]
public partial class ChildCat : ParentPet, IEquatable<ChildCat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Dog
/// </summary>
[DataContract(Name = "Dog")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Dog : Animal, IEquatable<Dog>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Cat
/// </summary>
[DataContract(Name = "Cat")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Cat : Animal, IEquatable<Cat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// ChildCat
/// </summary>
[DataContract(Name = "ChildCat")]
[JsonConverter(typeof(JsonSubtypes), "PetType")]
public partial class ChildCat : ParentPet, IEquatable<ChildCat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Dog
/// </summary>
[DataContract(Name = "Dog")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Dog : Animal, IEquatable<Dog>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Cat
/// </summary>
[DataContract(Name = "Cat")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Cat : Animal, IEquatable<Cat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// ChildCat
/// </summary>
[DataContract(Name = "ChildCat")]
[JsonConverter(typeof(JsonSubtypes), "PetType")]
public partial class ChildCat : ParentPet, IEquatable<ChildCat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Dog
/// </summary>
[DataContract(Name = "Dog")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Dog : Animal, IEquatable<Dog>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Cat
/// </summary>
[DataContract(Name = "Cat")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Cat : Animal, IEquatable<Cat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// ChildCat
/// </summary>
[DataContract(Name = "ChildCat")]
[JsonConverter(typeof(JsonSubtypes), "PetType")]
public partial class ChildCat : ParentPet, IEquatable<ChildCat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Dog
/// </summary>
[DataContract(Name = "Dog")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Dog : Animal, IEquatable<Dog>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Cat
/// </summary>
[DataContract(Name = "Cat")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Cat : Animal, IEquatable<Cat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// ChildCat
/// </summary>
[DataContract(Name = "ChildCat")]
[JsonConverter(typeof(JsonSubtypes), "PetType")]
public partial class ChildCat : ParentPet, IEquatable<ChildCat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Dog
/// </summary>
[DataContract(Name = "Dog")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Dog : Animal, IEquatable<Dog>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Cat
/// </summary>
[DataContract(Name = "Cat")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Cat : Animal, IEquatable<Cat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// ChildCat
/// </summary>
[DataContract(Name = "ChildCat")]
[JsonConverter(typeof(JsonSubtypes), "PetType")]
public partial class ChildCat : ParentPet, IEquatable<ChildCat>, IValidatableObject
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Org.OpenAPITools.Model
/// Dog
/// </summary>
[DataContract(Name = "Dog")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Dog : Animal, IEquatable<Dog>, IValidatableObject
{
/// <summary>
Expand Down

0 comments on commit d9229c7

Please sign in to comment.