[C#][netcore] Add custom converters for oneOf models (#7766)

* add custom converter for oneof models

* remove custom logic when deserializing oneof response
This commit is contained in:
William Cheng
2020-10-20 23:10:31 +08:00
committed by GitHub
parent 072b309100
commit 19249e597c
24 changed files with 810 additions and 27 deletions

View File

@@ -455,15 +455,6 @@ namespace {{packageName}}.Client
response = client.Execute<T>(req);
}
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
if (typeof({{{packageName}}}.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
{
T instance = (T)Activator.CreateInstance(typeof(T));
MethodInfo method = typeof(T).GetMethod("FromJson");
method.Invoke(instance, new object[] { response.Content });
response.Data = instance;
}
InterceptResponse(req, response);
var result = ToApiResponse(response);

View File

@@ -28,6 +28,11 @@ using OpenAPIClientUtils = {{packageName}}.Client.ClientUtils;
{{/useCompareNetObjects}}
{{#models}}
{{#model}}
{{#oneOf}}
{{#-first}}
using System.Reflection;
{{/-first}}
{{/oneOf}}
namespace {{packageName}}.{{modelPackage}}
{

View File

@@ -1,6 +1,7 @@
/// <summary>
/// {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
/// </summary>
[JsonConverter(typeof({{classname}}JsonConverter))]
[DataContract(Name = "{{{name}}}")]
{{>visibility}} partial class {{classname}} : AbstractOpenAPISchema, {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}>{{#validatable}}, IValidatableObject{{/validatable}}
{
@@ -204,3 +205,43 @@
yield break;
}
}
/// <summary>
/// Custom JSON converter for {{classname}}
/// </summary>
public class {{classname}}JsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof({{classname}}).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return {{classname}}.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}

View File

@@ -10,6 +10,7 @@ using Xunit;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
using Newtonsoft.Json;
namespace Org.OpenAPITools.Test
{
@@ -86,6 +87,13 @@ namespace Org.OpenAPITools.Test
Fruit f4 = Fruit.FromJson("{\"origin\":\"Japan\"}");
Assert.IsType<Apple>(f4.ActualInstance);
// test custom deserializer
Fruit f5 = JsonConvert.DeserializeObject<Fruit>("{\"lengthCm\":98}");
Assert.IsType<Banana>(f5.ActualInstance);
// test custom serializer
Assert.Equal("{\"lengthCm\":98.0}", JsonConvert.SerializeObject(f5));
}
}
}

View File

@@ -459,15 +459,6 @@ namespace Org.OpenAPITools.Client
response = client.Execute<T>(req);
}
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
{
T instance = (T)Activator.CreateInstance(typeof(T));
MethodInfo method = typeof(T).GetMethod("FromJson");
method.Invoke(instance, new object[] { response.Content });
response.Data = instance;
}
InterceptResponse(req, response);
var result = ToApiResponse(response);

View File

@@ -23,12 +23,14 @@ using Newtonsoft.Json.Linq;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Fruit
/// </summary>
[JsonConverter(typeof(FruitJsonConverter))]
[DataContract(Name = "fruit")]
public partial class Fruit : AbstractOpenAPISchema, IEquatable<Fruit>, IValidatableObject
{
@@ -221,4 +223,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Fruit
/// </summary>
public class FruitJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Fruit).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Fruit.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -23,12 +23,14 @@ using Newtonsoft.Json.Linq;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// FruitReq
/// </summary>
[JsonConverter(typeof(FruitReqJsonConverter))]
[DataContract(Name = "fruitReq")]
public partial class FruitReq : AbstractOpenAPISchema, IEquatable<FruitReq>, IValidatableObject
{
@@ -230,4 +232,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for FruitReq
/// </summary>
public class FruitReqJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(FruitReq).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return FruitReq.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Mammal
/// </summary>
[JsonConverter(typeof(MammalJsonConverter))]
[DataContract(Name = "mammal")]
public partial class Mammal : AbstractOpenAPISchema, IEquatable<Mammal>, IValidatableObject
{
@@ -278,4 +280,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Mammal
/// </summary>
public class MammalJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Mammal).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Mammal.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// The value may be a shape or the &#39;null&#39; value. The &#39;nullable&#39; attribute was introduced in OAS schema &gt;&#x3D; 3.0 and has been deprecated in OAS schema &gt;&#x3D; 3.1.
/// </summary>
[JsonConverter(typeof(NullableShapeJsonConverter))]
[DataContract(Name = "NullableShape")]
public partial class NullableShape : AbstractOpenAPISchema, IEquatable<NullableShape>, IValidatableObject
{
@@ -246,4 +248,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for NullableShape
/// </summary>
public class NullableShapeJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(NullableShape).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return NullableShape.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Pig
/// </summary>
[JsonConverter(typeof(PigJsonConverter))]
[DataContract(Name = "Pig")]
public partial class Pig : AbstractOpenAPISchema, IEquatable<Pig>, IValidatableObject
{
@@ -237,4 +239,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Pig
/// </summary>
public class PigJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Pig).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Pig.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Quadrilateral
/// </summary>
[JsonConverter(typeof(QuadrilateralJsonConverter))]
[DataContract(Name = "Quadrilateral")]
public partial class Quadrilateral : AbstractOpenAPISchema, IEquatable<Quadrilateral>, IValidatableObject
{
@@ -237,4 +239,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Quadrilateral
/// </summary>
public class QuadrilateralJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Quadrilateral).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Quadrilateral.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Shape
/// </summary>
[JsonConverter(typeof(ShapeJsonConverter))]
[DataContract(Name = "Shape")]
public partial class Shape : AbstractOpenAPISchema, IEquatable<Shape>, IValidatableObject
{
@@ -237,4 +239,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Shape
/// </summary>
public class ShapeJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Shape).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Shape.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// The value may be a shape or the &#39;null&#39; value. This is introduced in OAS schema &gt;&#x3D; 3.1.
/// </summary>
[JsonConverter(typeof(ShapeOrNullJsonConverter))]
[DataContract(Name = "ShapeOrNull")]
public partial class ShapeOrNull : AbstractOpenAPISchema, IEquatable<ShapeOrNull>, IValidatableObject
{
@@ -246,4 +248,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for ShapeOrNull
/// </summary>
public class ShapeOrNullJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(ShapeOrNull).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return ShapeOrNull.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Triangle
/// </summary>
[JsonConverter(typeof(TriangleJsonConverter))]
[DataContract(Name = "Triangle")]
public partial class Triangle : AbstractOpenAPISchema, IEquatable<Triangle>, IValidatableObject
{
@@ -278,4 +280,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Triangle
/// </summary>
public class TriangleJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Triangle).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Triangle.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -460,15 +460,6 @@ namespace Org.OpenAPITools.Client
response = client.Execute<T>(req);
}
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
if (typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
{
T instance = (T)Activator.CreateInstance(typeof(T));
MethodInfo method = typeof(T).GetMethod("FromJson");
method.Invoke(instance, new object[] { response.Content });
response.Data = instance;
}
InterceptResponse(req, response);
var result = ToApiResponse(response);

View File

@@ -23,12 +23,14 @@ using Newtonsoft.Json.Linq;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Fruit
/// </summary>
[JsonConverter(typeof(FruitJsonConverter))]
[DataContract(Name = "fruit")]
public partial class Fruit : AbstractOpenAPISchema, IEquatable<Fruit>, IValidatableObject
{
@@ -221,4 +223,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Fruit
/// </summary>
public class FruitJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Fruit).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Fruit.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -23,12 +23,14 @@ using Newtonsoft.Json.Linq;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// FruitReq
/// </summary>
[JsonConverter(typeof(FruitReqJsonConverter))]
[DataContract(Name = "fruitReq")]
public partial class FruitReq : AbstractOpenAPISchema, IEquatable<FruitReq>, IValidatableObject
{
@@ -230,4 +232,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for FruitReq
/// </summary>
public class FruitReqJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(FruitReq).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return FruitReq.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Mammal
/// </summary>
[JsonConverter(typeof(MammalJsonConverter))]
[DataContract(Name = "mammal")]
public partial class Mammal : AbstractOpenAPISchema, IEquatable<Mammal>, IValidatableObject
{
@@ -260,4 +262,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Mammal
/// </summary>
public class MammalJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Mammal).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Mammal.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// The value may be a shape or the &#39;null&#39; value. The &#39;nullable&#39; attribute was introduced in OAS schema &gt;&#x3D; 3.0 and has been deprecated in OAS schema &gt;&#x3D; 3.1.
/// </summary>
[JsonConverter(typeof(NullableShapeJsonConverter))]
[DataContract(Name = "NullableShape")]
public partial class NullableShape : AbstractOpenAPISchema, IEquatable<NullableShape>, IValidatableObject
{
@@ -231,4 +233,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for NullableShape
/// </summary>
public class NullableShapeJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(NullableShape).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return NullableShape.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Pig
/// </summary>
[JsonConverter(typeof(PigJsonConverter))]
[DataContract(Name = "Pig")]
public partial class Pig : AbstractOpenAPISchema, IEquatable<Pig>, IValidatableObject
{
@@ -222,4 +224,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Pig
/// </summary>
public class PigJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Pig).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Pig.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Quadrilateral
/// </summary>
[JsonConverter(typeof(QuadrilateralJsonConverter))]
[DataContract(Name = "Quadrilateral")]
public partial class Quadrilateral : AbstractOpenAPISchema, IEquatable<Quadrilateral>, IValidatableObject
{
@@ -222,4 +224,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Quadrilateral
/// </summary>
public class QuadrilateralJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Quadrilateral).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Quadrilateral.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Shape
/// </summary>
[JsonConverter(typeof(ShapeJsonConverter))]
[DataContract(Name = "Shape")]
public partial class Shape : AbstractOpenAPISchema, IEquatable<Shape>, IValidatableObject
{
@@ -222,4 +224,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Shape
/// </summary>
public class ShapeJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Shape).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Shape.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// The value may be a shape or the &#39;null&#39; value. This is introduced in OAS schema &gt;&#x3D; 3.1.
/// </summary>
[JsonConverter(typeof(ShapeOrNullJsonConverter))]
[DataContract(Name = "ShapeOrNull")]
public partial class ShapeOrNull : AbstractOpenAPISchema, IEquatable<ShapeOrNull>, IValidatableObject
{
@@ -231,4 +233,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for ShapeOrNull
/// </summary>
public class ShapeOrNullJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(ShapeOrNull).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return ShapeOrNull.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}

View File

@@ -24,12 +24,14 @@ using JsonSubTypes;
using System.ComponentModel.DataAnnotations;
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
using System.Reflection;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Triangle
/// </summary>
[JsonConverter(typeof(TriangleJsonConverter))]
[DataContract(Name = "Triangle")]
public partial class Triangle : AbstractOpenAPISchema, IEquatable<Triangle>, IValidatableObject
{
@@ -260,4 +262,44 @@ namespace Org.OpenAPITools.Model
}
}
/// <summary>
/// Custom JSON converter for Triangle
/// </summary>
public class TriangleJsonConverter : JsonConverter
{
/// <summary>
/// To write the JSON string
/// </summary>
/// <param name="writer">JSON writer</param>
/// <param name="value">Object to be converted into a JSON string</param>
/// <param name="serializer">JSON Serializer</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteRaw((String)(typeof(Triangle).GetMethod("ToJson").Invoke(value, null)));
}
/// <summary>
/// To convert a JSON string into an object
/// </summary>
/// <param name="reader">JSON reader</param>
/// <param name="objectType">Object type</param>
/// <param name="existingValue">Existing value</param>
/// <param name="serializer">JSON Serializer</param>
/// <returns>The object converted from the JSON string</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return Triangle.FromJson(JObject.Load(reader).ToString(Formatting.None));
}
/// <summary>
/// Check if the object can be converted
/// </summary>
/// <param name="objectType">Object type</param>
/// <returns>True if the object can be converted</returns>
public override bool CanConvert(Type objectType)
{
return false;
}
}
}