[C#][netcore] Add oneOf support to C# .NET Core client (#7607)

* add oneOf support to c# netcore

* add oneof support to c# netcore client

* update samples

* remove unused file

* add oneof support to response in api client

* add oneof support to serialize

* update samples

* fix actual instance, add more tests

* fix oneof handling in api client

* update tests
This commit is contained in:
William Cheng 2020-10-08 15:46:36 +08:00 committed by GitHub
parent 8d0053fa9f
commit a1c8e248e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 2972 additions and 856 deletions

View File

@ -588,6 +588,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
final String testPackageName = testPackageName();
String packageFolder = sourceFolder + File.separator + packageName;
String clientPackageDir = packageFolder + File.separator + clientPackage;
String modelPackageDir = packageFolder + File.separator + modelPackage;
String testPackageFolder = testFolder + File.separator + testPackageName;
additionalProperties.put("testPackageName", testPackageName);
@ -645,6 +646,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
}
supportingFiles.add(new SupportingFile("appveyor.mustache", "", "appveyor.yml"));
supportingFiles.add(new SupportingFile("AbstractOpenAPISchema.mustache", modelPackageDir, "AbstractOpenAPISchema.cs"));
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);
@ -938,4 +940,31 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
return null;
}
}
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
objs = super.postProcessModels(objs);
List<Object> models = (List<Object>) objs.get("models");
// add implements for serializable/parcelable to all models
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");
if (cm.oneOf != null && !cm.oneOf.isEmpty() && cm.oneOf.contains("ModelNull")) {
// if oneOf contains "null" type
cm.isNullable = true;
cm.oneOf.remove("ModelNull");
}
if (cm.anyOf != null && !cm.anyOf.isEmpty() && cm.anyOf.contains("ModelNull")) {
// if anyOf contains "null" type
cm.isNullable = true;
cm.anyOf.remove("ModelNull");
}
}
return objs;
}
}

View File

@ -0,0 +1,53 @@
{{>partial_header}}
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace {{packageName}}.{{modelPackage}}
{
/// <summary>
/// Abstract base class for oneOf, anyOf schemas in the OpenAPI specification
/// </summary>
{{>visibility}} abstract partial class AbstractOpenAPISchema
{
protected readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
{
// OpenAPI generated types generally hide default constructors.
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
MissingMemberHandling = MissingMemberHandling.Error,
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy
{
OverrideSpecifiedNames = false
}
}
};
/// <summary>
/// Gets or Sets the actual instance
/// </summary>
public abstract Object ActualInstance { get; set; }
/// <summary>
/// Gets or Sets IsNullable to indicate whether the instance is nullable
/// </summary>
public bool IsNullable { get; protected set; }
/// <summary>
/// Gets or Sets the schema type, which can be either `oneOf` or `anyOf`
/// </summary>
public string SchemaType { get; protected set; }
/// <summary>
/// Converts the instance into JSON string.
/// </summary>
public abstract string ToJson();
/// <summary>
/// Converts the JSON string into the instance
/// </summary>
public abstract void FromJson(string jsonString);
}
}

View File

@ -5,17 +5,18 @@ using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
{{^netStandard}}
using System.Web;
{{/netStandard}}
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Text;
using System.Threading;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
{{^netStandard}}
using System.Web;
{{/netStandard}}
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using RestSharp;
@ -59,8 +60,15 @@ namespace {{packageName}}.Client
public string Serialize(object obj)
{
var result = JsonConvert.SerializeObject(obj, _serializerSettings);
return result;
if (obj != null && obj.GetType().IsInstanceOfType(typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema)))
{
// the object to be serialized is an oneOf/anyOf schema
return ((Org.OpenAPITools.Model.AbstractOpenAPISchema)obj).ToJson();
}
else
{
return JsonConvert.SerializeObject(obj, _serializerSettings);
}
}
public T Deserialize<T>(IRestResponse response)
@ -119,9 +127,19 @@ namespace {{packageName}}.Client
// at this point, it must be a model (json)
try
{
if (type.IsInstanceOfType(typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema)))
{
// the response is an oneOf/anyOf schema
Org.OpenAPITools.Model.AbstractOpenAPISchema instance = (Org.OpenAPITools.Model.AbstractOpenAPISchema)Activator.CreateInstance(type);
instance.FromJson(response.Content);
return instance;
}
else
{
return JsonConvert.DeserializeObject(response.Content, type, _serializerSettings);
}
}
catch (Exception e)
{
throw new ApiException(500, e.Message);
@ -437,6 +455,15 @@ namespace {{packageName}}.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);
@ -535,6 +562,15 @@ namespace {{packageName}}.Client
response = await client.ExecuteAsync<T>(req, cancellationToken).ConfigureAwait(false);
}
// 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

@ -30,7 +30,7 @@ using OpenAPIClientUtils = {{packageName}}.Client.ClientUtils;
namespace {{packageName}}.{{modelPackage}}
{
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}}
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{#oneOf}}{{#-first}}{{>modelOneOf}}{{/-first}}{{/oneOf}}{{^oneOf}}{{>modelGeneric}}{{/oneOf}}{{/isEnum}}
{{/model}}
{{/models}}
}

View File

