forked from loafle/openapi-generator-original
[csharp][netcore] better tests for oneOf with primitive types (#11907)
* update samples * undo changes for generichost
This commit is contained in:
parent
1fe2eb6b7a
commit
571e635a54
@ -1,8 +1,9 @@
|
||||
# for csharp-netcore generichost
|
||||
generatorName: csharp-netcore
|
||||
outputDir: samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature-generichost.yaml
|
||||
library: generichost
|
||||
templateDir: modules/openapi-generator/src/main/resources/csharp-netcore
|
||||
additionalProperties:
|
||||
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||
useCompareNetObjects: true
|
||||
|
@ -1,8 +1,9 @@
|
||||
# for csharp-netcore generichost
|
||||
generatorName: csharp-netcore
|
||||
outputDir: samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature-generichost.yaml
|
||||
library: generichost
|
||||
templateDir: modules/openapi-generator/src/main/resources/csharp-netcore
|
||||
additionalProperties:
|
||||
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||
useCompareNetObjects: true
|
||||
|
@ -1,8 +1,9 @@
|
||||
# for csharp-netcore generichost
|
||||
generatorName: csharp-netcore
|
||||
outputDir: samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-netstandard2.0
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature-generichost.yaml
|
||||
library: generichost
|
||||
templateDir: modules/openapi-generator/src/main/resources/csharp-netcore
|
||||
additionalProperties:
|
||||
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||
useCompareNetObjects: true
|
||||
|
@ -1,7 +1,7 @@
|
||||
# for .net standard httpclient
|
||||
generatorName: csharp-netcore
|
||||
outputDir: samples/client/petstore/csharp-netcore/OpenAPIClient-httpclient
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/csharp-netcore
|
||||
library: httpclient
|
||||
additionalProperties:
|
||||
|
@ -1,7 +1,7 @@
|
||||
# for .net standard
|
||||
generatorName: csharp-netcore
|
||||
outputDir: samples/client/petstore/csharp-netcore/OpenAPIClient-net47
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/csharp-netcore
|
||||
additionalProperties:
|
||||
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||
|
@ -1,7 +1,7 @@
|
||||
# for .net standard
|
||||
generatorName: csharp-netcore
|
||||
outputDir: samples/client/petstore/csharp-netcore/OpenAPIClient-net5.0
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/csharp-netcore
|
||||
additionalProperties:
|
||||
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||
|
@ -1,7 +1,7 @@
|
||||
# for .net standard
|
||||
generatorName: csharp-netcore
|
||||
outputDir: samples/client/petstore/csharp-netcore/OpenAPIClient
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/csharp-netcore
|
||||
additionalProperties:
|
||||
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||
|
@ -1,6 +1,6 @@
|
||||
generatorName: csharp-netcore
|
||||
outputDir: samples/client/petstore/csharp-netcore/OpenAPIClientCore
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/csharp-netcore
|
||||
additionalProperties:
|
||||
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||
|
@ -1,7 +1,7 @@
|
||||
# for .net standard
|
||||
generatorName: csharp-netcore
|
||||
outputDir: samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/java/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/csharp-netcore
|
||||
additionalProperties:
|
||||
packageGuid: '{fa96c953-af24-457d-8a01-f2fd2a7547a9}'
|
||||
@ -9,4 +9,4 @@ additionalProperties:
|
||||
disallowAdditionalPropertiesIfNotPresent: false
|
||||
useOneOfDiscriminatorLookup: true
|
||||
targetFramework: netstandard2.0
|
||||
conditionalSerialization: true
|
||||
conditionalSerialization: true
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -67,6 +67,7 @@ docs/ParentPet.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/Pig.md
|
||||
docs/PolymorphicProperty.md
|
||||
docs/Quadrilateral.md
|
||||
docs/QuadrilateralInterface.md
|
||||
docs/ReadOnlyFirst.md
|
||||
@ -172,6 +173,7 @@ src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs
|
||||
src/Org.OpenAPITools/Model/ParentPet.cs
|
||||
src/Org.OpenAPITools/Model/Pet.cs
|
||||
src/Org.OpenAPITools/Model/Pig.cs
|
||||
src/Org.OpenAPITools/Model/PolymorphicProperty.cs
|
||||
src/Org.OpenAPITools/Model/Quadrilateral.cs
|
||||
src/Org.OpenAPITools/Model/QuadrilateralInterface.cs
|
||||
src/Org.OpenAPITools/Model/ReadOnlyFirst.cs
|
||||
|
@ -207,6 +207,7 @@ Class | Method | HTTP request | Description
|
||||
- [Model.ParentPet](docs/ParentPet.md)
|
||||
- [Model.Pet](docs/Pet.md)
|
||||
- [Model.Pig](docs/Pig.md)
|
||||
- [Model.PolymorphicProperty](docs/PolymorphicProperty.md)
|
||||
- [Model.Quadrilateral](docs/Quadrilateral.md)
|
||||
- [Model.QuadrilateralInterface](docs/QuadrilateralInterface.md)
|
||||
- [Model.ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
|
@ -0,0 +1,9 @@
|
||||
# Org.OpenAPITools.Model.PolymorphicProperty
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 Xunit;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Org.OpenAPITools.Api;
|
||||
using Org.OpenAPITools.Model;
|
||||
using Org.OpenAPITools.Client;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Org.OpenAPITools.Test.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// Class for testing PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
/// Please update the test case below to test the model.
|
||||
/// </remarks>
|
||||
public class PolymorphicPropertyTests : IDisposable
|
||||
{
|
||||
// TODO uncomment below to declare an instance variable for PolymorphicProperty
|
||||
//private PolymorphicProperty instance;
|
||||
|
||||
public PolymorphicPropertyTests()
|
||||
{
|
||||
// TODO uncomment below to create an instance of PolymorphicProperty
|
||||
//instance = new PolymorphicProperty();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Cleanup when everything is done.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void PolymorphicPropertyInstanceTest()
|
||||
{
|
||||
// TODO uncomment below to test "IsType" PolymorphicProperty
|
||||
//Assert.IsType<PolymorphicProperty>(instance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,383 @@
|
||||
/*
|
||||
* 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 System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
|
||||
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Org.OpenAPITools.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// PolymorphicProperty
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(PolymorphicPropertyJsonConverter))]
|
||||
[DataContract(Name = "PolymorphicProperty")]
|
||||
public partial class PolymorphicProperty : AbstractOpenAPISchema, IEquatable<PolymorphicProperty>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="bool" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of bool.</param>
|
||||
public PolymorphicProperty(bool actualInstance)
|
||||
{
|
||||
this.IsNullable = false;
|
||||
this.SchemaType= "oneOf";
|
||||
this.ActualInstance = actualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="string" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of string.</param>
|
||||
public PolymorphicProperty(string 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="Object" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of Object.</param>
|
||||
public PolymorphicProperty(Object 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="List<string>" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of List<string>.</param>
|
||||
public PolymorphicProperty(List<string> 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(List<string>))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(Object))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(bool))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(string))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Invalid instance found. Must be the following types: List<string>, Object, bool, string");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `bool`. If the actual instance is not `bool`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of bool</returns>
|
||||
public bool GetBool()
|
||||
{
|
||||
return (bool)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `string`. If the actual instance is not `string`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of string</returns>
|
||||
public string GetString()
|
||||
{
|
||||
return (string)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `Object`. If the actual instance is not `Object`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of Object</returns>
|
||||
public Object GetObject()
|
||||
{
|
||||
return (Object)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `List<string>`. If the actual instance is not `List<string>`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of List<string></returns>
|
||||
public List<string> GetListString()
|
||||
{
|
||||
return (List<string>)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <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 PolymorphicProperty {\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, PolymorphicProperty.SerializerSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the JSON string into an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <param name="jsonString">JSON string</param>
|
||||
/// <returns>An instance of PolymorphicProperty</returns>
|
||||
public static PolymorphicProperty FromJson(string jsonString)
|
||||
{
|
||||
PolymorphicProperty newPolymorphicProperty = null;
|
||||
|
||||
if (string.IsNullOrEmpty(jsonString))
|
||||
{
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
int match = 0;
|
||||
List<string> matchedTypes = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(List<string>).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("List<string>");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into List<string>: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(Object).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("Object");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into Object: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(bool).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("bool");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into bool: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(string).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("string");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into string: {1}", jsonString, 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.
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input as PolymorphicProperty).AreEqual;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if PolymorphicProperty instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of PolymorphicProperty to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(PolymorphicProperty input)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom JSON converter for PolymorphicProperty
|
||||
/// </summary>
|
||||
public class PolymorphicPropertyJsonConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// To write the JSON string
|
||||
/// </summary>
|
||||
/// <param name="writer">JSON writer</param>
|
||||
/// <param name="value">Object to be converted into a JSON string</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteRawValue((string)(typeof(PolymorphicProperty).GetMethod("ToJson").Invoke(value, null)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To convert a JSON string into an object
|
||||
/// </summary>
|
||||
/// <param name="reader">JSON reader</param>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <param name="existingValue">Existing value</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
/// <returns>The object converted from the JSON string</returns>
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if(reader.TokenType != JsonToken.Null)
|
||||
{
|
||||
return PolymorphicProperty.FromJson(JObject.Load(reader).ToString(Formatting.None));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the object can be converted
|
||||
/// </summary>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <returns>True if the object can be converted</returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -67,6 +67,7 @@ docs/ParentPet.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/Pig.md
|
||||
docs/PolymorphicProperty.md
|
||||
docs/Quadrilateral.md
|
||||
docs/QuadrilateralInterface.md
|
||||
docs/ReadOnlyFirst.md
|
||||
@ -172,6 +173,7 @@ src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs
|
||||
src/Org.OpenAPITools/Model/ParentPet.cs
|
||||
src/Org.OpenAPITools/Model/Pet.cs
|
||||
src/Org.OpenAPITools/Model/Pig.cs
|
||||
src/Org.OpenAPITools/Model/PolymorphicProperty.cs
|
||||
src/Org.OpenAPITools/Model/Quadrilateral.cs
|
||||
src/Org.OpenAPITools/Model/QuadrilateralInterface.cs
|
||||
src/Org.OpenAPITools/Model/ReadOnlyFirst.cs
|
||||
|
@ -232,6 +232,7 @@ Class | Method | HTTP request | Description
|
||||
- [Model.ParentPet](docs/ParentPet.md)
|
||||
- [Model.Pet](docs/Pet.md)
|
||||
- [Model.Pig](docs/Pig.md)
|
||||
- [Model.PolymorphicProperty](docs/PolymorphicProperty.md)
|
||||
- [Model.Quadrilateral](docs/Quadrilateral.md)
|
||||
- [Model.QuadrilateralInterface](docs/QuadrilateralInterface.md)
|
||||
- [Model.ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
|
@ -0,0 +1,9 @@
|
||||
# Org.OpenAPITools.Model.PolymorphicProperty
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 Xunit;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Org.OpenAPITools.Api;
|
||||
using Org.OpenAPITools.Model;
|
||||
using Org.OpenAPITools.Client;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Org.OpenAPITools.Test.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// Class for testing PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
/// Please update the test case below to test the model.
|
||||
/// </remarks>
|
||||
public class PolymorphicPropertyTests : IDisposable
|
||||
{
|
||||
// TODO uncomment below to declare an instance variable for PolymorphicProperty
|
||||
//private PolymorphicProperty instance;
|
||||
|
||||
public PolymorphicPropertyTests()
|
||||
{
|
||||
// TODO uncomment below to create an instance of PolymorphicProperty
|
||||
//instance = new PolymorphicProperty();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Cleanup when everything is done.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void PolymorphicPropertyInstanceTest()
|
||||
{
|
||||
// TODO uncomment below to test "IsType" PolymorphicProperty
|
||||
//Assert.IsType<PolymorphicProperty>(instance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,384 @@
|
||||
/*
|
||||
* 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 System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using FileParameter = Org.OpenAPITools.Client.FileParameter;
|
||||
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
|
||||
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Org.OpenAPITools.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// PolymorphicProperty
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(PolymorphicPropertyJsonConverter))]
|
||||
[DataContract(Name = "PolymorphicProperty")]
|
||||
public partial class PolymorphicProperty : AbstractOpenAPISchema, IEquatable<PolymorphicProperty>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="bool" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of bool.</param>
|
||||
public PolymorphicProperty(bool actualInstance)
|
||||
{
|
||||
this.IsNullable = false;
|
||||
this.SchemaType= "oneOf";
|
||||
this.ActualInstance = actualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="string" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of string.</param>
|
||||
public PolymorphicProperty(string 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="Object" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of Object.</param>
|
||||
public PolymorphicProperty(Object 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="List<string>" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of List<string>.</param>
|
||||
public PolymorphicProperty(List<string> 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(List<string>))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(Object))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(bool))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(string))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Invalid instance found. Must be the following types: List<string>, Object, bool, string");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `bool`. If the actual instance is not `bool`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of bool</returns>
|
||||
public bool GetBool()
|
||||
{
|
||||
return (bool)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `string`. If the actual instance is not `string`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of string</returns>
|
||||
public string GetString()
|
||||
{
|
||||
return (string)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `Object`. If the actual instance is not `Object`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of Object</returns>
|
||||
public Object GetObject()
|
||||
{
|
||||
return (Object)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `List<string>`. If the actual instance is not `List<string>`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of List<string></returns>
|
||||
public List<string> GetListString()
|
||||
{
|
||||
return (List<string>)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <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 PolymorphicProperty {\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, PolymorphicProperty.SerializerSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the JSON string into an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <param name="jsonString">JSON string</param>
|
||||
/// <returns>An instance of PolymorphicProperty</returns>
|
||||
public static PolymorphicProperty FromJson(string jsonString)
|
||||
{
|
||||
PolymorphicProperty newPolymorphicProperty = null;
|
||||
|
||||
if (string.IsNullOrEmpty(jsonString))
|
||||
{
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
int match = 0;
|
||||
List<string> matchedTypes = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(List<string>).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("List<string>");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into List<string>: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(Object).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("Object");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into Object: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(bool).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("bool");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into bool: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(string).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("string");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into string: {1}", jsonString, 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.
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input as PolymorphicProperty).AreEqual;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if PolymorphicProperty instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of PolymorphicProperty to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(PolymorphicProperty input)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom JSON converter for PolymorphicProperty
|
||||
/// </summary>
|
||||
public class PolymorphicPropertyJsonConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// To write the JSON string
|
||||
/// </summary>
|
||||
/// <param name="writer">JSON writer</param>
|
||||
/// <param name="value">Object to be converted into a JSON string</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteRawValue((string)(typeof(PolymorphicProperty).GetMethod("ToJson").Invoke(value, null)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To convert a JSON string into an object
|
||||
/// </summary>
|
||||
/// <param name="reader">JSON reader</param>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <param name="existingValue">Existing value</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
/// <returns>The object converted from the JSON string</returns>
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if(reader.TokenType != JsonToken.Null)
|
||||
{
|
||||
return PolymorphicProperty.FromJson(JObject.Load(reader).ToString(Formatting.None));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the object can be converted
|
||||
/// </summary>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <returns>True if the object can be converted</returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -67,6 +67,7 @@ docs/ParentPet.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/Pig.md
|
||||
docs/PolymorphicProperty.md
|
||||
docs/Quadrilateral.md
|
||||
docs/QuadrilateralInterface.md
|
||||
docs/ReadOnlyFirst.md
|
||||
@ -172,6 +173,7 @@ src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs
|
||||
src/Org.OpenAPITools/Model/ParentPet.cs
|
||||
src/Org.OpenAPITools/Model/Pet.cs
|
||||
src/Org.OpenAPITools/Model/Pig.cs
|
||||
src/Org.OpenAPITools/Model/PolymorphicProperty.cs
|
||||
src/Org.OpenAPITools/Model/Quadrilateral.cs
|
||||
src/Org.OpenAPITools/Model/QuadrilateralInterface.cs
|
||||
src/Org.OpenAPITools/Model/ReadOnlyFirst.cs
|
||||
|
@ -219,6 +219,7 @@ Class | Method | HTTP request | Description
|
||||
- [Model.ParentPet](docs/ParentPet.md)
|
||||
- [Model.Pet](docs/Pet.md)
|
||||
- [Model.Pig](docs/Pig.md)
|
||||
- [Model.PolymorphicProperty](docs/PolymorphicProperty.md)
|
||||
- [Model.Quadrilateral](docs/Quadrilateral.md)
|
||||
- [Model.QuadrilateralInterface](docs/QuadrilateralInterface.md)
|
||||
- [Model.ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
|
@ -0,0 +1,9 @@
|
||||
# Org.OpenAPITools.Model.PolymorphicProperty
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 Xunit;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Org.OpenAPITools.Api;
|
||||
using Org.OpenAPITools.Model;
|
||||
using Org.OpenAPITools.Client;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Org.OpenAPITools.Test.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// Class for testing PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
/// Please update the test case below to test the model.
|
||||
/// </remarks>
|
||||
public class PolymorphicPropertyTests : IDisposable
|
||||
{
|
||||
// TODO uncomment below to declare an instance variable for PolymorphicProperty
|
||||
//private PolymorphicProperty instance;
|
||||
|
||||
public PolymorphicPropertyTests()
|
||||
{
|
||||
// TODO uncomment below to create an instance of PolymorphicProperty
|
||||
//instance = new PolymorphicProperty();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Cleanup when everything is done.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void PolymorphicPropertyInstanceTest()
|
||||
{
|
||||
// TODO uncomment below to test "IsType" PolymorphicProperty
|
||||
//Assert.IsType<PolymorphicProperty>(instance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,383 @@
|
||||
/*
|
||||
* 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 System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
|
||||
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Org.OpenAPITools.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// PolymorphicProperty
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(PolymorphicPropertyJsonConverter))]
|
||||
[DataContract(Name = "PolymorphicProperty")]
|
||||
public partial class PolymorphicProperty : AbstractOpenAPISchema, IEquatable<PolymorphicProperty>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="bool" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of bool.</param>
|
||||
public PolymorphicProperty(bool actualInstance)
|
||||
{
|
||||
this.IsNullable = false;
|
||||
this.SchemaType= "oneOf";
|
||||
this.ActualInstance = actualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="string" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of string.</param>
|
||||
public PolymorphicProperty(string 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="Object" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of Object.</param>
|
||||
public PolymorphicProperty(Object 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="List<string>" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of List<string>.</param>
|
||||
public PolymorphicProperty(List<string> 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(List<string>))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(Object))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(bool))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(string))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Invalid instance found. Must be the following types: List<string>, Object, bool, string");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `bool`. If the actual instance is not `bool`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of bool</returns>
|
||||
public bool GetBool()
|
||||
{
|
||||
return (bool)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `string`. If the actual instance is not `string`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of string</returns>
|
||||
public string GetString()
|
||||
{
|
||||
return (string)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `Object`. If the actual instance is not `Object`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of Object</returns>
|
||||
public Object GetObject()
|
||||
{
|
||||
return (Object)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `List<string>`. If the actual instance is not `List<string>`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of List<string></returns>
|
||||
public List<string> GetListString()
|
||||
{
|
||||
return (List<string>)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <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 PolymorphicProperty {\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, PolymorphicProperty.SerializerSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the JSON string into an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <param name="jsonString">JSON string</param>
|
||||
/// <returns>An instance of PolymorphicProperty</returns>
|
||||
public static PolymorphicProperty FromJson(string jsonString)
|
||||
{
|
||||
PolymorphicProperty newPolymorphicProperty = null;
|
||||
|
||||
if (string.IsNullOrEmpty(jsonString))
|
||||
{
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
int match = 0;
|
||||
List<string> matchedTypes = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(List<string>).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("List<string>");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into List<string>: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(Object).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("Object");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into Object: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(bool).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("bool");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into bool: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(string).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("string");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into string: {1}", jsonString, 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.
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input as PolymorphicProperty).AreEqual;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if PolymorphicProperty instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of PolymorphicProperty to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(PolymorphicProperty input)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom JSON converter for PolymorphicProperty
|
||||
/// </summary>
|
||||
public class PolymorphicPropertyJsonConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// To write the JSON string
|
||||
/// </summary>
|
||||
/// <param name="writer">JSON writer</param>
|
||||
/// <param name="value">Object to be converted into a JSON string</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteRawValue((string)(typeof(PolymorphicProperty).GetMethod("ToJson").Invoke(value, null)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To convert a JSON string into an object
|
||||
/// </summary>
|
||||
/// <param name="reader">JSON reader</param>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <param name="existingValue">Existing value</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
/// <returns>The object converted from the JSON string</returns>
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if(reader.TokenType != JsonToken.Null)
|
||||
{
|
||||
return PolymorphicProperty.FromJson(JObject.Load(reader).ToString(Formatting.None));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the object can be converted
|
||||
/// </summary>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <returns>True if the object can be converted</returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -67,6 +67,7 @@ docs/ParentPet.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/Pig.md
|
||||
docs/PolymorphicProperty.md
|
||||
docs/Quadrilateral.md
|
||||
docs/QuadrilateralInterface.md
|
||||
docs/ReadOnlyFirst.md
|
||||
@ -172,6 +173,7 @@ src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs
|
||||
src/Org.OpenAPITools/Model/ParentPet.cs
|
||||
src/Org.OpenAPITools/Model/Pet.cs
|
||||
src/Org.OpenAPITools/Model/Pig.cs
|
||||
src/Org.OpenAPITools/Model/PolymorphicProperty.cs
|
||||
src/Org.OpenAPITools/Model/Quadrilateral.cs
|
||||
src/Org.OpenAPITools/Model/QuadrilateralInterface.cs
|
||||
src/Org.OpenAPITools/Model/ReadOnlyFirst.cs
|
||||
|
@ -219,6 +219,7 @@ Class | Method | HTTP request | Description
|
||||
- [Model.ParentPet](docs/ParentPet.md)
|
||||
- [Model.Pet](docs/Pet.md)
|
||||
- [Model.Pig](docs/Pig.md)
|
||||
- [Model.PolymorphicProperty](docs/PolymorphicProperty.md)
|
||||
- [Model.Quadrilateral](docs/Quadrilateral.md)
|
||||
- [Model.QuadrilateralInterface](docs/QuadrilateralInterface.md)
|
||||
- [Model.ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
|
@ -0,0 +1,9 @@
|
||||
# Org.OpenAPITools.Model.PolymorphicProperty
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 Xunit;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Org.OpenAPITools.Api;
|
||||
using Org.OpenAPITools.Model;
|
||||
using Org.OpenAPITools.Client;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Org.OpenAPITools.Test.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// Class for testing PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
/// Please update the test case below to test the model.
|
||||
/// </remarks>
|
||||
public class PolymorphicPropertyTests : IDisposable
|
||||
{
|
||||
// TODO uncomment below to declare an instance variable for PolymorphicProperty
|
||||
//private PolymorphicProperty instance;
|
||||
|
||||
public PolymorphicPropertyTests()
|
||||
{
|
||||
// TODO uncomment below to create an instance of PolymorphicProperty
|
||||
//instance = new PolymorphicProperty();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Cleanup when everything is done.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void PolymorphicPropertyInstanceTest()
|
||||
{
|
||||
// TODO uncomment below to test "IsType" PolymorphicProperty
|
||||
//Assert.IsType<PolymorphicProperty>(instance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,383 @@
|
||||
/*
|
||||
* 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 System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
|
||||
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Org.OpenAPITools.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// PolymorphicProperty
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(PolymorphicPropertyJsonConverter))]
|
||||
[DataContract(Name = "PolymorphicProperty")]
|
||||
public partial class PolymorphicProperty : AbstractOpenAPISchema, IEquatable<PolymorphicProperty>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="bool" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of bool.</param>
|
||||
public PolymorphicProperty(bool actualInstance)
|
||||
{
|
||||
this.IsNullable = false;
|
||||
this.SchemaType= "oneOf";
|
||||
this.ActualInstance = actualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="string" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of string.</param>
|
||||
public PolymorphicProperty(string 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="Object" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of Object.</param>
|
||||
public PolymorphicProperty(Object 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="List<string>" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of List<string>.</param>
|
||||
public PolymorphicProperty(List<string> 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(List<string>))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(Object))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(bool))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(string))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Invalid instance found. Must be the following types: List<string>, Object, bool, string");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `bool`. If the actual instance is not `bool`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of bool</returns>
|
||||
public bool GetBool()
|
||||
{
|
||||
return (bool)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `string`. If the actual instance is not `string`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of string</returns>
|
||||
public string GetString()
|
||||
{
|
||||
return (string)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `Object`. If the actual instance is not `Object`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of Object</returns>
|
||||
public Object GetObject()
|
||||
{
|
||||
return (Object)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `List<string>`. If the actual instance is not `List<string>`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of List<string></returns>
|
||||
public List<string> GetListString()
|
||||
{
|
||||
return (List<string>)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <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 PolymorphicProperty {\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, PolymorphicProperty.SerializerSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the JSON string into an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <param name="jsonString">JSON string</param>
|
||||
/// <returns>An instance of PolymorphicProperty</returns>
|
||||
public static PolymorphicProperty FromJson(string jsonString)
|
||||
{
|
||||
PolymorphicProperty newPolymorphicProperty = null;
|
||||
|
||||
if (string.IsNullOrEmpty(jsonString))
|
||||
{
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
int match = 0;
|
||||
List<string> matchedTypes = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(List<string>).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("List<string>");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into List<string>: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(Object).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("Object");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into Object: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(bool).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("bool");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into bool: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(string).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("string");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into string: {1}", jsonString, 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.
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input as PolymorphicProperty).AreEqual;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if PolymorphicProperty instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of PolymorphicProperty to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(PolymorphicProperty input)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom JSON converter for PolymorphicProperty
|
||||
/// </summary>
|
||||
public class PolymorphicPropertyJsonConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// To write the JSON string
|
||||
/// </summary>
|
||||
/// <param name="writer">JSON writer</param>
|
||||
/// <param name="value">Object to be converted into a JSON string</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteRawValue((string)(typeof(PolymorphicProperty).GetMethod("ToJson").Invoke(value, null)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To convert a JSON string into an object
|
||||
/// </summary>
|
||||
/// <param name="reader">JSON reader</param>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <param name="existingValue">Existing value</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
/// <returns>The object converted from the JSON string</returns>
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if(reader.TokenType != JsonToken.Null)
|
||||
{
|
||||
return PolymorphicProperty.FromJson(JObject.Load(reader).ToString(Formatting.None));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the object can be converted
|
||||
/// </summary>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <returns>True if the object can be converted</returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -67,6 +67,7 @@ docs/ParentPet.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/Pig.md
|
||||
docs/PolymorphicProperty.md
|
||||
docs/Quadrilateral.md
|
||||
docs/QuadrilateralInterface.md
|
||||
docs/ReadOnlyFirst.md
|
||||
@ -171,6 +172,7 @@ src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs
|
||||
src/Org.OpenAPITools/Model/ParentPet.cs
|
||||
src/Org.OpenAPITools/Model/Pet.cs
|
||||
src/Org.OpenAPITools/Model/Pig.cs
|
||||
src/Org.OpenAPITools/Model/PolymorphicProperty.cs
|
||||
src/Org.OpenAPITools/Model/Quadrilateral.cs
|
||||
src/Org.OpenAPITools/Model/QuadrilateralInterface.cs
|
||||
src/Org.OpenAPITools/Model/ReadOnlyFirst.cs
|
||||
|
@ -207,6 +207,7 @@ Class | Method | HTTP request | Description
|
||||
- [Model.ParentPet](docs/ParentPet.md)
|
||||
- [Model.Pet](docs/Pet.md)
|
||||
- [Model.Pig](docs/Pig.md)
|
||||
- [Model.PolymorphicProperty](docs/PolymorphicProperty.md)
|
||||
- [Model.Quadrilateral](docs/Quadrilateral.md)
|
||||
- [Model.QuadrilateralInterface](docs/QuadrilateralInterface.md)
|
||||
- [Model.ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
|
@ -0,0 +1,9 @@
|
||||
# Org.OpenAPITools.Model.PolymorphicProperty
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 Xunit;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Org.OpenAPITools.Api;
|
||||
using Org.OpenAPITools.Model;
|
||||
using Org.OpenAPITools.Client;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Org.OpenAPITools.Test.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// Class for testing PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
/// Please update the test case below to test the model.
|
||||
/// </remarks>
|
||||
public class PolymorphicPropertyTests : IDisposable
|
||||
{
|
||||
// TODO uncomment below to declare an instance variable for PolymorphicProperty
|
||||
//private PolymorphicProperty instance;
|
||||
|
||||
public PolymorphicPropertyTests()
|
||||
{
|
||||
// TODO uncomment below to create an instance of PolymorphicProperty
|
||||
//instance = new PolymorphicProperty();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Cleanup when everything is done.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void PolymorphicPropertyInstanceTest()
|
||||
{
|
||||
// TODO uncomment below to test "IsType" PolymorphicProperty
|
||||
//Assert.IsType<PolymorphicProperty>(instance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,383 @@
|
||||
/*
|
||||
* 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 System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
|
||||
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Org.OpenAPITools.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// PolymorphicProperty
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(PolymorphicPropertyJsonConverter))]
|
||||
[DataContract(Name = "PolymorphicProperty")]
|
||||
public partial class PolymorphicProperty : AbstractOpenAPISchema, IEquatable<PolymorphicProperty>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="bool" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of bool.</param>
|
||||
public PolymorphicProperty(bool actualInstance)
|
||||
{
|
||||
this.IsNullable = false;
|
||||
this.SchemaType= "oneOf";
|
||||
this.ActualInstance = actualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="string" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of string.</param>
|
||||
public PolymorphicProperty(string 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="Object" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of Object.</param>
|
||||
public PolymorphicProperty(Object 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="List<string>" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of List<string>.</param>
|
||||
public PolymorphicProperty(List<string> 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(List<string>))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(Object))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(bool))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(string))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Invalid instance found. Must be the following types: List<string>, Object, bool, string");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `bool`. If the actual instance is not `bool`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of bool</returns>
|
||||
public bool GetBool()
|
||||
{
|
||||
return (bool)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `string`. If the actual instance is not `string`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of string</returns>
|
||||
public string GetString()
|
||||
{
|
||||
return (string)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `Object`. If the actual instance is not `Object`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of Object</returns>
|
||||
public Object GetObject()
|
||||
{
|
||||
return (Object)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `List<string>`. If the actual instance is not `List<string>`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of List<string></returns>
|
||||
public List<string> GetListString()
|
||||
{
|
||||
return (List<string>)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <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 PolymorphicProperty {\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, PolymorphicProperty.SerializerSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the JSON string into an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <param name="jsonString">JSON string</param>
|
||||
/// <returns>An instance of PolymorphicProperty</returns>
|
||||
public static PolymorphicProperty FromJson(string jsonString)
|
||||
{
|
||||
PolymorphicProperty newPolymorphicProperty = null;
|
||||
|
||||
if (string.IsNullOrEmpty(jsonString))
|
||||
{
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
int match = 0;
|
||||
List<string> matchedTypes = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(List<string>).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("List<string>");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into List<string>: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(Object).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("Object");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into Object: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(bool).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("bool");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into bool: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(string).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("string");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into string: {1}", jsonString, 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.
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input as PolymorphicProperty).AreEqual;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if PolymorphicProperty instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of PolymorphicProperty to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(PolymorphicProperty input)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom JSON converter for PolymorphicProperty
|
||||
/// </summary>
|
||||
public class PolymorphicPropertyJsonConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// To write the JSON string
|
||||
/// </summary>
|
||||
/// <param name="writer">JSON writer</param>
|
||||
/// <param name="value">Object to be converted into a JSON string</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteRawValue((string)(typeof(PolymorphicProperty).GetMethod("ToJson").Invoke(value, null)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To convert a JSON string into an object
|
||||
/// </summary>
|
||||
/// <param name="reader">JSON reader</param>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <param name="existingValue">Existing value</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
/// <returns>The object converted from the JSON string</returns>
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if(reader.TokenType != JsonToken.Null)
|
||||
{
|
||||
return PolymorphicProperty.FromJson(JObject.Load(reader).ToString(Formatting.None));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the object can be converted
|
||||
/// </summary>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <returns>True if the object can be converted</returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -67,6 +67,7 @@ docs/ParentPet.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/Pig.md
|
||||
docs/PolymorphicProperty.md
|
||||
docs/Quadrilateral.md
|
||||
docs/QuadrilateralInterface.md
|
||||
docs/ReadOnlyFirst.md
|
||||
@ -171,6 +172,7 @@ src/Org.OpenAPITools/Model/OuterEnumIntegerDefaultValue.cs
|
||||
src/Org.OpenAPITools/Model/ParentPet.cs
|
||||
src/Org.OpenAPITools/Model/Pet.cs
|
||||
src/Org.OpenAPITools/Model/Pig.cs
|
||||
src/Org.OpenAPITools/Model/PolymorphicProperty.cs
|
||||
src/Org.OpenAPITools/Model/Quadrilateral.cs
|
||||
src/Org.OpenAPITools/Model/QuadrilateralInterface.cs
|
||||
src/Org.OpenAPITools/Model/ReadOnlyFirst.cs
|
||||
|
@ -219,6 +219,7 @@ Class | Method | HTTP request | Description
|
||||
- [Model.ParentPet](docs/ParentPet.md)
|
||||
- [Model.Pet](docs/Pet.md)
|
||||
- [Model.Pig](docs/Pig.md)
|
||||
- [Model.PolymorphicProperty](docs/PolymorphicProperty.md)
|
||||
- [Model.Quadrilateral](docs/Quadrilateral.md)
|
||||
- [Model.QuadrilateralInterface](docs/QuadrilateralInterface.md)
|
||||
- [Model.ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
|
@ -0,0 +1,9 @@
|
||||
# Org.OpenAPITools.Model.PolymorphicProperty
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 Xunit;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Org.OpenAPITools.Api;
|
||||
using Org.OpenAPITools.Model;
|
||||
using Org.OpenAPITools.Client;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Org.OpenAPITools.Test.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// Class for testing PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
/// Please update the test case below to test the model.
|
||||
/// </remarks>
|
||||
public class PolymorphicPropertyTests : IDisposable
|
||||
{
|
||||
// TODO uncomment below to declare an instance variable for PolymorphicProperty
|
||||
//private PolymorphicProperty instance;
|
||||
|
||||
public PolymorphicPropertyTests()
|
||||
{
|
||||
// TODO uncomment below to create an instance of PolymorphicProperty
|
||||
//instance = new PolymorphicProperty();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Cleanup when everything is done.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void PolymorphicPropertyInstanceTest()
|
||||
{
|
||||
// TODO uncomment below to test "IsType" PolymorphicProperty
|
||||
//Assert.IsType<PolymorphicProperty>(instance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,383 @@
|
||||
/*
|
||||
* 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 System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using OpenAPIDateConverter = Org.OpenAPITools.Client.OpenAPIDateConverter;
|
||||
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Org.OpenAPITools.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// PolymorphicProperty
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(PolymorphicPropertyJsonConverter))]
|
||||
[DataContract(Name = "PolymorphicProperty")]
|
||||
public partial class PolymorphicProperty : AbstractOpenAPISchema, IEquatable<PolymorphicProperty>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="bool" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of bool.</param>
|
||||
public PolymorphicProperty(bool actualInstance)
|
||||
{
|
||||
this.IsNullable = false;
|
||||
this.SchemaType= "oneOf";
|
||||
this.ActualInstance = actualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PolymorphicProperty" /> class
|
||||
/// with the <see cref="string" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of string.</param>
|
||||
public PolymorphicProperty(string 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="Object" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of Object.</param>
|
||||
public PolymorphicProperty(Object 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="PolymorphicProperty" /> class
|
||||
/// with the <see cref="List<string>" /> class
|
||||
/// </summary>
|
||||
/// <param name="actualInstance">An instance of List<string>.</param>
|
||||
public PolymorphicProperty(List<string> 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(List<string>))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(Object))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(bool))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else if (value.GetType() == typeof(string))
|
||||
{
|
||||
this._actualInstance = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Invalid instance found. Must be the following types: List<string>, Object, bool, string");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `bool`. If the actual instance is not `bool`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of bool</returns>
|
||||
public bool GetBool()
|
||||
{
|
||||
return (bool)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `string`. If the actual instance is not `string`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of string</returns>
|
||||
public string GetString()
|
||||
{
|
||||
return (string)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `Object`. If the actual instance is not `Object`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of Object</returns>
|
||||
public Object GetObject()
|
||||
{
|
||||
return (Object)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the actual instance of `List<string>`. If the actual instance is not `List<string>`,
|
||||
/// the InvalidClassException will be thrown
|
||||
/// </summary>
|
||||
/// <returns>An instance of List<string></returns>
|
||||
public List<string> GetListString()
|
||||
{
|
||||
return (List<string>)this.ActualInstance;
|
||||
}
|
||||
|
||||
/// <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 PolymorphicProperty {\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, PolymorphicProperty.SerializerSettings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the JSON string into an instance of PolymorphicProperty
|
||||
/// </summary>
|
||||
/// <param name="jsonString">JSON string</param>
|
||||
/// <returns>An instance of PolymorphicProperty</returns>
|
||||
public static PolymorphicProperty FromJson(string jsonString)
|
||||
{
|
||||
PolymorphicProperty newPolymorphicProperty = null;
|
||||
|
||||
if (string.IsNullOrEmpty(jsonString))
|
||||
{
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
int match = 0;
|
||||
List<string> matchedTypes = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(List<string>).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<List<string>>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("List<string>");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into List<string>: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(Object).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<Object>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("Object");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into Object: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(bool).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<bool>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("bool");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into bool: {1}", jsonString, exception.ToString()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if it does not contains "AdditionalProperties", use SerializerSettings to deserialize
|
||||
if (typeof(string).GetProperty("AdditionalProperties") == null)
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.SerializerSettings));
|
||||
}
|
||||
else
|
||||
{
|
||||
newPolymorphicProperty = new PolymorphicProperty(JsonConvert.DeserializeObject<string>(jsonString, PolymorphicProperty.AdditionalPropertiesSerializerSettings));
|
||||
}
|
||||
matchedTypes.Add("string");
|
||||
match++;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// deserialization failed, try the next one
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("Failed to deserialize `{0}` into string: {1}", jsonString, 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.
|
||||
return newPolymorphicProperty;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input as PolymorphicProperty).AreEqual;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if PolymorphicProperty instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of PolymorphicProperty to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(PolymorphicProperty input)
|
||||
{
|
||||
return OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom JSON converter for PolymorphicProperty
|
||||
/// </summary>
|
||||
public class PolymorphicPropertyJsonConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// To write the JSON string
|
||||
/// </summary>
|
||||
/// <param name="writer">JSON writer</param>
|
||||
/// <param name="value">Object to be converted into a JSON string</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteRawValue((string)(typeof(PolymorphicProperty).GetMethod("ToJson").Invoke(value, null)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To convert a JSON string into an object
|
||||
/// </summary>
|
||||
/// <param name="reader">JSON reader</param>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <param name="existingValue">Existing value</param>
|
||||
/// <param name="serializer">JSON Serializer</param>
|
||||
/// <returns>The object converted from the JSON string</returns>
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if(reader.TokenType != JsonToken.Null)
|
||||
{
|
||||
return PolymorphicProperty.FromJson(JObject.Load(reader).ToString(Formatting.None));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the object can be converted
|
||||
/// </summary>
|
||||
/// <param name="objectType">Object type</param>
|
||||
/// <returns>True if the object can be converted</returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user