mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-05-17 00:21:19 +00:00
[csharp] Update JsonSubTypes to 1.1.3 and use nuget dependency (#6969)
* the result I want to obtain * add csharp-petstore-net-40.bat for windows * just ran bin\windows\csharp-petstore-all.bat * Removed those directories: - samples\client\petstore\csharp - samples\client\petstore\csharp-dotnet2 then ran : bin\windows\csharp-petstore-all.bat * - update JsonSubTypes to 1.1.3 by using nuget dependency (the package is compatible with net40) - allign all version of Newtonsoft.Json to 10.0.3 * the result of bin\windows\csharp-petstore-all.bat * ran bin\security\windows\csharp-petstore.bat
This commit is contained in:
@@ -1,331 +0,0 @@
|
||||
/*
|
||||
* Swagger 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: \" \\
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
* Contact: apiteam@swagger.io
|
||||
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using RestSharp.Portable;
|
||||
using IO.Swagger.Client;
|
||||
using IO.Swagger.Model;
|
||||
|
||||
namespace IO.Swagger.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of functions to interact with the API endpoints
|
||||
/// </summary>
|
||||
public interface IFake_classname_tags123Api : IApiAccessor
|
||||
{
|
||||
#region Synchronous Operations
|
||||
/// <summary>
|
||||
/// To test class name in snake case
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="body">client model</param>
|
||||
/// <returns>ModelClient</returns>
|
||||
ModelClient TestClassname (ModelClient body);
|
||||
|
||||
/// <summary>
|
||||
/// To test class name in snake case
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="body">client model</param>
|
||||
/// <returns>ApiResponse of ModelClient</returns>
|
||||
ApiResponse<ModelClient> TestClassnameWithHttpInfo (ModelClient body);
|
||||
#endregion Synchronous Operations
|
||||
#region Asynchronous Operations
|
||||
/// <summary>
|
||||
/// To test class name in snake case
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="body">client model</param>
|
||||
/// <returns>Task of ModelClient</returns>
|
||||
System.Threading.Tasks.Task<ModelClient> TestClassnameAsync (ModelClient body);
|
||||
|
||||
/// <summary>
|
||||
/// To test class name in snake case
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="body">client model</param>
|
||||
/// <returns>Task of ApiResponse (ModelClient)</returns>
|
||||
System.Threading.Tasks.Task<ApiResponse<ModelClient>> TestClassnameAsyncWithHttpInfo (ModelClient body);
|
||||
#endregion Asynchronous Operations
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a collection of functions to interact with the API endpoints
|
||||
/// </summary>
|
||||
public partial class Fake_classname_tags123Api : IFake_classname_tags123Api
|
||||
{
|
||||
private IO.Swagger.Client.ExceptionFactory _exceptionFactory = (name, response) => null;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fake_classname_tags123Api"/> class.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Fake_classname_tags123Api(String basePath)
|
||||
{
|
||||
this.Configuration = new Configuration { BasePath = basePath };
|
||||
|
||||
ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fake_classname_tags123Api"/> class
|
||||
/// using Configuration object
|
||||
/// </summary>
|
||||
/// <param name="configuration">An instance of Configuration</param>
|
||||
/// <returns></returns>
|
||||
public Fake_classname_tags123Api(Configuration configuration = null)
|
||||
{
|
||||
if (configuration == null) // use the default one in Configuration
|
||||
this.Configuration = Configuration.Default;
|
||||
else
|
||||
this.Configuration = configuration;
|
||||
|
||||
ExceptionFactory = IO.Swagger.Client.Configuration.DefaultExceptionFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
public String GetBasePath()
|
||||
{
|
||||
return this.Configuration.ApiClient.RestClient.BaseUrl.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
[Obsolete("SetBasePath is deprecated, please do 'Configuration.ApiClient = new ApiClient(\"http://new-path\")' instead.")]
|
||||
public void SetBasePath(String basePath)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the configuration object
|
||||
/// </summary>
|
||||
/// <value>An instance of the Configuration</value>
|
||||
public Configuration Configuration {get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// Provides a factory method hook for the creation of exceptions.
|
||||
/// </summary>
|
||||
public IO.Swagger.Client.ExceptionFactory ExceptionFactory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1)
|
||||
{
|
||||
throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported.");
|
||||
}
|
||||
return _exceptionFactory;
|
||||
}
|
||||
set { _exceptionFactory = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default header.
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of HTTP header</returns>
|
||||
[Obsolete("DefaultHeader is deprecated, please use Configuration.DefaultHeader instead.")]
|
||||
public IDictionary<String, String> DefaultHeader()
|
||||
{
|
||||
return new ReadOnlyDictionary<string, string>(this.Configuration.DefaultHeader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add default header.
|
||||
/// </summary>
|
||||
/// <param name="key">Header field name.</param>
|
||||
/// <param name="value">Header field value.</param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("AddDefaultHeader is deprecated, please use Configuration.AddDefaultHeader instead.")]
|
||||
public void AddDefaultHeader(string key, string value)
|
||||
{
|
||||
this.Configuration.AddDefaultHeader(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To test class name in snake case
|
||||
/// </summary>
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="body">client model</param>
|
||||
/// <returns>ModelClient</returns>
|
||||
public ModelClient TestClassname (ModelClient body)
|
||||
{
|
||||
ApiResponse<ModelClient> localVarResponse = TestClassnameWithHttpInfo(body);
|
||||
return localVarResponse.Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To test class name in snake case
|
||||
/// </summary>
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="body">client model</param>
|
||||
/// <returns>ApiResponse of ModelClient</returns>
|
||||
public ApiResponse< ModelClient > TestClassnameWithHttpInfo (ModelClient body)
|
||||
{
|
||||
// verify the required parameter 'body' is set
|
||||
if (body == null)
|
||||
throw new ApiException(400, "Missing required parameter 'body' when calling Fake_classname_tags123Api->TestClassname");
|
||||
|
||||
var localVarPath = "./fake_classname_test";
|
||||
var localVarPathParams = new Dictionary<String, String>();
|
||||
var localVarQueryParams = new List<KeyValuePair<String, String>>();
|
||||
var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
||||
var localVarFormParams = new Dictionary<String, String>();
|
||||
var localVarFileParams = new Dictionary<String, FileParameter>();
|
||||
Object localVarPostBody = null;
|
||||
|
||||
// to determine the Content-Type header
|
||||
String[] localVarHttpContentTypes = new String[] {
|
||||
"application/json"
|
||||
};
|
||||
String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);
|
||||
|
||||
// to determine the Accept header
|
||||
String[] localVarHttpHeaderAccepts = new String[] {
|
||||
"application/json"
|
||||
};
|
||||
String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);
|
||||
if (localVarHttpHeaderAccept != null)
|
||||
localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
|
||||
|
||||
if (body != null && body.GetType() != typeof(byte[]))
|
||||
{
|
||||
localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter
|
||||
}
|
||||
else
|
||||
{
|
||||
localVarPostBody = body; // byte array
|
||||
}
|
||||
|
||||
// authentication (api_key_query) required
|
||||
if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key_query")))
|
||||
{
|
||||
localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "api_key_query", Configuration.GetApiKeyWithPrefix("api_key_query")));
|
||||
}
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse localVarResponse = (IRestResponse) Configuration.ApiClient.CallApi(localVarPath,
|
||||
Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
|
||||
localVarPathParams, localVarHttpContentType);
|
||||
|
||||
int localVarStatusCode = (int) localVarResponse.StatusCode;
|
||||
|
||||
if (ExceptionFactory != null)
|
||||
{
|
||||
Exception exception = ExceptionFactory("TestClassname", localVarResponse);
|
||||
if (exception != null) throw exception;
|
||||
}
|
||||
|
||||
return new ApiResponse<ModelClient>(localVarStatusCode,
|
||||
localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()),
|
||||
(ModelClient) Configuration.ApiClient.Deserialize(localVarResponse, typeof(ModelClient)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To test class name in snake case
|
||||
/// </summary>
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="body">client model</param>
|
||||
/// <returns>Task of ModelClient</returns>
|
||||
public async System.Threading.Tasks.Task<ModelClient> TestClassnameAsync (ModelClient body)
|
||||
{
|
||||
ApiResponse<ModelClient> localVarResponse = await TestClassnameAsyncWithHttpInfo(body);
|
||||
return localVarResponse.Data;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To test class name in snake case
|
||||
/// </summary>
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="body">client model</param>
|
||||
/// <returns>Task of ApiResponse (ModelClient)</returns>
|
||||
public async System.Threading.Tasks.Task<ApiResponse<ModelClient>> TestClassnameAsyncWithHttpInfo (ModelClient body)
|
||||
{
|
||||
// verify the required parameter 'body' is set
|
||||
if (body == null)
|
||||
throw new ApiException(400, "Missing required parameter 'body' when calling Fake_classname_tags123Api->TestClassname");
|
||||
|
||||
var localVarPath = "./fake_classname_test";
|
||||
var localVarPathParams = new Dictionary<String, String>();
|
||||
var localVarQueryParams = new List<KeyValuePair<String, String>>();
|
||||
var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader);
|
||||
var localVarFormParams = new Dictionary<String, String>();
|
||||
var localVarFileParams = new Dictionary<String, FileParameter>();
|
||||
Object localVarPostBody = null;
|
||||
|
||||
// to determine the Content-Type header
|
||||
String[] localVarHttpContentTypes = new String[] {
|
||||
"application/json"
|
||||
};
|
||||
String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);
|
||||
|
||||
// to determine the Accept header
|
||||
String[] localVarHttpHeaderAccepts = new String[] {
|
||||
"application/json"
|
||||
};
|
||||
String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);
|
||||
if (localVarHttpHeaderAccept != null)
|
||||
localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
|
||||
|
||||
if (body != null && body.GetType() != typeof(byte[]))
|
||||
{
|
||||
localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter
|
||||
}
|
||||
else
|
||||
{
|
||||
localVarPostBody = body; // byte array
|
||||
}
|
||||
|
||||
// authentication (api_key_query) required
|
||||
if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key_query")))
|
||||
{
|
||||
localVarQueryParams.AddRange(Configuration.ApiClient.ParameterToKeyValuePairs("", "api_key_query", Configuration.GetApiKeyWithPrefix("api_key_query")));
|
||||
}
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath,
|
||||
Method.PATCH, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
|
||||
localVarPathParams, localVarHttpContentType);
|
||||
|
||||
int localVarStatusCode = (int) localVarResponse.StatusCode;
|
||||
|
||||
if (ExceptionFactory != null)
|
||||
{
|
||||
Exception exception = ExceptionFactory("TestClassname", localVarResponse);
|
||||
if (exception != null) throw exception;
|
||||
}
|
||||
|
||||
return new ApiResponse<ModelClient>(localVarStatusCode,
|
||||
localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()),
|
||||
(ModelClient) Configuration.ApiClient.Deserialize(localVarResponse, typeof(ModelClient)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,272 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace JsonSubTypes
|
||||
{
|
||||
// Copied from project https://github.com/manuc66/JsonSubTypes
|
||||
// https://raw.githubusercontent.com/manuc66/JsonSubTypes/07403192ea3f4959f6d42f5966ac56ceb0d6095b/JsonSubTypes/JsonSubtypes.cs
|
||||
|
||||
public class JsonSubtypes : JsonConverter
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||
public class KnownSubTypeAttribute : Attribute
|
||||
{
|
||||
public Type SubType { get; private set; }
|
||||
public object AssociatedValue { get; private set; }
|
||||
|
||||
public KnownSubTypeAttribute(Type subType, object associatedValue)
|
||||
{
|
||||
SubType = subType;
|
||||
AssociatedValue = associatedValue;
|
||||
}
|
||||
}
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
|
||||
public class KnownSubTypeWithPropertyAttribute : Attribute
|
||||
{
|
||||
public Type SubType { get; private set; }
|
||||
public string PropertyName { get; private set; }
|
||||
|
||||
public KnownSubTypeWithPropertyAttribute(Type subType, string propertyName)
|
||||
{
|
||||
SubType = subType;
|
||||
PropertyName = propertyName;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly string _typeMappingPropertyName;
|
||||
|
||||
private bool _isInsideRead;
|
||||
private JsonReader _reader;
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_isInsideRead)
|
||||
return true;
|
||||
|
||||
return !string.IsNullOrEmpty(_reader.Path);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed override bool CanWrite
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public JsonSubtypes()
|
||||
{
|
||||
}
|
||||
|
||||
public JsonSubtypes(string typeMappingPropertyName)
|
||||
{
|
||||
_typeMappingPropertyName = typeMappingPropertyName;
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return _typeMappingPropertyName != null;
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.Comment)
|
||||
reader.Read();
|
||||
|
||||
switch (reader.TokenType)
|
||||
{
|
||||
case JsonToken.Null:
|
||||
return null;
|
||||
case JsonToken.StartArray:
|
||||
return ReadArray(reader, objectType, serializer);
|
||||
case JsonToken.StartObject:
|
||||
return ReadObject(reader, objectType, serializer);
|
||||
default:
|
||||
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||
}
|
||||
}
|
||||
|
||||
private IList ReadArray(JsonReader reader, Type targetType, JsonSerializer serializer)
|
||||
{
|
||||
var elementType = GetElementType(targetType);
|
||||
|
||||
var list = CreateCompatibleList(targetType, elementType);
|
||||
|
||||
while (reader.TokenType != JsonToken.EndArray && reader.Read())
|
||||
{
|
||||
switch (reader.TokenType)
|
||||
{
|
||||
case JsonToken.Null:
|
||||
list.Add(reader.Value);
|
||||
break;
|
||||
case JsonToken.Comment:
|
||||
break;
|
||||
case JsonToken.StartObject:
|
||||
list.Add(ReadObject(reader, elementType, serializer));
|
||||
break;
|
||||
case JsonToken.EndArray:
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Array: Unrecognized token: " + reader.TokenType);
|
||||
}
|
||||
}
|
||||
if (targetType.IsArray)
|
||||
{
|
||||
var array = Array.CreateInstance(targetType.GetElementType(), list.Count);
|
||||
list.CopyTo(array, 0);
|
||||
list = array;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static IList CreateCompatibleList(Type targetContainerType, Type elementType)
|
||||
{
|
||||
IList list;
|
||||
if (targetContainerType.IsArray || targetContainerType.GetTypeInfo().IsAbstract)
|
||||
{
|
||||
list = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType));
|
||||
}
|
||||
else
|
||||
{
|
||||
list = (IList)Activator.CreateInstance(targetContainerType);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static Type GetElementType(Type arrayOrGenericContainer)
|
||||
{
|
||||
Type elementType;
|
||||
if (arrayOrGenericContainer.IsArray)
|
||||
{
|
||||
elementType = arrayOrGenericContainer.GetElementType();
|
||||
}
|
||||
else
|
||||
{
|
||||
elementType = arrayOrGenericContainer.GenericTypeArguments[0];
|
||||
}
|
||||
return elementType;
|
||||
}
|
||||
|
||||
private object ReadObject(JsonReader reader, Type objectType, JsonSerializer serializer)
|
||||
{
|
||||
var jObject = JObject.Load(reader);
|
||||
|
||||
var targetType = GetType(jObject, objectType) ?? objectType;
|
||||
|
||||
return _ReadJson(CreateAnotherReader(jObject, reader), targetType, null, serializer);
|
||||
}
|
||||
|
||||
private static JsonReader CreateAnotherReader(JObject jObject, JsonReader reader)
|
||||
{
|
||||
var jObjectReader = jObject.CreateReader();
|
||||
jObjectReader.Culture = reader.Culture;
|
||||
jObjectReader.CloseInput = reader.CloseInput;
|
||||
jObjectReader.SupportMultipleContent = reader.SupportMultipleContent;
|
||||
jObjectReader.DateTimeZoneHandling = reader.DateTimeZoneHandling;
|
||||
jObjectReader.FloatParseHandling = reader.FloatParseHandling;
|
||||
jObjectReader.DateFormatString = reader.DateFormatString;
|
||||
jObjectReader.DateParseHandling = reader.DateParseHandling;
|
||||
return jObjectReader;
|
||||
}
|
||||
|
||||
public Type GetType(JObject jObject, Type parentType)
|
||||
{
|
||||
if (_typeMappingPropertyName == null)
|
||||
{
|
||||
return GetTypeByPropertyPresence(jObject, parentType);
|
||||
}
|
||||
return GetTypeFromDiscriminatorValue(jObject, parentType);
|
||||
}
|
||||
|
||||
private static Type GetTypeByPropertyPresence(JObject jObject, Type parentType)
|
||||
{
|
||||
foreach (var type in parentType.GetTypeInfo().GetCustomAttributes<KnownSubTypeWithPropertyAttribute>())
|
||||
{
|
||||
JToken ignore;
|
||||
if (jObject.TryGetValue(type.PropertyName, out ignore))
|
||||
{
|
||||
return type.SubType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Type GetTypeFromDiscriminatorValue(JObject jObject, Type parentType)
|
||||
{
|
||||
JToken jToken;
|
||||
if (!jObject.TryGetValue(_typeMappingPropertyName, out jToken)) return null;
|
||||
|
||||
var discriminatorValue = jToken.ToObject<object>();
|
||||
if (discriminatorValue == null) return null;
|
||||
|
||||
var typeMapping = GetSubTypeMapping(parentType);
|
||||
if (typeMapping.Any())
|
||||
{
|
||||
return GetTypeFromMapping(typeMapping, discriminatorValue);
|
||||
}
|
||||
return GetTypeByName(discriminatorValue as string, parentType);
|
||||
}
|
||||
|
||||
private static Type GetTypeByName(string typeName, Type parentType)
|
||||
{
|
||||
if (typeName == null)
|
||||
return null;
|
||||
|
||||
var insideAssembly = parentType.GetTypeInfo().Assembly;
|
||||
|
||||
var typeByName = insideAssembly.GetType(typeName);
|
||||
if (typeByName == null)
|
||||
{
|
||||
var searchLocation = parentType.FullName.Substring(0, parentType.FullName.Length - parentType.Name.Length);
|
||||
typeByName = insideAssembly.GetType(searchLocation + typeName, false, true);
|
||||
}
|
||||
return typeByName;
|
||||
}
|
||||
|
||||
private static Type GetTypeFromMapping(IReadOnlyDictionary<object, Type> typeMapping, object discriminatorValue)
|
||||
{
|
||||
var targetlookupValueType = typeMapping.First().Key.GetType();
|
||||
var lookupValue = ConvertJsonValueToType(discriminatorValue, targetlookupValueType);
|
||||
|
||||
Type targetType;
|
||||
return typeMapping.TryGetValue(lookupValue, out targetType) ? targetType : null;
|
||||
}
|
||||
|
||||
private static Dictionary<object, Type> GetSubTypeMapping(Type type)
|
||||
{
|
||||
return type.GetTypeInfo().GetCustomAttributes<KnownSubTypeAttribute>().ToDictionary(x => x.AssociatedValue, x => x.SubType);
|
||||
}
|
||||
|
||||
private static object ConvertJsonValueToType(object objectType, Type targetlookupValueType)
|
||||
{
|
||||
if (targetlookupValueType.GetTypeInfo().IsEnum)
|
||||
return Enum.ToObject(targetlookupValueType, objectType);
|
||||
|
||||
return Convert.ChangeType(objectType, targetlookupValueType);
|
||||
}
|
||||
|
||||
protected object _ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
_reader = reader;
|
||||
_isInsideRead = true;
|
||||
try
|
||||
{
|
||||
return serializer.Deserialize(reader, objectType);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isInsideRead = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ Contact: apiteam@swagger.io
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{321C8C3F-0156-40C1-AE42-D59761FB9B6C}</ProjectGuid>
|
||||
<ProjectGuid>{3AB1F259-1769-484B-9411-84505FCCBD55}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>IO.Swagger</RootNamespace>
|
||||
|
||||
@@ -39,16 +39,20 @@ namespace IO.Swagger.Model
|
||||
/// Enum GreaterThanOrEqualTo for ">="
|
||||
/// </summary>
|
||||
[EnumMember(Value = ">=")]
|
||||
GreaterThanOrEqualTo,
|
||||
GreaterThanOrEqualTo = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Dollar for "$"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "$")]
|
||||
Dollar
|
||||
Dollar = 2
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets JustSymbol
|
||||
/// </summary>
|
||||
[DataMember(Name="just_symbol", EmitDefaultValue=false)]
|
||||
public JustSymbolEnum? JustSymbol { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or Sets ArrayEnum
|
||||
/// </summary>
|
||||
@@ -60,20 +64,16 @@ namespace IO.Swagger.Model
|
||||
/// Enum Fish for "fish"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "fish")]
|
||||
Fish,
|
||||
Fish = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Crab for "crab"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "crab")]
|
||||
Crab
|
||||
Crab = 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets JustSymbol
|
||||
/// </summary>
|
||||
[DataMember(Name="just_symbol", EmitDefaultValue=false)]
|
||||
public JustSymbolEnum? JustSymbol { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets ArrayEnum
|
||||
/// </summary>
|
||||
|
||||
@@ -33,19 +33,19 @@ namespace IO.Swagger.Model
|
||||
/// Enum Abc for "_abc"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "_abc")]
|
||||
Abc,
|
||||
Abc = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Efg for "-efg"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "-efg")]
|
||||
Efg,
|
||||
Efg = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Xyz for "(xyz)"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "(xyz)")]
|
||||
Xyz
|
||||
Xyz = 3
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,21 +39,26 @@ namespace IO.Swagger.Model
|
||||
/// Enum UPPER for "UPPER"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "UPPER")]
|
||||
UPPER,
|
||||
UPPER = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Lower for "lower"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "lower")]
|
||||
Lower,
|
||||
Lower = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Empty for ""
|
||||
/// </summary>
|
||||
[EnumMember(Value = "")]
|
||||
Empty
|
||||
Empty = 3
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets EnumString
|
||||
/// </summary>
|
||||
[DataMember(Name="enum_string", EmitDefaultValue=false)]
|
||||
public EnumStringEnum? EnumString { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or Sets EnumInteger
|
||||
/// </summary>
|
||||
@@ -74,6 +79,11 @@ namespace IO.Swagger.Model
|
||||
NUMBER_MINUS_1 = -1
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets EnumInteger
|
||||
/// </summary>
|
||||
[DataMember(Name="enum_integer", EmitDefaultValue=false)]
|
||||
public EnumIntegerEnum? EnumInteger { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or Sets EnumNumber
|
||||
/// </summary>
|
||||
@@ -85,38 +95,33 @@ namespace IO.Swagger.Model
|
||||
/// Enum NUMBER_1_DOT_1 for 1.1
|
||||
/// </summary>
|
||||
[EnumMember(Value = "1.1")]
|
||||
NUMBER_1_DOT_1,
|
||||
NUMBER_1_DOT_1 = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Enum NUMBER_MINUS_1_DOT_2 for -1.2
|
||||
/// </summary>
|
||||
[EnumMember(Value = "-1.2")]
|
||||
NUMBER_MINUS_1_DOT_2
|
||||
NUMBER_MINUS_1_DOT_2 = 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets EnumString
|
||||
/// </summary>
|
||||
[DataMember(Name="enum_string", EmitDefaultValue=false)]
|
||||
public EnumStringEnum? EnumString { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or Sets EnumInteger
|
||||
/// </summary>
|
||||
[DataMember(Name="enum_integer", EmitDefaultValue=false)]
|
||||
public EnumIntegerEnum? EnumInteger { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or Sets EnumNumber
|
||||
/// </summary>
|
||||
[DataMember(Name="enum_number", EmitDefaultValue=false)]
|
||||
public EnumNumberEnum? EnumNumber { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or Sets OuterEnum
|
||||
/// </summary>
|
||||
[DataMember(Name="outerEnum", EmitDefaultValue=false)]
|
||||
public OuterEnum? OuterEnum { get; set; }
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnumTest" /> class.
|
||||
/// </summary>
|
||||
/// <param name="EnumString">EnumString.</param>
|
||||
/// <param name="EnumInteger">EnumInteger.</param>
|
||||
/// <param name="EnumNumber">EnumNumber.</param>
|
||||
/// <param name="OuterEnum">OuterEnum.</param>
|
||||
public EnumTest(EnumStringEnum? EnumString = default(EnumStringEnum?), EnumIntegerEnum? EnumInteger = default(EnumIntegerEnum?), EnumNumberEnum? EnumNumber = default(EnumNumberEnum?), OuterEnum OuterEnum = default(OuterEnum))
|
||||
public EnumTest(EnumStringEnum? EnumString = default(EnumStringEnum?), EnumIntegerEnum? EnumInteger = default(EnumIntegerEnum?), EnumNumberEnum? EnumNumber = default(EnumNumberEnum?), OuterEnum? OuterEnum = default(OuterEnum?))
|
||||
{
|
||||
this.EnumString = EnumString;
|
||||
this.EnumInteger = EnumInteger;
|
||||
@@ -127,11 +132,6 @@ namespace IO.Swagger.Model
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets OuterEnum
|
||||
/// </summary>
|
||||
[DataMember(Name="outerEnum", EmitDefaultValue=false)]
|
||||
public OuterEnum OuterEnum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the string presentation of the object
|
||||
|
||||
@@ -28,7 +28,6 @@ namespace IO.Swagger.Model
|
||||
[DataContract]
|
||||
public partial class MapTest : IEquatable<MapTest>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Inner
|
||||
/// </summary>
|
||||
@@ -40,15 +39,16 @@ namespace IO.Swagger.Model
|
||||
/// Enum UPPER for "UPPER"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "UPPER")]
|
||||
UPPER,
|
||||
UPPER = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Lower for "lower"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "lower")]
|
||||
Lower
|
||||
Lower = 2
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets MapOfEnumString
|
||||
/// </summary>
|
||||
|
||||
@@ -40,19 +40,19 @@ namespace IO.Swagger.Model
|
||||
/// Enum Placed for "placed"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "placed")]
|
||||
Placed,
|
||||
Placed = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Approved for "approved"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "approved")]
|
||||
Approved,
|
||||
Approved = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Delivered for "delivered"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "delivered")]
|
||||
Delivered
|
||||
Delivered = 3
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -33,19 +33,19 @@ namespace IO.Swagger.Model
|
||||
/// Enum Placed for "placed"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "placed")]
|
||||
Placed,
|
||||
Placed = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Approved for "approved"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "approved")]
|
||||
Approved,
|
||||
Approved = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Delivered for "delivered"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "delivered")]
|
||||
Delivered
|
||||
Delivered = 3
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,19 +40,19 @@ namespace IO.Swagger.Model
|
||||
/// Enum Available for "available"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "available")]
|
||||
Available,
|
||||
Available = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Pending for "pending"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "pending")]
|
||||
Pending,
|
||||
Pending = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Sold for "sold"
|
||||
/// </summary>
|
||||
[EnumMember(Value = "sold")]
|
||||
Sold
|
||||
Sold = 3
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
"dependencies": {
|
||||
"FubarCoder.RestSharp.Portable.Core": "4.0.7",
|
||||
"FubarCoder.RestSharp.Portable.HttpClient": "4.0.7",
|
||||
"Newtonsoft.Json": "9.0.1"
|
||||
"Newtonsoft.Json": "10.0.3",
|
||||
"JsonSubTypes": "1.1.3"
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.3": {}
|
||||
|
||||
Reference in New Issue
Block a user