@ -0,0 +1,184 @@
/// <summary>
/// {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
/// </summary>
[DataContract(Name = "{{{name}}}")]
{{>visibility}} partial class {{classname}} : AbstractOpenAPISchema, {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}>{{#validatable}}, IValidatableObject{{/validatable}}
{
/// <summary>
/// Initializes a new instance of the <see cref="{{classname}}" /> class.
/// </summary>
public {{classname}}()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
{{#oneOf}}
/// <summary>
/// Initializes a new instance of the <see cref="{{classname}}" /> class
/// with the <see cref="{{{.}}}" /> class
/// </summary>
/// <param name="actualInstance">An instance of {{{.}}}.</param>
public {{classname}}({{{.}}} actualInstance)
{
this.IsNullable = {{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}};
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance{{^isNullable}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isNullable}};
}
{{/oneOf}}
private Object _actualInstance;
/// <summary>
/// Gets or Sets ActualInstance
/// </summary>
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
{{#oneOf}}
{{^-first}}else {{/-first}}if (value.GetType() == typeof({{{.}}}))
{
this._actualInstance = value;
}
{{/oneOf}}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types:{{#oneOf}} {{{.}}}{{^-last}},{{/-last}}{{/oneOf}}");
}
}
}
{{#oneOf}}
/// <summary>
/// Get the actual instance of `{{{.}}}`. If the actual instanct is not `{{{.}}}`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of {{{.}}}</returns>
public {{{.}}} Get{{{.}}}()
{
return ({{{.}}})this.ActualInstance;
}
{{/oneOf}}
/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class {{classname}} {\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public override string ToJson()
{
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
{{#oneOf}}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<{{{.}}}>(jsonString, _serializerSettings);
matchedTypes.Add("{{{.}}}");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
{{/oneOf}}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input)
{
{{#useCompareNetObjects}}
return OpenAPIClientUtils.compareLogic.Compare(this, input as {{classname}}).AreEqual;
{{/useCompareNetObjects}}
{{^useCompareNetObjects}}
return this.Equals(input as {{classname}});
{{/useCompareNetObjects}}
}
/// <summary>
/// Returns true if {{classname}} instances are equal
/// </summary>
/// <param name="input">Instance of {{classname}} to be compared</param>
/// <returns>Boolean</returns>
public bool Equals({{classname}} input)
{
{{#useCompareNetObjects}}
return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual;
{{/useCompareNetObjects}}
{{^useCompareNetObjects}}
if (input == null)
return false;
return this.ActualInstance.Equals(input.ActualInstance);
{{/useCompareNetObjects}}
}
/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
yield break;
}
}

View File

@ -114,6 +114,7 @@ src/Org.OpenAPITools/Client/Multimap.cs
src/Org.OpenAPITools/Client/OpenAPIDateConverter.cs
src/Org.OpenAPITools/Client/RequestOptions.cs
src/Org.OpenAPITools/Client/RetryConfiguration.cs
src/Org.OpenAPITools/Model/AbstractOpenAPISchema.cs
src/Org.OpenAPITools/Model/AdditionalPropertiesClass.cs
src/Org.OpenAPITools/Model/Animal.cs
src/Org.OpenAPITools/Model/ApiResponse.cs

View File

@ -0,0 +1,71 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using RestSharp;
using Xunit;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
namespace Org.OpenAPITools.Test
{
/// <summary>
/// Class for testing Configuration
/// </summary>
public class JSONComposedSchemaTests
{
public JSONComposedSchemaTests()
{
}
/// <summary>
/// Test GetServerUrl
/// </summary>
[Fact]
public void testOneOfSchemaAdditionalProperties()
{
// TODO
}
/// <summary>
/// Test Fruit
/// </summary>
[Fact]
public void testFruit()
{
Apple a = new Apple();
a.Origin = "Japan";
Banana b = new Banana();
b.LengthCm = 13;
Tag t = new Tag();
t.Id = 12;
t.Name = "Something";
Fruit f1 = new Fruit(a);
Fruit f2 = new Fruit(a);
f1.ActualInstance = b;
f2.ActualInstance = a;
Assert.Equal(13, f1.GetBanana().LengthCm);
Assert.Equal("Japan", f2.GetApple().Origin);
Assert.Throws<System.ArgumentException>(() => f1.ActualInstance = t);
Assert.Equal("{\"lengthCm\":13.0}", f1.ToJson());
Assert.Equal("{\"origin\":\"Japan\"}", f2.ToJson());
f1.FromJson("{\"lengthCm\":98}");
Assert.IsType<Banana>(f1.ActualInstance);
f2.FromJson("{\"origin\":\"Japan\"}");
Assert.IsType<Apple>(f2.ActualInstance);
}
}
}

View File

@ -15,6 +15,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Text;
@ -64,8 +65,15 @@ namespace Org.OpenAPITools.Client
public string Serialize(object obj)
{
var result = JsonConvert.SerializeObject(obj, _serializerSettings);
return result;
if (obj != null && obj.GetType().IsInstanceOfType(typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema)))
{
// the object to be serialized is an oneOf/anyOf schema
return ((Org.OpenAPITools.Model.AbstractOpenAPISchema)obj).ToJson();
}
else
{
return JsonConvert.SerializeObject(obj, _serializerSettings);
}
}
public T Deserialize<T>(IRestResponse response)
@ -124,9 +132,19 @@ namespace Org.OpenAPITools.Client
// at this point, it must be a model (json)
try
{
if (type.IsInstanceOfType(typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema)))
{
// the response is an oneOf/anyOf schema
Org.OpenAPITools.Model.AbstractOpenAPISchema instance = (Org.OpenAPITools.Model.AbstractOpenAPISchema)Activator.CreateInstance(type);
instance.FromJson(response.Content);
return instance;
}
else
{
return JsonConvert.DeserializeObject(response.Content, type, _serializerSettings);
}
}
catch (Exception e)
{
throw new ApiException(500, e.Message);
@ -441,6 +459,15 @@ 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);
@ -538,6 +565,15 @@ namespace Org.OpenAPITools.Client
response = await client.ExecuteAsync<T>(req, cancellationToken).ConfigureAwait(false);
}
// 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

@ -0,0 +1,61 @@
/*
* OpenAPI Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Abstract base class for oneOf, anyOf schemas in the OpenAPI specification
/// </summary>
public abstract partial class AbstractOpenAPISchema
{
protected readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
{
// OpenAPI generated types generally hide default constructors.
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
MissingMemberHandling = MissingMemberHandling.Error,
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy
{
OverrideSpecifiedNames = false
}
}
};
/// <summary>
/// Gets or Sets the actual instance
/// </summary>
public abstract Object ActualInstance { get; set; }
/// <summary>
/// Gets or Sets IsNullable to indicate whether the instance is nullable
/// </summary>
public bool IsNullable { get; protected set; }
/// <summary>
/// Gets or Sets the schema type, which can be either `oneOf` or `anyOf`
/// </summary>
public string SchemaType { get; protected set; }
/// <summary>
/// Converts the instance into JSON string.
/// </summary>
public abstract string ToJson();
/// <summary>
/// Converts the JSON string into the instance
/// </summary>
public abstract void FromJson(string jsonString);
}
}

View File

@ -29,46 +29,89 @@ namespace Org.OpenAPITools.Model
/// Fruit
/// </summary>
[DataContract(Name = "fruit")]
public partial class Fruit : IEquatable<Fruit>, IValidatableObject
public partial class Fruit : AbstractOpenAPISchema, IEquatable<Fruit>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Fruit" /> class.
/// </summary>
/// <param name="color">color.</param>
/// <param name="cultivar">cultivar.</param>
/// <param name="origin">origin.</param>
/// <param name="lengthCm">lengthCm.</param>
public Fruit(string color = default(string), string cultivar = default(string), string origin = default(string), decimal lengthCm = default(decimal))
public Fruit()
{
this.Color = color;
this.Cultivar = cultivar;
this.Origin = origin;
this.LengthCm = lengthCm;
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets Color
/// Initializes a new instance of the <see cref="Fruit" /> class
/// with the <see cref="Apple" /> class
/// </summary>
[DataMember(Name = "color", EmitDefaultValue = false)]
public string Color { get; set; }
/// <param name="actualInstance">An instance of Apple.</param>
public Fruit(Apple actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets Cultivar
/// Initializes a new instance of the <see cref="Fruit" /> class
/// with the <see cref="Banana" /> class
/// </summary>
[DataMember(Name = "cultivar", EmitDefaultValue = false)]
public string Cultivar { get; set; }
/// <param name="actualInstance">An instance of Banana.</param>
public Fruit(Banana actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets Origin
/// Gets or Sets ActualInstance
/// </summary>
[DataMember(Name = "origin", EmitDefaultValue = false)]
public string Origin { get; set; }
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(Apple))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Banana))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: Apple, Banana");
}
}
}
/// <summary>
/// Gets or Sets LengthCm
/// Get the actual instance of `Apple`. If the actual instanct is not `Apple`,
/// the InvalidClassException will be thrown
/// </summary>
[DataMember(Name = "lengthCm", EmitDefaultValue = false)]
public decimal LengthCm { get; set; }
/// <returns>An instance of Apple</returns>
public Apple GetApple()
{
return (Apple)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Banana`. If the actual instanct is not `Banana`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Banana</returns>
public Banana GetBanana()
{
return (Banana)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -78,10 +121,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Fruit {\n");
sb.Append(" Color: ").Append(Color).Append("\n");
sb.Append(" Cultivar: ").Append(Cultivar).Append("\n");
sb.Append(" Origin: ").Append(Origin).Append("\n");
sb.Append(" LengthCm: ").Append(LengthCm).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -90,9 +130,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Apple>(jsonString, _serializerSettings);
matchedTypes.Add("Apple");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Banana>(jsonString, _serializerSettings);
matchedTypes.Add("Banana");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -124,13 +211,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.Color != null)
hashCode = hashCode * 59 + this.Color.GetHashCode();
if (this.Cultivar != null)
hashCode = hashCode * 59 + this.Cultivar.GetHashCode();
if (this.Origin != null)
hashCode = hashCode * 59 + this.Origin.GetHashCode();
hashCode = hashCode * 59 + this.LengthCm.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -142,20 +224,6 @@ namespace Org.OpenAPITools.Model
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
// Cultivar (string) pattern
Regex regexCultivar = new Regex(@"^[a-zA-Z\\s]*$", RegexOptions.CultureInvariant);
if (false == regexCultivar.Match(this.Cultivar).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Cultivar, must match a pattern of " + regexCultivar, new [] { "Cultivar" });
}
// Origin (string) pattern
Regex regexOrigin = new Regex(@"^[A-Z\\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexOrigin.Match(this.Origin).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Origin, must match a pattern of " + regexOrigin, new [] { "Origin" });
}
yield break;
}
}

View File

@ -29,52 +29,89 @@ namespace Org.OpenAPITools.Model
/// FruitReq
/// </summary>
[DataContract(Name = "fruitReq")]
public partial class FruitReq : IEquatable<FruitReq>, IValidatableObject
public partial class FruitReq : AbstractOpenAPISchema, IEquatable<FruitReq>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="FruitReq" /> class.
/// </summary>
[JsonConstructorAttribute]
protected FruitReq() { }
/// <summary>
/// Initializes a new instance of the <see cref="FruitReq" /> class.
/// </summary>
/// <param name="cultivar">cultivar (required).</param>
/// <param name="mealy">mealy.</param>
/// <param name="lengthCm">lengthCm (required).</param>
/// <param name="sweet">sweet.</param>
public FruitReq(string cultivar = default(string), bool mealy = default(bool), decimal lengthCm = default(decimal), bool sweet = default(bool))
public FruitReq()
{
// to ensure "cultivar" is required (not null)
this.Cultivar = cultivar ?? throw new ArgumentNullException("cultivar is a required property for FruitReq and cannot be null");
this.LengthCm = lengthCm;
this.Mealy = mealy;
this.Sweet = sweet;
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets Cultivar
/// Initializes a new instance of the <see cref="FruitReq" /> class
/// with the <see cref="AppleReq" /> class
/// </summary>
[DataMember(Name = "cultivar", IsRequired = true, EmitDefaultValue = false)]
public string Cultivar { get; set; }
/// <param name="actualInstance">An instance of AppleReq.</param>
public FruitReq(AppleReq actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
/// <summary>
/// Gets or Sets Mealy
/// Initializes a new instance of the <see cref="FruitReq" /> class
/// with the <see cref="BananaReq" /> class
/// </summary>
[DataMember(Name = "mealy", EmitDefaultValue = false)]
public bool Mealy { get; set; }
/// <param name="actualInstance">An instance of BananaReq.</param>
public FruitReq(BananaReq actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets LengthCm
/// Gets or Sets ActualInstance
/// </summary>
[DataMember(Name = "lengthCm", IsRequired = true, EmitDefaultValue = false)]
public decimal LengthCm { get; set; }
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(AppleReq))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(BananaReq))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: AppleReq, BananaReq");
}
}
}
/// <summary>
/// Gets or Sets Sweet
/// Get the actual instance of `AppleReq`. If the actual instanct is not `AppleReq`,
/// the InvalidClassException will be thrown
/// </summary>
[DataMember(Name = "sweet", EmitDefaultValue = false)]
public bool Sweet { get; set; }
/// <returns>An instance of AppleReq</returns>
public AppleReq GetAppleReq()
{
return (AppleReq)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `BananaReq`. If the actual instanct is not `BananaReq`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of BananaReq</returns>
public BananaReq GetBananaReq()
{
return (BananaReq)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -84,10 +121,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class FruitReq {\n");
sb.Append(" Cultivar: ").Append(Cultivar).Append("\n");
sb.Append(" Mealy: ").Append(Mealy).Append("\n");
sb.Append(" LengthCm: ").Append(LengthCm).Append("\n");
sb.Append(" Sweet: ").Append(Sweet).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -96,9 +130,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<AppleReq>(jsonString, _serializerSettings);
matchedTypes.Add("AppleReq");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<BananaReq>(jsonString, _serializerSettings);
matchedTypes.Add("BananaReq");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -130,11 +211,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.Cultivar != null)
hashCode = hashCode * 59 + this.Cultivar.GetHashCode();
hashCode = hashCode * 59 + this.Mealy.GetHashCode();
hashCode = hashCode * 59 + this.LengthCm.GetHashCode();
hashCode = hashCode * 59 + this.Sweet.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}

View File

@ -30,88 +30,115 @@ namespace Org.OpenAPITools.Model
/// Mammal
/// </summary>
[DataContract(Name = "mammal")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Mammal : IEquatable<Mammal>, IValidatableObject
public partial class Mammal : AbstractOpenAPISchema, IEquatable<Mammal>, IValidatableObject
{
/// <summary>
/// Defines Type
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum TypeEnum
{
/// <summary>
/// Enum Plains for value: plains
/// </summary>
[EnumMember(Value = "plains")]
Plains = 1,
/// <summary>
/// Enum Mountain for value: mountain
/// </summary>
[EnumMember(Value = "mountain")]
Mountain = 2,
/// <summary>
/// Enum Grevys for value: grevys
/// </summary>
[EnumMember(Value = "grevys")]
Grevys = 3
}
/// <summary>
/// Gets or Sets Type
/// </summary>
[DataMember(Name = "type", EmitDefaultValue = false)]
public TypeEnum? Type { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="Mammal" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Mammal()
public Mammal()
{
this.AdditionalProperties = new Dictionary<string, object>();
}
/// <summary>
/// Initializes a new instance of the <see cref="Mammal" /> class.
/// </summary>
/// <param name="hasBaleen">hasBaleen.</param>
/// <param name="hasTeeth">hasTeeth.</param>
/// <param name="className">className (required).</param>
/// <param name="type">type.</param>
public Mammal(bool hasBaleen = default(bool), bool hasTeeth = default(bool), string className = default(string), TypeEnum? type = default(TypeEnum?))
{
// to ensure "className" is required (not null)
this.ClassName = className ?? throw new ArgumentNullException("className is a required property for Mammal and cannot be null");
this.HasBaleen = hasBaleen;
this.HasTeeth = hasTeeth;
this.Type = type;
this.AdditionalProperties = new Dictionary<string, object>();
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets HasBaleen
/// Initializes a new instance of the <see cref="Mammal" /> class
/// with the <see cref="Pig" /> class
/// </summary>
[DataMember(Name = "hasBaleen", EmitDefaultValue = false)]
public bool HasBaleen { get; set; }
/// <param name="actualInstance">An instance of Pig.</param>
public Mammal(Pig actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets HasTeeth
/// Initializes a new instance of the <see cref="Mammal" /> class
/// with the <see cref="Whale" /> class
/// </summary>
[DataMember(Name = "hasTeeth", EmitDefaultValue = false)]
public bool HasTeeth { get; set; }
/// <param name="actualInstance">An instance of Whale.</param>
public Mammal(Whale actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets ClassName
/// Initializes a new instance of the <see cref="Mammal" /> class
/// with the <see cref="Zebra" /> class
/// </summary>
[DataMember(Name = "className", IsRequired = true, EmitDefaultValue = false)]
public string ClassName { get; set; }
/// <param name="actualInstance">An instance of Zebra.</param>
public Mammal(Zebra actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets additional properties
/// Gets or Sets ActualInstance
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalProperties { get; set; }
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(Pig))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Whale))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Zebra))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: Pig, Whale, Zebra");
}
}
}
/// <summary>
/// Get the actual instance of `Pig`. If the actual instanct is not `Pig`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Pig</returns>
public Pig GetPig()
{
return (Pig)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Whale`. If the actual instanct is not `Whale`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Whale</returns>
public Whale GetWhale()
{
return (Whale)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Zebra`. If the actual instanct is not `Zebra`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Zebra</returns>
public Zebra GetZebra()
{
return (Zebra)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -121,11 +148,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Mammal {\n");
sb.Append(" HasBaleen: ").Append(HasBaleen).Append("\n");
sb.Append(" HasTeeth: ").Append(HasTeeth).Append("\n");
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
sb.Append(" Type: ").Append(Type).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -134,9 +157,69 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Pig>(jsonString, _serializerSettings);
matchedTypes.Add("Pig");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Whale>(jsonString, _serializerSettings);
matchedTypes.Add("Whale");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Zebra>(jsonString, _serializerSettings);
matchedTypes.Add("Zebra");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -168,13 +251,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
hashCode = hashCode * 59 + this.HasBaleen.GetHashCode();
hashCode = hashCode * 59 + this.HasTeeth.GetHashCode();
if (this.ClassName != null)
hashCode = hashCode * 59 + this.ClassName.GetHashCode();
hashCode = hashCode * 59 + this.Type.GetHashCode();
if (this.AdditionalProperties != null)
hashCode = hashCode * 59 + this.AdditionalProperties.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -185,16 +263,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,49 +30,89 @@ namespace Org.OpenAPITools.Model
/// 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>
[DataContract(Name = "NullableShape")]
[JsonConverter(typeof(JsonSubtypes), "ShapeType")]
public partial class NullableShape : IEquatable<NullableShape>, IValidatableObject
public partial class NullableShape : AbstractOpenAPISchema, IEquatable<NullableShape>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="NullableShape" /> class.
/// </summary>
[JsonConstructorAttribute]
protected NullableShape()
public NullableShape()
{
this.AdditionalProperties = new Dictionary<string, object>();
}
/// <summary>
/// Initializes a new instance of the <see cref="NullableShape" /> class.
/// </summary>
/// <param name="shapeType">shapeType (required).</param>
/// <param name="quadrilateralType">quadrilateralType (required).</param>
/// <param name="triangleType">triangleType (required).</param>
public NullableShape(string shapeType = default(string), string quadrilateralType = default(string), string triangleType = default(string))
{
// to ensure "shapeType" is required (not null)
this.ShapeType = shapeType ?? throw new ArgumentNullException("shapeType is a required property for NullableShape and cannot be null");
// to ensure "quadrilateralType" is required (not null)
this.QuadrilateralType = quadrilateralType ?? throw new ArgumentNullException("quadrilateralType is a required property for NullableShape and cannot be null");
this.AdditionalProperties = new Dictionary<string, object>();
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ShapeType
/// Initializes a new instance of the <see cref="NullableShape" /> class
/// with the <see cref="Quadrilateral" /> class
/// </summary>
[DataMember(Name = "shapeType", IsRequired = true, EmitDefaultValue = false)]
public string ShapeType { get; set; }
/// <param name="actualInstance">An instance of Quadrilateral.</param>
public NullableShape(Quadrilateral actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
/// <summary>
/// Gets or Sets QuadrilateralType
/// Initializes a new instance of the <see cref="NullableShape" /> class
/// with the <see cref="Triangle" /> class
/// </summary>
[DataMember(Name = "quadrilateralType", IsRequired = true, EmitDefaultValue = false)]
public string QuadrilateralType { get; set; }
/// <param name="actualInstance">An instance of Triangle.</param>
public NullableShape(Triangle actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets additional properties
/// Gets or Sets ActualInstance
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalProperties { get; set; }
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(Quadrilateral))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Triangle))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: Quadrilateral, Triangle");
}
}
}
/// <summary>
/// Get the actual instance of `Quadrilateral`. If the actual instanct is not `Quadrilateral`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Quadrilateral</returns>
public Quadrilateral GetQuadrilateral()
{
return (Quadrilateral)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Triangle`. If the actual instanct is not `Triangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Triangle</returns>
public Triangle GetTriangle()
{
return (Triangle)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -82,9 +122,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class NullableShape {\n");
sb.Append(" ShapeType: ").Append(ShapeType).Append("\n");
sb.Append(" QuadrilateralType: ").Append(QuadrilateralType).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -93,9 +131,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, _serializerSettings);
matchedTypes.Add("Quadrilateral");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, _serializerSettings);
matchedTypes.Add("Triangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -127,12 +212,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ShapeType != null)
hashCode = hashCode * 59 + this.ShapeType.GetHashCode();
if (this.QuadrilateralType != null)
hashCode = hashCode * 59 + this.QuadrilateralType.GetHashCode();
if (this.AdditionalProperties != null)
hashCode = hashCode * 59 + this.AdditionalProperties.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -143,16 +224,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,39 +30,89 @@ namespace Org.OpenAPITools.Model
/// Pig
/// </summary>
[DataContract(Name = "Pig")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Pig : IEquatable<Pig>, IValidatableObject
public partial class Pig : AbstractOpenAPISchema, IEquatable<Pig>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Pig" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Pig()
public Pig()
{
this.AdditionalProperties = new Dictionary<string, object>();
}
/// <summary>
/// Initializes a new instance of the <see cref="Pig" /> class.
/// </summary>
/// <param name="className">className (required).</param>
public Pig(string className = default(string))
{
// to ensure "className" is required (not null)
this.ClassName = className ?? throw new ArgumentNullException("className is a required property for Pig and cannot be null");
this.AdditionalProperties = new Dictionary<string, object>();
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ClassName
/// Initializes a new instance of the <see cref="Pig" /> class
/// with the <see cref="BasquePig" /> class
/// </summary>
[DataMember(Name = "className", IsRequired = true, EmitDefaultValue = false)]
public string ClassName { get; set; }
/// <param name="actualInstance">An instance of BasquePig.</param>
public Pig(BasquePig actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets additional properties
/// Initializes a new instance of the <see cref="Pig" /> class
/// with the <see cref="DanishPig" /> class
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalProperties { get; set; }
/// <param name="actualInstance">An instance of DanishPig.</param>
public Pig(DanishPig actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets ActualInstance
/// </summary>
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(BasquePig))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(DanishPig))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: BasquePig, DanishPig");
}
}
}
/// <summary>
/// Get the actual instance of `BasquePig`. If the actual instanct is not `BasquePig`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of BasquePig</returns>
public BasquePig GetBasquePig()
{
return (BasquePig)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `DanishPig`. If the actual instanct is not `DanishPig`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of DanishPig</returns>
public DanishPig GetDanishPig()
{
return (DanishPig)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -72,8 +122,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Pig {\n");
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -82,9 +131,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<BasquePig>(jsonString, _serializerSettings);
matchedTypes.Add("BasquePig");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<DanishPig>(jsonString, _serializerSettings);
matchedTypes.Add("DanishPig");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -116,10 +212,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ClassName != null)
hashCode = hashCode * 59 + this.ClassName.GetHashCode();
if (this.AdditionalProperties != null)
hashCode = hashCode * 59 + this.AdditionalProperties.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -130,16 +224,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,48 +30,89 @@ namespace Org.OpenAPITools.Model
/// Quadrilateral
/// </summary>
[DataContract(Name = "Quadrilateral")]
[JsonConverter(typeof(JsonSubtypes), "QuadrilateralType")]
public partial class Quadrilateral : IEquatable<Quadrilateral>, IValidatableObject
public partial class Quadrilateral : AbstractOpenAPISchema, IEquatable<Quadrilateral>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Quadrilateral" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Quadrilateral()
public Quadrilateral()
{
this.AdditionalProperties = new Dictionary<string, object>();
}
/// <summary>
/// Initializes a new instance of the <see cref="Quadrilateral" /> class.
/// </summary>
/// <param name="shapeType">shapeType (required).</param>
/// <param name="quadrilateralType">quadrilateralType (required).</param>
public Quadrilateral(string shapeType = default(string), string quadrilateralType = default(string))
{
// to ensure "shapeType" is required (not null)
this.ShapeType = shapeType ?? throw new ArgumentNullException("shapeType is a required property for Quadrilateral and cannot be null");
// to ensure "quadrilateralType" is required (not null)
this.QuadrilateralType = quadrilateralType ?? throw new ArgumentNullException("quadrilateralType is a required property for Quadrilateral and cannot be null");
this.AdditionalProperties = new Dictionary<string, object>();
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ShapeType
/// Initializes a new instance of the <see cref="Quadrilateral" /> class
/// with the <see cref="ComplexQuadrilateral" /> class
/// </summary>
[DataMember(Name = "shapeType", IsRequired = true, EmitDefaultValue = false)]
public string ShapeType { get; set; }
/// <param name="actualInstance">An instance of ComplexQuadrilateral.</param>
public Quadrilateral(ComplexQuadrilateral actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets QuadrilateralType
/// Initializes a new instance of the <see cref="Quadrilateral" /> class
/// with the <see cref="SimpleQuadrilateral" /> class
/// </summary>
[DataMember(Name = "quadrilateralType", IsRequired = true, EmitDefaultValue = false)]
public string QuadrilateralType { get; set; }
/// <param name="actualInstance">An instance of SimpleQuadrilateral.</param>
public Quadrilateral(SimpleQuadrilateral actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets additional properties
/// Gets or Sets ActualInstance
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalProperties { get; set; }
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(ComplexQuadrilateral))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(SimpleQuadrilateral))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: ComplexQuadrilateral, SimpleQuadrilateral");
}
}
}
/// <summary>
/// Get the actual instance of `ComplexQuadrilateral`. If the actual instanct is not `ComplexQuadrilateral`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of ComplexQuadrilateral</returns>
public ComplexQuadrilateral GetComplexQuadrilateral()
{
return (ComplexQuadrilateral)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `SimpleQuadrilateral`. If the actual instanct is not `SimpleQuadrilateral`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of SimpleQuadrilateral</returns>
public SimpleQuadrilateral GetSimpleQuadrilateral()
{
return (SimpleQuadrilateral)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -81,9 +122,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Quadrilateral {\n");
sb.Append(" ShapeType: ").Append(ShapeType).Append("\n");
sb.Append(" QuadrilateralType: ").Append(QuadrilateralType).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -92,9 +131,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<ComplexQuadrilateral>(jsonString, _serializerSettings);
matchedTypes.Add("ComplexQuadrilateral");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<SimpleQuadrilateral>(jsonString, _serializerSettings);
matchedTypes.Add("SimpleQuadrilateral");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -126,12 +212,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ShapeType != null)
hashCode = hashCode * 59 + this.ShapeType.GetHashCode();
if (this.QuadrilateralType != null)
hashCode = hashCode * 59 + this.QuadrilateralType.GetHashCode();
if (this.AdditionalProperties != null)
hashCode = hashCode * 59 + this.AdditionalProperties.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -142,16 +224,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,49 +30,89 @@ namespace Org.OpenAPITools.Model
/// Shape
/// </summary>
[DataContract(Name = "Shape")]
[JsonConverter(typeof(JsonSubtypes), "ShapeType")]
public partial class Shape : IEquatable<Shape>, IValidatableObject
public partial class Shape : AbstractOpenAPISchema, IEquatable<Shape>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Shape" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Shape()
public Shape()
{
this.AdditionalProperties = new Dictionary<string, object>();
}
/// <summary>
/// Initializes a new instance of the <see cref="Shape" /> class.
/// </summary>
/// <param name="shapeType">shapeType (required).</param>
/// <param name="quadrilateralType">quadrilateralType (required).</param>
/// <param name="triangleType">triangleType (required).</param>
public Shape(string shapeType = default(string), string quadrilateralType = default(string), string triangleType = default(string))
{
// to ensure "shapeType" is required (not null)
this.ShapeType = shapeType ?? throw new ArgumentNullException("shapeType is a required property for Shape and cannot be null");
// to ensure "quadrilateralType" is required (not null)
this.QuadrilateralType = quadrilateralType ?? throw new ArgumentNullException("quadrilateralType is a required property for Shape and cannot be null");
this.AdditionalProperties = new Dictionary<string, object>();
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ShapeType
/// Initializes a new instance of the <see cref="Shape" /> class
/// with the <see cref="Quadrilateral" /> class
/// </summary>
[DataMember(Name = "shapeType", IsRequired = true, EmitDefaultValue = false)]
public string ShapeType { get; set; }
/// <param name="actualInstance">An instance of Quadrilateral.</param>
public Shape(Quadrilateral actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets QuadrilateralType
/// Initializes a new instance of the <see cref="Shape" /> class
/// with the <see cref="Triangle" /> class
/// </summary>
[DataMember(Name = "quadrilateralType", IsRequired = true, EmitDefaultValue = false)]
public string QuadrilateralType { get; set; }
/// <param name="actualInstance">An instance of Triangle.</param>
public Shape(Triangle actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets additional properties
/// Gets or Sets ActualInstance
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalProperties { get; set; }
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(Quadrilateral))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Triangle))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: Quadrilateral, Triangle");
}
}
}
/// <summary>
/// Get the actual instance of `Quadrilateral`. If the actual instanct is not `Quadrilateral`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Quadrilateral</returns>
public Quadrilateral GetQuadrilateral()
{
return (Quadrilateral)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Triangle`. If the actual instanct is not `Triangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Triangle</returns>
public Triangle GetTriangle()
{
return (Triangle)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -82,9 +122,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Shape {\n");
sb.Append(" ShapeType: ").Append(ShapeType).Append("\n");
sb.Append(" QuadrilateralType: ").Append(QuadrilateralType).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -93,9 +131,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, _serializerSettings);
matchedTypes.Add("Quadrilateral");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, _serializerSettings);
matchedTypes.Add("Triangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -127,12 +212,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ShapeType != null)
hashCode = hashCode * 59 + this.ShapeType.GetHashCode();
if (this.QuadrilateralType != null)
hashCode = hashCode * 59 + this.QuadrilateralType.GetHashCode();
if (this.AdditionalProperties != null)
hashCode = hashCode * 59 + this.AdditionalProperties.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -143,16 +224,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,49 +30,89 @@ namespace Org.OpenAPITools.Model
/// The value may be a shape or the &#39;null&#39; value. This is introduced in OAS schema &gt;&#x3D; 3.1.
/// </summary>
[DataContract(Name = "ShapeOrNull")]
[JsonConverter(typeof(JsonSubtypes), "ShapeType")]
public partial class ShapeOrNull : IEquatable<ShapeOrNull>, IValidatableObject
public partial class ShapeOrNull : AbstractOpenAPISchema, IEquatable<ShapeOrNull>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="ShapeOrNull" /> class.
/// </summary>
[JsonConstructorAttribute]
protected ShapeOrNull()
public ShapeOrNull()
{
this.AdditionalProperties = new Dictionary<string, object>();
}
/// <summary>
/// Initializes a new instance of the <see cref="ShapeOrNull" /> class.
/// </summary>
/// <param name="shapeType">shapeType (required).</param>
/// <param name="quadrilateralType">quadrilateralType (required).</param>
/// <param name="triangleType">triangleType (required).</param>
public ShapeOrNull(string shapeType = default(string), string quadrilateralType = default(string), string triangleType = default(string))
{
// to ensure "shapeType" is required (not null)
this.ShapeType = shapeType ?? throw new ArgumentNullException("shapeType is a required property for ShapeOrNull and cannot be null");
// to ensure "quadrilateralType" is required (not null)
this.QuadrilateralType = quadrilateralType ?? throw new ArgumentNullException("quadrilateralType is a required property for ShapeOrNull and cannot be null");
this.AdditionalProperties = new Dictionary<string, object>();
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ShapeType
/// Initializes a new instance of the <see cref="ShapeOrNull" /> class
/// with the <see cref="Quadrilateral" /> class
/// </summary>
[DataMember(Name = "shapeType", IsRequired = true, EmitDefaultValue = false)]
public string ShapeType { get; set; }
/// <param name="actualInstance">An instance of Quadrilateral.</param>
public ShapeOrNull(Quadrilateral actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
/// <summary>
/// Gets or Sets QuadrilateralType
/// Initializes a new instance of the <see cref="ShapeOrNull" /> class
/// with the <see cref="Triangle" /> class
/// </summary>
[DataMember(Name = "quadrilateralType", IsRequired = true, EmitDefaultValue = false)]
public string QuadrilateralType { get; set; }
/// <param name="actualInstance">An instance of Triangle.</param>
public ShapeOrNull(Triangle actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets additional properties
/// Gets or Sets ActualInstance
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalProperties { get; set; }
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(Quadrilateral))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Triangle))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: Quadrilateral, Triangle");
}
}
}
/// <summary>
/// Get the actual instance of `Quadrilateral`. If the actual instanct is not `Quadrilateral`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Quadrilateral</returns>
public Quadrilateral GetQuadrilateral()
{
return (Quadrilateral)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Triangle`. If the actual instanct is not `Triangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Triangle</returns>
public Triangle GetTriangle()
{
return (Triangle)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -82,9 +122,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class ShapeOrNull {\n");
sb.Append(" ShapeType: ").Append(ShapeType).Append("\n");
sb.Append(" QuadrilateralType: ").Append(QuadrilateralType).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -93,9 +131,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, _serializerSettings);
matchedTypes.Add("Quadrilateral");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, _serializerSettings);
matchedTypes.Add("Triangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -127,12 +212,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ShapeType != null)
hashCode = hashCode * 59 + this.ShapeType.GetHashCode();
if (this.QuadrilateralType != null)
hashCode = hashCode * 59 + this.QuadrilateralType.GetHashCode();
if (this.AdditionalProperties != null)
hashCode = hashCode * 59 + this.AdditionalProperties.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -143,16 +224,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,48 +30,115 @@ namespace Org.OpenAPITools.Model
/// Triangle
/// </summary>
[DataContract(Name = "Triangle")]
[JsonConverter(typeof(JsonSubtypes), "TriangleType")]
public partial class Triangle : IEquatable<Triangle>, IValidatableObject
public partial class Triangle : AbstractOpenAPISchema, IEquatable<Triangle>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Triangle" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Triangle()
public Triangle()
{
this.AdditionalProperties = new Dictionary<string, object>();
}
/// <summary>
/// Initializes a new instance of the <see cref="Triangle" /> class.
/// </summary>
/// <param name="shapeType">shapeType (required).</param>
/// <param name="triangleType">triangleType (required).</param>
public Triangle(string shapeType = default(string), string triangleType = default(string))
{
// to ensure "shapeType" is required (not null)
this.ShapeType = shapeType ?? throw new ArgumentNullException("shapeType is a required property for Triangle and cannot be null");
// to ensure "triangleType" is required (not null)
this.TriangleType = triangleType ?? throw new ArgumentNullException("triangleType is a required property for Triangle and cannot be null");
this.AdditionalProperties = new Dictionary<string, object>();
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ShapeType
/// Initializes a new instance of the <see cref="Triangle" /> class
/// with the <see cref="EquilateralTriangle" /> class
/// </summary>
[DataMember(Name = "shapeType", IsRequired = true, EmitDefaultValue = false)]
public string ShapeType { get; set; }
/// <param name="actualInstance">An instance of EquilateralTriangle.</param>
public Triangle(EquilateralTriangle actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets TriangleType
/// Initializes a new instance of the <see cref="Triangle" /> class
/// with the <see cref="IsoscelesTriangle" /> class
/// </summary>
[DataMember(Name = "triangleType", IsRequired = true, EmitDefaultValue = false)]
public string TriangleType { get; set; }
/// <param name="actualInstance">An instance of IsoscelesTriangle.</param>
public Triangle(IsoscelesTriangle actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets additional properties
/// Initializes a new instance of the <see cref="Triangle" /> class
/// with the <see cref="ScaleneTriangle" /> class
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalProperties { get; set; }
/// <param name="actualInstance">An instance of ScaleneTriangle.</param>
public Triangle(ScaleneTriangle actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets ActualInstance
/// </summary>
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(EquilateralTriangle))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(IsoscelesTriangle))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(ScaleneTriangle))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: EquilateralTriangle, IsoscelesTriangle, ScaleneTriangle");
}
}
}
/// <summary>
/// Get the actual instance of `EquilateralTriangle`. If the actual instanct is not `EquilateralTriangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of EquilateralTriangle</returns>
public EquilateralTriangle GetEquilateralTriangle()
{
return (EquilateralTriangle)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `IsoscelesTriangle`. If the actual instanct is not `IsoscelesTriangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of IsoscelesTriangle</returns>
public IsoscelesTriangle GetIsoscelesTriangle()
{
return (IsoscelesTriangle)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `ScaleneTriangle`. If the actual instanct is not `ScaleneTriangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of ScaleneTriangle</returns>
public ScaleneTriangle GetScaleneTriangle()
{
return (ScaleneTriangle)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -81,9 +148,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Triangle {\n");
sb.Append(" ShapeType: ").Append(ShapeType).Append("\n");
sb.Append(" TriangleType: ").Append(TriangleType).Append("\n");
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -92,9 +157,69 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<EquilateralTriangle>(jsonString, _serializerSettings);
matchedTypes.Add("EquilateralTriangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<IsoscelesTriangle>(jsonString, _serializerSettings);
matchedTypes.Add("IsoscelesTriangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<ScaleneTriangle>(jsonString, _serializerSettings);
matchedTypes.Add("ScaleneTriangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -126,12 +251,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ShapeType != null)
hashCode = hashCode * 59 + this.ShapeType.GetHashCode();
if (this.TriangleType != null)
hashCode = hashCode * 59 + this.TriangleType.GetHashCode();
if (this.AdditionalProperties != null)
hashCode = hashCode * 59 + this.AdditionalProperties.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -142,16 +263,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -114,6 +114,7 @@ src/Org.OpenAPITools/Client/Multimap.cs
src/Org.OpenAPITools/Client/OpenAPIDateConverter.cs
src/Org.OpenAPITools/Client/RequestOptions.cs
src/Org.OpenAPITools/Client/RetryConfiguration.cs
src/Org.OpenAPITools/Model/AbstractOpenAPISchema.cs
src/Org.OpenAPITools/Model/AdditionalPropertiesClass.cs
src/Org.OpenAPITools/Model/Animal.cs
src/Org.OpenAPITools/Model/ApiResponse.cs

View File

@ -13,15 +13,16 @@ using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Web;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Text;
using System.Threading;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using RestSharp;
@ -65,8 +66,15 @@ namespace Org.OpenAPITools.Client
public string Serialize(object obj)
{
var result = JsonConvert.SerializeObject(obj, _serializerSettings);
return result;
if (obj != null && obj.GetType().IsInstanceOfType(typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema)))
{
// the object to be serialized is an oneOf/anyOf schema
return ((Org.OpenAPITools.Model.AbstractOpenAPISchema)obj).ToJson();
}
else
{
return JsonConvert.SerializeObject(obj, _serializerSettings);
}
}
public T Deserialize<T>(IRestResponse response)
@ -125,9 +133,19 @@ namespace Org.OpenAPITools.Client
// at this point, it must be a model (json)
try
{
if (type.IsInstanceOfType(typeof(Org.OpenAPITools.Model.AbstractOpenAPISchema)))
{
// the response is an oneOf/anyOf schema
Org.OpenAPITools.Model.AbstractOpenAPISchema instance = (Org.OpenAPITools.Model.AbstractOpenAPISchema)Activator.CreateInstance(type);
instance.FromJson(response.Content);
return instance;
}
else
{
return JsonConvert.DeserializeObject(response.Content, type, _serializerSettings);
}
}
catch (Exception e)
{
throw new ApiException(500, e.Message);
@ -442,6 +460,15 @@ 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);
@ -539,6 +566,15 @@ namespace Org.OpenAPITools.Client
response = await client.ExecuteAsync<T>(req, cancellationToken).ConfigureAwait(false);
}
// 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

@ -0,0 +1,61 @@
/*
* OpenAPI Petstore
*
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Org.OpenAPITools.Model
{
/// <summary>
/// Abstract base class for oneOf, anyOf schemas in the OpenAPI specification
/// </summary>
public abstract partial class AbstractOpenAPISchema
{
protected readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
{
// OpenAPI generated types generally hide default constructors.
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
MissingMemberHandling = MissingMemberHandling.Error,
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy
{
OverrideSpecifiedNames = false
}
}
};
/// <summary>
/// Gets or Sets the actual instance
/// </summary>
public abstract Object ActualInstance { get; set; }
/// <summary>
/// Gets or Sets IsNullable to indicate whether the instance is nullable
/// </summary>
public bool IsNullable { get; protected set; }
/// <summary>
/// Gets or Sets the schema type, which can be either `oneOf` or `anyOf`
/// </summary>
public string SchemaType { get; protected set; }
/// <summary>
/// Converts the instance into JSON string.
/// </summary>
public abstract string ToJson();
/// <summary>
/// Converts the JSON string into the instance
/// </summary>
public abstract void FromJson(string jsonString);
}
}

View File

@ -29,46 +29,89 @@ namespace Org.OpenAPITools.Model
/// Fruit
/// </summary>
[DataContract(Name = "fruit")]
public partial class Fruit : IEquatable<Fruit>, IValidatableObject
public partial class Fruit : AbstractOpenAPISchema, IEquatable<Fruit>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Fruit" /> class.
/// </summary>
/// <param name="color">color.</param>
/// <param name="cultivar">cultivar.</param>
/// <param name="origin">origin.</param>
/// <param name="lengthCm">lengthCm.</param>
public Fruit(string color = default(string), string cultivar = default(string), string origin = default(string), decimal lengthCm = default(decimal))
public Fruit()
{
this.Color = color;
this.Cultivar = cultivar;
this.Origin = origin;
this.LengthCm = lengthCm;
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets Color
/// Initializes a new instance of the <see cref="Fruit" /> class
/// with the <see cref="Apple" /> class
/// </summary>
[DataMember(Name = "color", EmitDefaultValue = false)]
public string Color { get; set; }
/// <param name="actualInstance">An instance of Apple.</param>
public Fruit(Apple actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets Cultivar
/// Initializes a new instance of the <see cref="Fruit" /> class
/// with the <see cref="Banana" /> class
/// </summary>
[DataMember(Name = "cultivar", EmitDefaultValue = false)]
public string Cultivar { get; set; }
/// <param name="actualInstance">An instance of Banana.</param>
public Fruit(Banana actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets Origin
/// Gets or Sets ActualInstance
/// </summary>
[DataMember(Name = "origin", EmitDefaultValue = false)]
public string Origin { get; set; }
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(Apple))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Banana))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: Apple, Banana");
}
}
}
/// <summary>
/// Gets or Sets LengthCm
/// Get the actual instance of `Apple`. If the actual instanct is not `Apple`,
/// the InvalidClassException will be thrown
/// </summary>
[DataMember(Name = "lengthCm", EmitDefaultValue = false)]
public decimal LengthCm { get; set; }
/// <returns>An instance of Apple</returns>
public Apple GetApple()
{
return (Apple)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Banana`. If the actual instanct is not `Banana`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Banana</returns>
public Banana GetBanana()
{
return (Banana)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -78,10 +121,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Fruit {\n");
sb.Append(" Color: ").Append(Color).Append("\n");
sb.Append(" Cultivar: ").Append(Cultivar).Append("\n");
sb.Append(" Origin: ").Append(Origin).Append("\n");
sb.Append(" LengthCm: ").Append(LengthCm).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -90,9 +130,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Apple>(jsonString, _serializerSettings);
matchedTypes.Add("Apple");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Banana>(jsonString, _serializerSettings);
matchedTypes.Add("Banana");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -124,13 +211,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.Color != null)
hashCode = hashCode * 59 + this.Color.GetHashCode();
if (this.Cultivar != null)
hashCode = hashCode * 59 + this.Cultivar.GetHashCode();
if (this.Origin != null)
hashCode = hashCode * 59 + this.Origin.GetHashCode();
hashCode = hashCode * 59 + this.LengthCm.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -142,20 +224,6 @@ namespace Org.OpenAPITools.Model
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
// Cultivar (string) pattern
Regex regexCultivar = new Regex(@"^[a-zA-Z\\s]*$", RegexOptions.CultureInvariant);
if (false == regexCultivar.Match(this.Cultivar).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Cultivar, must match a pattern of " + regexCultivar, new [] { "Cultivar" });
}
// Origin (string) pattern
Regex regexOrigin = new Regex(@"^[A-Z\\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexOrigin.Match(this.Origin).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Origin, must match a pattern of " + regexOrigin, new [] { "Origin" });
}
yield break;
}
}

View File

@ -29,52 +29,89 @@ namespace Org.OpenAPITools.Model
/// FruitReq
/// </summary>
[DataContract(Name = "fruitReq")]
public partial class FruitReq : IEquatable<FruitReq>, IValidatableObject
public partial class FruitReq : AbstractOpenAPISchema, IEquatable<FruitReq>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="FruitReq" /> class.
/// </summary>
[JsonConstructorAttribute]
protected FruitReq() { }
/// <summary>
/// Initializes a new instance of the <see cref="FruitReq" /> class.
/// </summary>
/// <param name="cultivar">cultivar (required).</param>
/// <param name="mealy">mealy.</param>
/// <param name="lengthCm">lengthCm (required).</param>
/// <param name="sweet">sweet.</param>
public FruitReq(string cultivar = default(string), bool mealy = default(bool), decimal lengthCm = default(decimal), bool sweet = default(bool))
public FruitReq()
{
// to ensure "cultivar" is required (not null)
this.Cultivar = cultivar ?? throw new ArgumentNullException("cultivar is a required property for FruitReq and cannot be null");
this.LengthCm = lengthCm;
this.Mealy = mealy;
this.Sweet = sweet;
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets Cultivar
/// Initializes a new instance of the <see cref="FruitReq" /> class
/// with the <see cref="AppleReq" /> class
/// </summary>
[DataMember(Name = "cultivar", IsRequired = true, EmitDefaultValue = false)]
public string Cultivar { get; set; }
/// <param name="actualInstance">An instance of AppleReq.</param>
public FruitReq(AppleReq actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
/// <summary>
/// Gets or Sets Mealy
/// Initializes a new instance of the <see cref="FruitReq" /> class
/// with the <see cref="BananaReq" /> class
/// </summary>
[DataMember(Name = "mealy", EmitDefaultValue = false)]
public bool Mealy { get; set; }
/// <param name="actualInstance">An instance of BananaReq.</param>
public FruitReq(BananaReq actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets LengthCm
/// Gets or Sets ActualInstance
/// </summary>
[DataMember(Name = "lengthCm", IsRequired = true, EmitDefaultValue = false)]
public decimal LengthCm { get; set; }
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(AppleReq))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(BananaReq))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: AppleReq, BananaReq");
}
}
}
/// <summary>
/// Gets or Sets Sweet
/// Get the actual instance of `AppleReq`. If the actual instanct is not `AppleReq`,
/// the InvalidClassException will be thrown
/// </summary>
[DataMember(Name = "sweet", EmitDefaultValue = false)]
public bool Sweet { get; set; }
/// <returns>An instance of AppleReq</returns>
public AppleReq GetAppleReq()
{
return (AppleReq)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `BananaReq`. If the actual instanct is not `BananaReq`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of BananaReq</returns>
public BananaReq GetBananaReq()
{
return (BananaReq)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -84,10 +121,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class FruitReq {\n");
sb.Append(" Cultivar: ").Append(Cultivar).Append("\n");
sb.Append(" Mealy: ").Append(Mealy).Append("\n");
sb.Append(" LengthCm: ").Append(LengthCm).Append("\n");
sb.Append(" Sweet: ").Append(Sweet).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -96,9 +130,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<AppleReq>(jsonString, _serializerSettings);
matchedTypes.Add("AppleReq");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<BananaReq>(jsonString, _serializerSettings);
matchedTypes.Add("BananaReq");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -130,11 +211,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.Cultivar != null)
hashCode = hashCode * 59 + this.Cultivar.GetHashCode();
hashCode = hashCode * 59 + this.Mealy.GetHashCode();
hashCode = hashCode * 59 + this.LengthCm.GetHashCode();
hashCode = hashCode * 59 + this.Sweet.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}

View File

@ -30,78 +30,115 @@ namespace Org.OpenAPITools.Model
/// Mammal
/// </summary>
[DataContract(Name = "mammal")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Mammal : IEquatable<Mammal>, IValidatableObject
public partial class Mammal : AbstractOpenAPISchema, IEquatable<Mammal>, IValidatableObject
{
/// <summary>
/// Defines Type
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum TypeEnum
{
/// <summary>
/// Enum Plains for value: plains
/// </summary>
[EnumMember(Value = "plains")]
Plains = 1,
/// <summary>
/// Enum Mountain for value: mountain
/// </summary>
[EnumMember(Value = "mountain")]
Mountain = 2,
/// <summary>
/// Enum Grevys for value: grevys
/// </summary>
[EnumMember(Value = "grevys")]
Grevys = 3
}
/// <summary>
/// Gets or Sets Type
/// </summary>
[DataMember(Name = "type", EmitDefaultValue = false)]
public TypeEnum? Type { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="Mammal" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Mammal() { }
/// <summary>
/// Initializes a new instance of the <see cref="Mammal" /> class.
/// </summary>
/// <param name="hasBaleen">hasBaleen.</param>
/// <param name="hasTeeth">hasTeeth.</param>
/// <param name="className">className (required).</param>
/// <param name="type">type.</param>
public Mammal(bool hasBaleen = default(bool), bool hasTeeth = default(bool), string className = default(string), TypeEnum? type = default(TypeEnum?))
public Mammal()
{
// to ensure "className" is required (not null)
this.ClassName = className ?? throw new ArgumentNullException("className is a required property for Mammal and cannot be null");
this.HasBaleen = hasBaleen;
this.HasTeeth = hasTeeth;
this.Type = type;
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets HasBaleen
/// Initializes a new instance of the <see cref="Mammal" /> class
/// with the <see cref="Pig" /> class
/// </summary>
[DataMember(Name = "hasBaleen", EmitDefaultValue = false)]
public bool HasBaleen { get; set; }
/// <param name="actualInstance">An instance of Pig.</param>
public Mammal(Pig actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets HasTeeth
/// Initializes a new instance of the <see cref="Mammal" /> class
/// with the <see cref="Whale" /> class
/// </summary>
[DataMember(Name = "hasTeeth", EmitDefaultValue = false)]
public bool HasTeeth { get; set; }
/// <param name="actualInstance">An instance of Whale.</param>
public Mammal(Whale actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets ClassName
/// Initializes a new instance of the <see cref="Mammal" /> class
/// with the <see cref="Zebra" /> class
/// </summary>
[DataMember(Name = "className", IsRequired = true, EmitDefaultValue = false)]
public string ClassName { get; set; }
/// <param name="actualInstance">An instance of Zebra.</param>
public Mammal(Zebra actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets ActualInstance
/// </summary>
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(Pig))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Whale))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Zebra))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: Pig, Whale, Zebra");
}
}
}
/// <summary>
/// Get the actual instance of `Pig`. If the actual instanct is not `Pig`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Pig</returns>
public Pig GetPig()
{
return (Pig)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Whale`. If the actual instanct is not `Whale`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Whale</returns>
public Whale GetWhale()
{
return (Whale)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Zebra`. If the actual instanct is not `Zebra`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Zebra</returns>
public Zebra GetZebra()
{
return (Zebra)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -111,10 +148,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Mammal {\n");
sb.Append(" HasBaleen: ").Append(HasBaleen).Append("\n");
sb.Append(" HasTeeth: ").Append(HasTeeth).Append("\n");
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
sb.Append(" Type: ").Append(Type).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -123,9 +157,69 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Pig>(jsonString, _serializerSettings);
matchedTypes.Add("Pig");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Whale>(jsonString, _serializerSettings);
matchedTypes.Add("Whale");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Zebra>(jsonString, _serializerSettings);
matchedTypes.Add("Zebra");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -157,11 +251,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
hashCode = hashCode * 59 + this.HasBaleen.GetHashCode();
hashCode = hashCode * 59 + this.HasTeeth.GetHashCode();
if (this.ClassName != null)
hashCode = hashCode * 59 + this.ClassName.GetHashCode();
hashCode = hashCode * 59 + this.Type.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -172,16 +263,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,39 +30,89 @@ namespace Org.OpenAPITools.Model
/// 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>
[DataContract(Name = "NullableShape")]
[JsonConverter(typeof(JsonSubtypes), "ShapeType")]
public partial class NullableShape : IEquatable<NullableShape>, IValidatableObject
public partial class NullableShape : AbstractOpenAPISchema, IEquatable<NullableShape>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="NullableShape" /> class.
/// </summary>
[JsonConstructorAttribute]
protected NullableShape() { }
/// <summary>
/// Initializes a new instance of the <see cref="NullableShape" /> class.
/// </summary>
/// <param name="shapeType">shapeType (required).</param>
/// <param name="quadrilateralType">quadrilateralType (required).</param>
/// <param name="triangleType">triangleType (required).</param>
public NullableShape(string shapeType = default(string), string quadrilateralType = default(string), string triangleType = default(string))
public NullableShape()
{
// to ensure "shapeType" is required (not null)
this.ShapeType = shapeType ?? throw new ArgumentNullException("shapeType is a required property for NullableShape and cannot be null");
// to ensure "quadrilateralType" is required (not null)
this.QuadrilateralType = quadrilateralType ?? throw new ArgumentNullException("quadrilateralType is a required property for NullableShape and cannot be null");
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ShapeType
/// Initializes a new instance of the <see cref="NullableShape" /> class
/// with the <see cref="Quadrilateral" /> class
/// </summary>
[DataMember(Name = "shapeType", IsRequired = true, EmitDefaultValue = false)]
public string ShapeType { get; set; }
/// <param name="actualInstance">An instance of Quadrilateral.</param>
public NullableShape(Quadrilateral actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
/// <summary>
/// Gets or Sets QuadrilateralType
/// Initializes a new instance of the <see cref="NullableShape" /> class
/// with the <see cref="Triangle" /> class
/// </summary>
[DataMember(Name = "quadrilateralType", IsRequired = true, EmitDefaultValue = false)]
public string QuadrilateralType { get; set; }
/// <param name="actualInstance">An instance of Triangle.</param>
public NullableShape(Triangle actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets ActualInstance
/// </summary>
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(Quadrilateral))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Triangle))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: Quadrilateral, Triangle");
}
}
}
/// <summary>
/// Get the actual instance of `Quadrilateral`. If the actual instanct is not `Quadrilateral`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Quadrilateral</returns>
public Quadrilateral GetQuadrilateral()
{
return (Quadrilateral)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Triangle`. If the actual instanct is not `Triangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Triangle</returns>
public Triangle GetTriangle()
{
return (Triangle)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -72,8 +122,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class NullableShape {\n");
sb.Append(" ShapeType: ").Append(ShapeType).Append("\n");
sb.Append(" QuadrilateralType: ").Append(QuadrilateralType).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -82,9 +131,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, _serializerSettings);
matchedTypes.Add("Quadrilateral");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, _serializerSettings);
matchedTypes.Add("Triangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -116,10 +212,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ShapeType != null)
hashCode = hashCode * 59 + this.ShapeType.GetHashCode();
if (this.QuadrilateralType != null)
hashCode = hashCode * 59 + this.QuadrilateralType.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -130,16 +224,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,29 +30,89 @@ namespace Org.OpenAPITools.Model
/// Pig
/// </summary>
[DataContract(Name = "Pig")]
[JsonConverter(typeof(JsonSubtypes), "ClassName")]
public partial class Pig : IEquatable<Pig>, IValidatableObject
public partial class Pig : AbstractOpenAPISchema, IEquatable<Pig>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Pig" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Pig() { }
/// <summary>
/// Initializes a new instance of the <see cref="Pig" /> class.
/// </summary>
/// <param name="className">className (required).</param>
public Pig(string className = default(string))
public Pig()
{
// to ensure "className" is required (not null)
this.ClassName = className ?? throw new ArgumentNullException("className is a required property for Pig and cannot be null");
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ClassName
/// Initializes a new instance of the <see cref="Pig" /> class
/// with the <see cref="BasquePig" /> class
/// </summary>
[DataMember(Name = "className", IsRequired = true, EmitDefaultValue = false)]
public string ClassName { get; set; }
/// <param name="actualInstance">An instance of BasquePig.</param>
public Pig(BasquePig actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Initializes a new instance of the <see cref="Pig" /> class
/// with the <see cref="DanishPig" /> class
/// </summary>
/// <param name="actualInstance">An instance of DanishPig.</param>
public Pig(DanishPig actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets ActualInstance
/// </summary>
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(BasquePig))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(DanishPig))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: BasquePig, DanishPig");
}
}
}
/// <summary>
/// Get the actual instance of `BasquePig`. If the actual instanct is not `BasquePig`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of BasquePig</returns>
public BasquePig GetBasquePig()
{
return (BasquePig)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `DanishPig`. If the actual instanct is not `DanishPig`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of DanishPig</returns>
public DanishPig GetDanishPig()
{
return (DanishPig)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -62,7 +122,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Pig {\n");
sb.Append(" ClassName: ").Append(ClassName).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -71,9 +131,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<BasquePig>(jsonString, _serializerSettings);
matchedTypes.Add("BasquePig");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<DanishPig>(jsonString, _serializerSettings);
matchedTypes.Add("DanishPig");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -105,8 +212,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ClassName != null)
hashCode = hashCode * 59 + this.ClassName.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -117,16 +224,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,38 +30,89 @@ namespace Org.OpenAPITools.Model
/// Quadrilateral
/// </summary>
[DataContract(Name = "Quadrilateral")]
[JsonConverter(typeof(JsonSubtypes), "QuadrilateralType")]
public partial class Quadrilateral : IEquatable<Quadrilateral>, IValidatableObject
public partial class Quadrilateral : AbstractOpenAPISchema, IEquatable<Quadrilateral>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Quadrilateral" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Quadrilateral() { }
/// <summary>
/// Initializes a new instance of the <see cref="Quadrilateral" /> class.
/// </summary>
/// <param name="shapeType">shapeType (required).</param>
/// <param name="quadrilateralType">quadrilateralType (required).</param>
public Quadrilateral(string shapeType = default(string), string quadrilateralType = default(string))
public Quadrilateral()
{
// to ensure "shapeType" is required (not null)
this.ShapeType = shapeType ?? throw new ArgumentNullException("shapeType is a required property for Quadrilateral and cannot be null");
// to ensure "quadrilateralType" is required (not null)
this.QuadrilateralType = quadrilateralType ?? throw new ArgumentNullException("quadrilateralType is a required property for Quadrilateral and cannot be null");
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ShapeType
/// Initializes a new instance of the <see cref="Quadrilateral" /> class
/// with the <see cref="ComplexQuadrilateral" /> class
/// </summary>
[DataMember(Name = "shapeType", IsRequired = true, EmitDefaultValue = false)]
public string ShapeType { get; set; }
/// <param name="actualInstance">An instance of ComplexQuadrilateral.</param>
public Quadrilateral(ComplexQuadrilateral actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets QuadrilateralType
/// Initializes a new instance of the <see cref="Quadrilateral" /> class
/// with the <see cref="SimpleQuadrilateral" /> class
/// </summary>
[DataMember(Name = "quadrilateralType", IsRequired = true, EmitDefaultValue = false)]
public string QuadrilateralType { get; set; }
/// <param name="actualInstance">An instance of SimpleQuadrilateral.</param>
public Quadrilateral(SimpleQuadrilateral actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets ActualInstance
/// </summary>
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(ComplexQuadrilateral))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(SimpleQuadrilateral))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: ComplexQuadrilateral, SimpleQuadrilateral");
}
}
}
/// <summary>
/// Get the actual instance of `ComplexQuadrilateral`. If the actual instanct is not `ComplexQuadrilateral`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of ComplexQuadrilateral</returns>
public ComplexQuadrilateral GetComplexQuadrilateral()
{
return (ComplexQuadrilateral)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `SimpleQuadrilateral`. If the actual instanct is not `SimpleQuadrilateral`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of SimpleQuadrilateral</returns>
public SimpleQuadrilateral GetSimpleQuadrilateral()
{
return (SimpleQuadrilateral)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -71,8 +122,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Quadrilateral {\n");
sb.Append(" ShapeType: ").Append(ShapeType).Append("\n");
sb.Append(" QuadrilateralType: ").Append(QuadrilateralType).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -81,9 +131,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<ComplexQuadrilateral>(jsonString, _serializerSettings);
matchedTypes.Add("ComplexQuadrilateral");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<SimpleQuadrilateral>(jsonString, _serializerSettings);
matchedTypes.Add("SimpleQuadrilateral");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -115,10 +212,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ShapeType != null)
hashCode = hashCode * 59 + this.ShapeType.GetHashCode();
if (this.QuadrilateralType != null)
hashCode = hashCode * 59 + this.QuadrilateralType.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -129,16 +224,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,39 +30,89 @@ namespace Org.OpenAPITools.Model
/// Shape
/// </summary>
[DataContract(Name = "Shape")]
[JsonConverter(typeof(JsonSubtypes), "ShapeType")]
public partial class Shape : IEquatable<Shape>, IValidatableObject
public partial class Shape : AbstractOpenAPISchema, IEquatable<Shape>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Shape" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Shape() { }
/// <summary>
/// Initializes a new instance of the <see cref="Shape" /> class.
/// </summary>
/// <param name="shapeType">shapeType (required).</param>
/// <param name="quadrilateralType">quadrilateralType (required).</param>
/// <param name="triangleType">triangleType (required).</param>
public Shape(string shapeType = default(string), string quadrilateralType = default(string), string triangleType = default(string))
public Shape()
{
// to ensure "shapeType" is required (not null)
this.ShapeType = shapeType ?? throw new ArgumentNullException("shapeType is a required property for Shape and cannot be null");
// to ensure "quadrilateralType" is required (not null)
this.QuadrilateralType = quadrilateralType ?? throw new ArgumentNullException("quadrilateralType is a required property for Shape and cannot be null");
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ShapeType
/// Initializes a new instance of the <see cref="Shape" /> class
/// with the <see cref="Quadrilateral" /> class
/// </summary>
[DataMember(Name = "shapeType", IsRequired = true, EmitDefaultValue = false)]
public string ShapeType { get; set; }
/// <param name="actualInstance">An instance of Quadrilateral.</param>
public Shape(Quadrilateral actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets QuadrilateralType
/// Initializes a new instance of the <see cref="Shape" /> class
/// with the <see cref="Triangle" /> class
/// </summary>
[DataMember(Name = "quadrilateralType", IsRequired = true, EmitDefaultValue = false)]
public string QuadrilateralType { get; set; }
/// <param name="actualInstance">An instance of Triangle.</param>
public Shape(Triangle actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets ActualInstance
/// </summary>
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(Quadrilateral))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Triangle))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: Quadrilateral, Triangle");
}
}
}
/// <summary>
/// Get the actual instance of `Quadrilateral`. If the actual instanct is not `Quadrilateral`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Quadrilateral</returns>
public Quadrilateral GetQuadrilateral()
{
return (Quadrilateral)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Triangle`. If the actual instanct is not `Triangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Triangle</returns>
public Triangle GetTriangle()
{
return (Triangle)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -72,8 +122,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Shape {\n");
sb.Append(" ShapeType: ").Append(ShapeType).Append("\n");
sb.Append(" QuadrilateralType: ").Append(QuadrilateralType).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -82,9 +131,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, _serializerSettings);
matchedTypes.Add("Quadrilateral");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, _serializerSettings);
matchedTypes.Add("Triangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -116,10 +212,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ShapeType != null)
hashCode = hashCode * 59 + this.ShapeType.GetHashCode();
if (this.QuadrilateralType != null)
hashCode = hashCode * 59 + this.QuadrilateralType.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -130,16 +224,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,39 +30,89 @@ namespace Org.OpenAPITools.Model
/// The value may be a shape or the &#39;null&#39; value. This is introduced in OAS schema &gt;&#x3D; 3.1.
/// </summary>
[DataContract(Name = "ShapeOrNull")]
[JsonConverter(typeof(JsonSubtypes), "ShapeType")]
public partial class ShapeOrNull : IEquatable<ShapeOrNull>, IValidatableObject
public partial class ShapeOrNull : AbstractOpenAPISchema, IEquatable<ShapeOrNull>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="ShapeOrNull" /> class.
/// </summary>
[JsonConstructorAttribute]
protected ShapeOrNull() { }
/// <summary>
/// Initializes a new instance of the <see cref="ShapeOrNull" /> class.
/// </summary>
/// <param name="shapeType">shapeType (required).</param>
/// <param name="quadrilateralType">quadrilateralType (required).</param>
/// <param name="triangleType">triangleType (required).</param>
public ShapeOrNull(string shapeType = default(string), string quadrilateralType = default(string), string triangleType = default(string))
public ShapeOrNull()
{
// to ensure "shapeType" is required (not null)
this.ShapeType = shapeType ?? throw new ArgumentNullException("shapeType is a required property for ShapeOrNull and cannot be null");
// to ensure "quadrilateralType" is required (not null)
this.QuadrilateralType = quadrilateralType ?? throw new ArgumentNullException("quadrilateralType is a required property for ShapeOrNull and cannot be null");
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ShapeType
/// Initializes a new instance of the <see cref="ShapeOrNull" /> class
/// with the <see cref="Quadrilateral" /> class
/// </summary>
[DataMember(Name = "shapeType", IsRequired = true, EmitDefaultValue = false)]
public string ShapeType { get; set; }
/// <param name="actualInstance">An instance of Quadrilateral.</param>
public ShapeOrNull(Quadrilateral actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
/// <summary>
/// Gets or Sets QuadrilateralType
/// Initializes a new instance of the <see cref="ShapeOrNull" /> class
/// with the <see cref="Triangle" /> class
/// </summary>
[DataMember(Name = "quadrilateralType", IsRequired = true, EmitDefaultValue = false)]
public string QuadrilateralType { get; set; }
/// <param name="actualInstance">An instance of Triangle.</param>
public ShapeOrNull(Triangle actualInstance)
{
this.IsNullable = true;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance;
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets ActualInstance
/// </summary>
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(Quadrilateral))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(Triangle))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: Quadrilateral, Triangle");
}
}
}
/// <summary>
/// Get the actual instance of `Quadrilateral`. If the actual instanct is not `Quadrilateral`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Quadrilateral</returns>
public Quadrilateral GetQuadrilateral()
{
return (Quadrilateral)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `Triangle`. If the actual instanct is not `Triangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of Triangle</returns>
public Triangle GetTriangle()
{
return (Triangle)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -72,8 +122,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class ShapeOrNull {\n");
sb.Append(" ShapeType: ").Append(ShapeType).Append("\n");
sb.Append(" QuadrilateralType: ").Append(QuadrilateralType).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -82,9 +131,56 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, _serializerSettings);
matchedTypes.Add("Quadrilateral");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, _serializerSettings);
matchedTypes.Add("Triangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -116,10 +212,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ShapeType != null)
hashCode = hashCode * 59 + this.ShapeType.GetHashCode();
if (this.QuadrilateralType != null)
hashCode = hashCode * 59 + this.QuadrilateralType.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -130,16 +224,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -30,38 +30,115 @@ namespace Org.OpenAPITools.Model
/// Triangle
/// </summary>
[DataContract(Name = "Triangle")]
[JsonConverter(typeof(JsonSubtypes), "TriangleType")]
public partial class Triangle : IEquatable<Triangle>, IValidatableObject
public partial class Triangle : AbstractOpenAPISchema, IEquatable<Triangle>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Triangle" /> class.
/// </summary>
[JsonConstructorAttribute]
protected Triangle() { }
/// <summary>
/// Initializes a new instance of the <see cref="Triangle" /> class.
/// </summary>
/// <param name="shapeType">shapeType (required).</param>
/// <param name="triangleType">triangleType (required).</param>
public Triangle(string shapeType = default(string), string triangleType = default(string))
public Triangle()
{
// to ensure "shapeType" is required (not null)
this.ShapeType = shapeType ?? throw new ArgumentNullException("shapeType is a required property for Triangle and cannot be null");
// to ensure "triangleType" is required (not null)
this.TriangleType = triangleType ?? throw new ArgumentNullException("triangleType is a required property for Triangle and cannot be null");
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary>
/// Gets or Sets ShapeType
/// Initializes a new instance of the <see cref="Triangle" /> class
/// with the <see cref="EquilateralTriangle" /> class
/// </summary>
[DataMember(Name = "shapeType", IsRequired = true, EmitDefaultValue = false)]
public string ShapeType { get; set; }
/// <param name="actualInstance">An instance of EquilateralTriangle.</param>
public Triangle(EquilateralTriangle actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Gets or Sets TriangleType
/// Initializes a new instance of the <see cref="Triangle" /> class
/// with the <see cref="IsoscelesTriangle" /> class
/// </summary>
[DataMember(Name = "triangleType", IsRequired = true, EmitDefaultValue = false)]
public string TriangleType { get; set; }
/// <param name="actualInstance">An instance of IsoscelesTriangle.</param>
public Triangle(IsoscelesTriangle actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
/// <summary>
/// Initializes a new instance of the <see cref="Triangle" /> class
/// with the <see cref="ScaleneTriangle" /> class
/// </summary>
/// <param name="actualInstance">An instance of ScaleneTriangle.</param>
public Triangle(ScaleneTriangle actualInstance)
{
this.IsNullable = false;
this.SchemaType= "oneOf";
this.ActualInstance = actualInstance ?? throw new ArgumentException("Invalid instance found. Must not be null.");
}
private Object _actualInstance;
/// <summary>
/// Gets or Sets ActualInstance
/// </summary>
public override Object ActualInstance
{
get
{
return _actualInstance;
}
set
{
if (value.GetType() == typeof(EquilateralTriangle))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(IsoscelesTriangle))
{
this._actualInstance = value;
}
else if (value.GetType() == typeof(ScaleneTriangle))
{
this._actualInstance = value;
}
else
{
throw new ArgumentException("Invalid instance found. Must be the following types: EquilateralTriangle, IsoscelesTriangle, ScaleneTriangle");
}
}
}
/// <summary>
/// Get the actual instance of `EquilateralTriangle`. If the actual instanct is not `EquilateralTriangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of EquilateralTriangle</returns>
public EquilateralTriangle GetEquilateralTriangle()
{
return (EquilateralTriangle)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `IsoscelesTriangle`. If the actual instanct is not `IsoscelesTriangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of IsoscelesTriangle</returns>
public IsoscelesTriangle GetIsoscelesTriangle()
{
return (IsoscelesTriangle)this.ActualInstance;
}
/// <summary>
/// Get the actual instance of `ScaleneTriangle`. If the actual instanct is not `ScaleneTriangle`,
/// the InvalidClassException will be thrown
/// </summary>
/// <returns>An instance of ScaleneTriangle</returns>
public ScaleneTriangle GetScaleneTriangle()
{
return (ScaleneTriangle)this.ActualInstance;
}
/// <summary>
/// Returns the string presentation of the object
@ -71,8 +148,7 @@ namespace Org.OpenAPITools.Model
{
var sb = new StringBuilder();
sb.Append("class Triangle {\n");
sb.Append(" ShapeType: ").Append(ShapeType).Append("\n");
sb.Append(" TriangleType: ").Append(TriangleType).Append("\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
@ -81,9 +157,69 @@ namespace Org.OpenAPITools.Model
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson()
public override string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings);
}
/// <summary>
/// Converts the JSON string into the object
/// </summary>
/// <param name="jsonString">JSON string</param>
public override void FromJson(string jsonString)
{
int match = 0;
List<string> matchedTypes = new List<string>();
try
{
this.ActualInstance = JsonConvert.DeserializeObject<EquilateralTriangle>(jsonString, _serializerSettings);
matchedTypes.Add("EquilateralTriangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<IsoscelesTriangle>(jsonString, _serializerSettings);
matchedTypes.Add("IsoscelesTriangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
try
{
this.ActualInstance = JsonConvert.DeserializeObject<ScaleneTriangle>(jsonString, _serializerSettings);
matchedTypes.Add("ScaleneTriangle");
match++;
}
catch (Exception exception)
{
// deserialization failed, try the next one
// uncomment the line below for troubleshooting
//Console.WriteLine(exception.ToString());
}
if (match == 0)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
else if (match > 1)
{
throw new InvalidDataException("The JSON string `" + jsonString + "` incorrectly matches more than one schema (should be exactly one match): " + matchedTypes);
}
// deserialization is considered successful at this point if no exception has been thrown.
}
/// <summary>
@ -115,10 +251,8 @@ namespace Org.OpenAPITools.Model
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ShapeType != null)
hashCode = hashCode * 59 + this.ShapeType.GetHashCode();
if (this.TriangleType != null)
hashCode = hashCode * 59 + this.TriangleType.GetHashCode();
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
return hashCode;
}
}
@ -129,16 +263,6 @@ namespace Org.OpenAPITools.Model
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
{
yield break;
}

View File

@ -0,0 +1,68 @@
PATH
remote: .
specs:
petstore (1.0.0)
typhoeus (~> 1.0, >= 1.0.1)
GEM
remote: https://rubygems.org/
specs:
ast (2.4.1)
byebug (11.1.3)
coderay (1.1.3)
diff-lcs (1.4.4)
ethon (0.12.0)
ffi (>= 1.3.0)
ffi (1.13.1)
jaro_winkler (1.5.4)
method_source (1.0.0)
parallel (1.19.2)
parser (2.7.1.5)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
psych (3.2.0)
rainbow (3.0.0)
rake (13.0.1)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
rubocop (0.66.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
psych (>= 3.1.0)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.6)
ruby-progressbar (1.10.1)
typhoeus (1.4.0)
ethon (>= 0.9.0)
unicode-display_width (1.5.0)
PLATFORMS
ruby
DEPENDENCIES
petstore!
pry-byebug
rake (~> 13.0.1)
rspec (~> 3.6, >= 3.6.0)
rubocop (~> 0.66.0)
BUNDLED WITH
1.17.2