mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-09 23:06:11 +00:00
Rename csharp-netcore to csharp (#15903)
* rename csharp-netcore to csharp * rename file * renmae modules/openapi-generator/src/main/resources/csharp-netcore * update samples * mv dir * update samples * rename csharp-netcore to csharp in appveyor.yml * update doc
This commit is contained in:
@@ -0,0 +1,860 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* 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.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;
|
||||
using RestSharp;
|
||||
using RestSharp.Deserializers;
|
||||
using RestSharpMethod = RestSharp.Method;
|
||||
using Polly;
|
||||
|
||||
namespace Org.OpenAPITools.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows RestSharp to Serialize/Deserialize JSON using our custom logic, but only when ContentType is JSON.
|
||||
/// </summary>
|
||||
internal class CustomJsonCodec : RestSharp.Serializers.ISerializer, RestSharp.Deserializers.IDeserializer
|
||||
{
|
||||
private readonly IReadableConfiguration _configuration;
|
||||
private static readonly string _contentType = "application/json";
|
||||
private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
// OpenAPI generated types generally hide default constructors.
|
||||
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
|
||||
ContractResolver = new DefaultContractResolver
|
||||
{
|
||||
NamingStrategy = new CamelCaseNamingStrategy
|
||||
{
|
||||
OverrideSpecifiedNames = false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public CustomJsonCodec(IReadableConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public CustomJsonCodec(JsonSerializerSettings serializerSettings, IReadableConfiguration configuration)
|
||||
{
|
||||
_serializerSettings = serializerSettings;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize the object into a JSON string.
|
||||
/// </summary>
|
||||
/// <param name="obj">Object to be serialized.</param>
|
||||
/// <returns>A JSON string.</returns>
|
||||
public string Serialize(object obj)
|
||||
{
|
||||
if (obj != null && obj is Org.OpenAPITools.Models.AbstractOpenAPISchema)
|
||||
{
|
||||
// the object to be serialized is an oneOf/anyOf schema
|
||||
return ((Org.OpenAPITools.Models.AbstractOpenAPISchema)obj).ToJson();
|
||||
}
|
||||
else
|
||||
{
|
||||
return JsonConvert.SerializeObject(obj, _serializerSettings);
|
||||
}
|
||||
}
|
||||
|
||||
public T Deserialize<T>(IRestResponse response)
|
||||
{
|
||||
var result = (T)Deserialize(response, typeof(T));
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize the JSON string into a proper object.
|
||||
/// </summary>
|
||||
/// <param name="response">The HTTP response.</param>
|
||||
/// <param name="type">Object type.</param>
|
||||
/// <returns>Object representation of the JSON string.</returns>
|
||||
internal object Deserialize(IRestResponse response, Type type)
|
||||
{
|
||||
if (type == typeof(byte[])) // return byte array
|
||||
{
|
||||
return response.RawBytes;
|
||||
}
|
||||
|
||||
// TODO: ? if (type.IsAssignableFrom(typeof(Stream)))
|
||||
if (type == typeof(Stream))
|
||||
{
|
||||
var bytes = response.RawBytes;
|
||||
if (response.Headers != null)
|
||||
{
|
||||
var filePath = string.IsNullOrEmpty(_configuration.TempFolderPath)
|
||||
? Path.GetTempPath()
|
||||
: _configuration.TempFolderPath;
|
||||
var regex = new Regex(@"Content-Disposition=.*filename=['""]?([^'""\s]+)['""]?$");
|
||||
foreach (var header in response.Headers)
|
||||
{
|
||||
var match = regex.Match(header.ToString());
|
||||
if (match.Success)
|
||||
{
|
||||
string fileName = filePath + ClientUtils.SanitizeFilename(match.Groups[1].Value.Replace("\"", "").Replace("'", ""));
|
||||
File.WriteAllBytes(fileName, bytes);
|
||||
return new FileStream(fileName, FileMode.Open);
|
||||
}
|
||||
}
|
||||
}
|
||||
var stream = new MemoryStream(bytes);
|
||||
return stream;
|
||||
}
|
||||
|
||||
if (type.Name.StartsWith("System.Nullable`1[[System.DateTime")) // return a datetime object
|
||||
{
|
||||
return DateTime.Parse(response.Content, null, System.Globalization.DateTimeStyles.RoundtripKind);
|
||||
}
|
||||
|
||||
if (type == typeof(string) || type.Name.StartsWith("System.Nullable")) // return primitive type
|
||||
{
|
||||
return Convert.ChangeType(response.Content, type);
|
||||
}
|
||||
|
||||
// at this point, it must be a model (json)
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject(response.Content, type, _serializerSettings);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ApiException(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public string RootElement { get; set; }
|
||||
public string Namespace { get; set; }
|
||||
public string DateFormat { get; set; }
|
||||
|
||||
public string ContentType
|
||||
{
|
||||
get { return _contentType; }
|
||||
set { throw new InvalidOperationException("Not allowed to set content type."); }
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Provides a default implementation of an Api client (both synchronous and asynchronous implementations),
|
||||
/// encapsulating general REST accessor use cases.
|
||||
/// </summary>
|
||||
public partial class ApiClient : ISynchronousClient, IAsynchronousClient
|
||||
{
|
||||
private readonly string _baseUrl;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the settings on a <see cref="JsonSerializer" /> object.
|
||||
/// These settings can be adjusted to accommodate custom serialization rules.
|
||||
/// </summary>
|
||||
public JsonSerializerSettings SerializerSettings { get; set; } = new JsonSerializerSettings
|
||||
{
|
||||
// OpenAPI generated types generally hide default constructors.
|
||||
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
|
||||
ContractResolver = new DefaultContractResolver
|
||||
{
|
||||
NamingStrategy = new CamelCaseNamingStrategy
|
||||
{
|
||||
OverrideSpecifiedNames = false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Allows for extending request processing for <see cref="ApiClient"/> generated code.
|
||||
/// </summary>
|
||||
/// <param name="request">The RestSharp request object</param>
|
||||
partial void InterceptRequest(IRestRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Allows for extending response processing for <see cref="ApiClient"/> generated code.
|
||||
/// </summary>
|
||||
/// <param name="request">The RestSharp request object</param>
|
||||
/// <param name="response">The RestSharp response object</param>
|
||||
partial void InterceptResponse(IRestRequest request, IRestResponse response);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiClient" />, defaulting to the global configurations' base url.
|
||||
/// </summary>
|
||||
public ApiClient()
|
||||
{
|
||||
_baseUrl = Org.OpenAPITools.Client.GlobalConfiguration.Instance.BasePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiClient" />
|
||||
/// </summary>
|
||||
/// <param name="basePath">The target service's base path in URL format.</param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public ApiClient(string basePath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(basePath))
|
||||
throw new ArgumentException("basePath cannot be empty");
|
||||
|
||||
_baseUrl = basePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the RestSharp version of an http method
|
||||
/// </summary>
|
||||
/// <param name="method">Swagger Client Custom HttpMethod</param>
|
||||
/// <returns>RestSharp's HttpMethod instance.</returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
||||
private RestSharpMethod Method(HttpMethod method)
|
||||
{
|
||||
RestSharpMethod other;
|
||||
switch (method)
|
||||
{
|
||||
case HttpMethod.Get:
|
||||
other = RestSharpMethod.GET;
|
||||
break;
|
||||
case HttpMethod.Post:
|
||||
other = RestSharpMethod.POST;
|
||||
break;
|
||||
case HttpMethod.Put:
|
||||
other = RestSharpMethod.PUT;
|
||||
break;
|
||||
case HttpMethod.Delete:
|
||||
other = RestSharpMethod.DELETE;
|
||||
break;
|
||||
case HttpMethod.Head:
|
||||
other = RestSharpMethod.HEAD;
|
||||
break;
|
||||
case HttpMethod.Options:
|
||||
other = RestSharpMethod.OPTIONS;
|
||||
break;
|
||||
case HttpMethod.Patch:
|
||||
other = RestSharpMethod.PATCH;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("method", method, null);
|
||||
}
|
||||
|
||||
return other;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides all logic for constructing a new RestSharp <see cref="RestRequest"/>.
|
||||
/// At this point, all information for querying the service is known. Here, it is simply
|
||||
/// mapped into the RestSharp request.
|
||||
/// </summary>
|
||||
/// <param name="method">The http verb.</param>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <returns>[private] A new RestRequest instance.</returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
private RestRequest NewRequest(
|
||||
HttpMethod method,
|
||||
string path,
|
||||
RequestOptions options,
|
||||
IReadableConfiguration configuration)
|
||||
{
|
||||
if (path == null) throw new ArgumentNullException("path");
|
||||
if (options == null) throw new ArgumentNullException("options");
|
||||
if (configuration == null) throw new ArgumentNullException("configuration");
|
||||
|
||||
RestRequest request = new RestRequest(Method(method))
|
||||
{
|
||||
Resource = path,
|
||||
JsonSerializer = new CustomJsonCodec(SerializerSettings, configuration)
|
||||
};
|
||||
|
||||
if (options.PathParameters != null)
|
||||
{
|
||||
foreach (var pathParam in options.PathParameters)
|
||||
{
|
||||
request.AddParameter(pathParam.Key, pathParam.Value, ParameterType.UrlSegment);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.QueryParameters != null)
|
||||
{
|
||||
foreach (var queryParam in options.QueryParameters)
|
||||
{
|
||||
foreach (var value in queryParam.Value)
|
||||
{
|
||||
request.AddQueryParameter(queryParam.Key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (configuration.DefaultHeaders != null)
|
||||
{
|
||||
foreach (var headerParam in configuration.DefaultHeaders)
|
||||
{
|
||||
request.AddHeader(headerParam.Key, headerParam.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.HeaderParameters != null)
|
||||
{
|
||||
foreach (var headerParam in options.HeaderParameters)
|
||||
{
|
||||
foreach (var value in headerParam.Value)
|
||||
{
|
||||
request.AddHeader(headerParam.Key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options.FormParameters != null)
|
||||
{
|
||||
foreach (var formParam in options.FormParameters)
|
||||
{
|
||||
request.AddParameter(formParam.Key, formParam.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.Data != null)
|
||||
{
|
||||
if (options.Data is Stream stream)
|
||||
{
|
||||
var contentType = "application/octet-stream";
|
||||
if (options.HeaderParameters != null)
|
||||
{
|
||||
var contentTypes = options.HeaderParameters["Content-Type"];
|
||||
contentType = contentTypes[0];
|
||||
}
|
||||
|
||||
var bytes = ClientUtils.ReadAsBytes(stream);
|
||||
request.AddParameter(contentType, bytes, ParameterType.RequestBody);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options.HeaderParameters != null)
|
||||
{
|
||||
var contentTypes = options.HeaderParameters["Content-Type"];
|
||||
if (contentTypes == null || contentTypes.Any(header => header.Contains("application/json")))
|
||||
{
|
||||
request.RequestFormat = DataFormat.Json;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Generated client user should add additional handlers. RestSharp only supports XML and JSON, with XML as default.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Here, we'll assume JSON APIs are more common. XML can be forced by adding produces/consumes to openapi spec explicitly.
|
||||
request.RequestFormat = DataFormat.Json;
|
||||
}
|
||||
|
||||
request.AddJsonBody(options.Data);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.FileParameters != null)
|
||||
{
|
||||
foreach (var fileParam in options.FileParameters)
|
||||
{
|
||||
var bytes = ClientUtils.ReadAsBytes(fileParam.Value);
|
||||
var fileStream = fileParam.Value as FileStream;
|
||||
if (fileStream != null)
|
||||
request.Files.Add(FileParameter.Create(fileParam.Key, bytes, System.IO.Path.GetFileName(fileStream.Name)));
|
||||
else
|
||||
request.Files.Add(FileParameter.Create(fileParam.Key, bytes, "no_file_name_provided"));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.Cookies != null && options.Cookies.Count > 0)
|
||||
{
|
||||
foreach (var cookie in options.Cookies)
|
||||
{
|
||||
request.AddCookie(cookie.Name, cookie.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
private ApiResponse<T> ToApiResponse<T>(IRestResponse<T> response)
|
||||
{
|
||||
T result = response.Data;
|
||||
string rawContent = response.Content;
|
||||
|
||||
var transformed = new ApiResponse<T>(response.StatusCode, new Multimap<string, string>(), result, rawContent)
|
||||
{
|
||||
ErrorText = response.ErrorMessage,
|
||||
Cookies = new List<Cookie>()
|
||||
};
|
||||
|
||||
if (response.Headers != null)
|
||||
{
|
||||
foreach (var responseHeader in response.Headers)
|
||||
{
|
||||
transformed.Headers.Add(responseHeader.Name, ClientUtils.ParameterToString(responseHeader.Value));
|
||||
}
|
||||
}
|
||||
|
||||
if (response.Cookies != null)
|
||||
{
|
||||
foreach (var responseCookies in response.Cookies)
|
||||
{
|
||||
transformed.Cookies.Add(
|
||||
new Cookie(
|
||||
responseCookies.Name,
|
||||
responseCookies.Value,
|
||||
responseCookies.Path,
|
||||
responseCookies.Domain)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return transformed;
|
||||
}
|
||||
|
||||
private ApiResponse<T> Exec<T>(RestRequest req, IReadableConfiguration configuration)
|
||||
{
|
||||
RestClient client = new RestClient(_baseUrl);
|
||||
|
||||
client.ClearHandlers();
|
||||
var existingDeserializer = req.JsonSerializer as IDeserializer;
|
||||
if (existingDeserializer != null)
|
||||
{
|
||||
client.AddHandler("application/json", () => existingDeserializer);
|
||||
client.AddHandler("text/json", () => existingDeserializer);
|
||||
client.AddHandler("text/x-json", () => existingDeserializer);
|
||||
client.AddHandler("text/javascript", () => existingDeserializer);
|
||||
client.AddHandler("*+json", () => existingDeserializer);
|
||||
}
|
||||
else
|
||||
{
|
||||
var customDeserializer = new CustomJsonCodec(SerializerSettings, configuration);
|
||||
client.AddHandler("application/json", () => customDeserializer);
|
||||
client.AddHandler("text/json", () => customDeserializer);
|
||||
client.AddHandler("text/x-json", () => customDeserializer);
|
||||
client.AddHandler("text/javascript", () => customDeserializer);
|
||||
client.AddHandler("*+json", () => customDeserializer);
|
||||
}
|
||||
|
||||
var xmlDeserializer = new XmlDeserializer();
|
||||
client.AddHandler("application/xml", () => xmlDeserializer);
|
||||
client.AddHandler("text/xml", () => xmlDeserializer);
|
||||
client.AddHandler("*+xml", () => xmlDeserializer);
|
||||
client.AddHandler("*", () => xmlDeserializer);
|
||||
|
||||
client.Timeout = configuration.Timeout;
|
||||
|
||||
if (configuration.Proxy != null)
|
||||
{
|
||||
client.Proxy = configuration.Proxy;
|
||||
}
|
||||
|
||||
if (configuration.UserAgent != null)
|
||||
{
|
||||
client.UserAgent = configuration.UserAgent;
|
||||
}
|
||||
|
||||
if (configuration.ClientCertificates != null)
|
||||
{
|
||||
client.ClientCertificates = configuration.ClientCertificates;
|
||||
}
|
||||
|
||||
InterceptRequest(req);
|
||||
|
||||
IRestResponse<T> response;
|
||||
if (RetryConfiguration.RetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.RetryPolicy;
|
||||
var policyResult = policy.ExecuteAndCapture(() => client.Execute(req));
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>
|
||||
{
|
||||
Request = req,
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = client.Execute<T>(req);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Models.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies)
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<ApiResponse<T>> ExecAsync<T>(RestRequest req, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
{
|
||||
RestClient client = new RestClient(_baseUrl);
|
||||
|
||||
client.ClearHandlers();
|
||||
var existingDeserializer = req.JsonSerializer as IDeserializer;
|
||||
if (existingDeserializer != null)
|
||||
{
|
||||
client.AddHandler("application/json", () => existingDeserializer);
|
||||
client.AddHandler("text/json", () => existingDeserializer);
|
||||
client.AddHandler("text/x-json", () => existingDeserializer);
|
||||
client.AddHandler("text/javascript", () => existingDeserializer);
|
||||
client.AddHandler("*+json", () => existingDeserializer);
|
||||
}
|
||||
else
|
||||
{
|
||||
var customDeserializer = new CustomJsonCodec(SerializerSettings, configuration);
|
||||
client.AddHandler("application/json", () => customDeserializer);
|
||||
client.AddHandler("text/json", () => customDeserializer);
|
||||
client.AddHandler("text/x-json", () => customDeserializer);
|
||||
client.AddHandler("text/javascript", () => customDeserializer);
|
||||
client.AddHandler("*+json", () => customDeserializer);
|
||||
}
|
||||
|
||||
var xmlDeserializer = new XmlDeserializer();
|
||||
client.AddHandler("application/xml", () => xmlDeserializer);
|
||||
client.AddHandler("text/xml", () => xmlDeserializer);
|
||||
client.AddHandler("*+xml", () => xmlDeserializer);
|
||||
client.AddHandler("*", () => xmlDeserializer);
|
||||
|
||||
client.Timeout = configuration.Timeout;
|
||||
|
||||
if (configuration.Proxy != null)
|
||||
{
|
||||
client.Proxy = configuration.Proxy;
|
||||
}
|
||||
|
||||
if (configuration.UserAgent != null)
|
||||
{
|
||||
client.UserAgent = configuration.UserAgent;
|
||||
}
|
||||
|
||||
if (configuration.ClientCertificates != null)
|
||||
{
|
||||
client.ClientCertificates = configuration.ClientCertificates;
|
||||
}
|
||||
|
||||
InterceptRequest(req);
|
||||
|
||||
IRestResponse<T> response;
|
||||
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||
{
|
||||
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(req, ct), cancellationToken).ConfigureAwait(false);
|
||||
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>
|
||||
{
|
||||
Request = req,
|
||||
ErrorException = policyResult.FinalException
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await client.ExecuteAsync<T>(req, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||
if (typeof(Org.OpenAPITools.Models.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||
}
|
||||
else if (typeof(T).Name == "Stream") // for binary response
|
||||
{
|
||||
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||
}
|
||||
|
||||
InterceptResponse(req, response);
|
||||
|
||||
var result = ToApiResponse(response);
|
||||
if (response.ErrorMessage != null)
|
||||
{
|
||||
result.ErrorText = response.ErrorMessage;
|
||||
}
|
||||
|
||||
if (response.Cookies != null && response.Cookies.Count > 0)
|
||||
{
|
||||
if (result.Cookies == null) result.Cookies = new List<Cookie>();
|
||||
foreach (var restResponseCookie in response.Cookies)
|
||||
{
|
||||
var cookie = new Cookie(
|
||||
restResponseCookie.Name,
|
||||
restResponseCookie.Value,
|
||||
restResponseCookie.Path,
|
||||
restResponseCookie.Domain
|
||||
)
|
||||
{
|
||||
Comment = restResponseCookie.Comment,
|
||||
CommentUri = restResponseCookie.CommentUri,
|
||||
Discard = restResponseCookie.Discard,
|
||||
Expired = restResponseCookie.Expired,
|
||||
Expires = restResponseCookie.Expires,
|
||||
HttpOnly = restResponseCookie.HttpOnly,
|
||||
Port = restResponseCookie.Port,
|
||||
Secure = restResponseCookie.Secure,
|
||||
Version = restResponseCookie.Version
|
||||
};
|
||||
|
||||
result.Cookies.Add(cookie);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region IAsynchronousClient
|
||||
/// <summary>
|
||||
/// Make a HTTP GET request (async).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public Task<ApiResponse<T>> GetAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return ExecAsync<T>(NewRequest(HttpMethod.Get, path, options, config), config, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP POST request (async).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public Task<ApiResponse<T>> PostAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return ExecAsync<T>(NewRequest(HttpMethod.Post, path, options, config), config, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP PUT request (async).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public Task<ApiResponse<T>> PutAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return ExecAsync<T>(NewRequest(HttpMethod.Put, path, options, config), config, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP DELETE request (async).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public Task<ApiResponse<T>> DeleteAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return ExecAsync<T>(NewRequest(HttpMethod.Delete, path, options, config), config, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP HEAD request (async).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public Task<ApiResponse<T>> HeadAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return ExecAsync<T>(NewRequest(HttpMethod.Head, path, options, config), config, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP OPTION request (async).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public Task<ApiResponse<T>> OptionsAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return ExecAsync<T>(NewRequest(HttpMethod.Options, path, options, config), config, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP PATCH request (async).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <param name="cancellationToken">Token that enables callers to cancel the request.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public Task<ApiResponse<T>> PatchAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return ExecAsync<T>(NewRequest(HttpMethod.Patch, path, options, config), config, cancellationToken);
|
||||
}
|
||||
#endregion IAsynchronousClient
|
||||
|
||||
#region ISynchronousClient
|
||||
/// <summary>
|
||||
/// Make a HTTP GET request (synchronous).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public ApiResponse<T> Get<T>(string path, RequestOptions options, IReadableConfiguration configuration = null)
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return Exec<T>(NewRequest(HttpMethod.Get, path, options, config), config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP POST request (synchronous).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public ApiResponse<T> Post<T>(string path, RequestOptions options, IReadableConfiguration configuration = null)
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return Exec<T>(NewRequest(HttpMethod.Post, path, options, config), config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP PUT request (synchronous).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public ApiResponse<T> Put<T>(string path, RequestOptions options, IReadableConfiguration configuration = null)
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return Exec<T>(NewRequest(HttpMethod.Put, path, options, config), config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP DELETE request (synchronous).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public ApiResponse<T> Delete<T>(string path, RequestOptions options, IReadableConfiguration configuration = null)
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return Exec<T>(NewRequest(HttpMethod.Delete, path, options, config), config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP HEAD request (synchronous).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public ApiResponse<T> Head<T>(string path, RequestOptions options, IReadableConfiguration configuration = null)
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return Exec<T>(NewRequest(HttpMethod.Head, path, options, config), config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP OPTION request (synchronous).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public ApiResponse<T> Options<T>(string path, RequestOptions options, IReadableConfiguration configuration = null)
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return Exec<T>(NewRequest(HttpMethod.Options, path, options, config), config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a HTTP PATCH request (synchronous).
|
||||
/// </summary>
|
||||
/// <param name="path">The target path (or resource).</param>
|
||||
/// <param name="options">The additional request options.</param>
|
||||
/// <param name="configuration">A per-request configuration object. It is assumed that any merge with
|
||||
/// GlobalConfiguration has been done before calling this method.</param>
|
||||
/// <returns>A Task containing ApiResponse</returns>
|
||||
public ApiResponse<T> Patch<T>(string path, RequestOptions options, IReadableConfiguration configuration = null)
|
||||
{
|
||||
var config = configuration ?? GlobalConfiguration.Instance;
|
||||
return Exec<T>(NewRequest(HttpMethod.Patch, path, options, config), config);
|
||||
}
|
||||
#endregion ISynchronousClient
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.OpenAPITools.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// API Exception
|
||||
/// </summary>
|
||||
public class ApiException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the error code (HTTP status code)
|
||||
/// </summary>
|
||||
/// <value>The error code (HTTP status code).</value>
|
||||
public int ErrorCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the error content (body json object)
|
||||
/// </summary>
|
||||
/// <value>The error content (Http response body).</value>
|
||||
public object ErrorContent { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP headers
|
||||
/// </summary>
|
||||
/// <value>HTTP headers</value>
|
||||
public Multimap<string, string> Headers { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
public ApiException() { }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
public ApiException(int errorCode, string message) : base(message)
|
||||
{
|
||||
this.ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
/// <param name="errorContent">Error content.</param>
|
||||
/// <param name="headers">HTTP Headers.</param>
|
||||
public ApiException(int errorCode, string message, object errorContent = null, Multimap<string, string> headers = null) : base(message)
|
||||
{
|
||||
this.ErrorCode = errorCode;
|
||||
this.ErrorContent = errorContent;
|
||||
this.Headers = headers;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
|
||||
namespace Org.OpenAPITools.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a non-generic contract for the ApiResponse wrapper.
|
||||
/// </summary>
|
||||
public interface IApiResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// The data type of <see cref="Content"/>
|
||||
/// </summary>
|
||||
Type ResponseType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The content of this response
|
||||
/// </summary>
|
||||
Object Content { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status code (HTTP status code)
|
||||
/// </summary>
|
||||
/// <value>The status code.</value>
|
||||
HttpStatusCode StatusCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP headers
|
||||
/// </summary>
|
||||
/// <value>HTTP headers</value>
|
||||
Multimap<string, string> Headers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets any error text defined by the calling client.
|
||||
/// </summary>
|
||||
string ErrorText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets any cookies passed along on the response.
|
||||
/// </summary>
|
||||
List<Cookie> Cookies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The raw content of this response
|
||||
/// </summary>
|
||||
string RawContent { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API Response
|
||||
/// </summary>
|
||||
public class ApiResponse<T> : IApiResponse
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status code (HTTP status code)
|
||||
/// </summary>
|
||||
/// <value>The status code.</value>
|
||||
public HttpStatusCode StatusCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP headers
|
||||
/// </summary>
|
||||
/// <value>HTTP headers</value>
|
||||
public Multimap<string, string> Headers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the data (parsed HTTP body)
|
||||
/// </summary>
|
||||
/// <value>The data.</value>
|
||||
public T Data { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets any error text defined by the calling client.
|
||||
/// </summary>
|
||||
public string ErrorText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets any cookies passed along on the response.
|
||||
/// </summary>
|
||||
public List<Cookie> Cookies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The content of this response
|
||||
/// </summary>
|
||||
public Type ResponseType
|
||||
{
|
||||
get { return typeof(T); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The data type of <see cref="Content"/>
|
||||
/// </summary>
|
||||
public object Content
|
||||
{
|
||||
get { return Data; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The raw content
|
||||
/// </summary>
|
||||
public string RawContent { get; }
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiResponse{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">HTTP status code.</param>
|
||||
/// <param name="headers">HTTP headers.</param>
|
||||
/// <param name="data">Data (parsed HTTP body)</param>
|
||||
/// <param name="rawContent">Raw content.</param>
|
||||
public ApiResponse(HttpStatusCode statusCode, Multimap<string, string> headers, T data, string rawContent)
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
Headers = headers;
|
||||
Data = data;
|
||||
RawContent = rawContent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiResponse{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">HTTP status code.</param>
|
||||
/// <param name="headers">HTTP headers.</param>
|
||||
/// <param name="data">Data (parsed HTTP body)</param>
|
||||
public ApiResponse(HttpStatusCode statusCode, Multimap<string, string> headers, T data) : this(statusCode, headers, data, null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiResponse{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">HTTP status code.</param>
|
||||
/// <param name="data">Data (parsed HTTP body)</param>
|
||||
/// <param name="rawContent">Raw content.</param>
|
||||
public ApiResponse(HttpStatusCode statusCode, T data, string rawContent) : this(statusCode, null, data, rawContent)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiResponse{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">HTTP status code.</param>
|
||||
/// <param name="data">Data (parsed HTTP body)</param>
|
||||
public ApiResponse(HttpStatusCode statusCode, T data) : this(statusCode, data, null)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion Constructors
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,515 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
|
||||
namespace Org.OpenAPITools.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a set of configuration settings
|
||||
/// </summary>
|
||||
public class Configuration : IReadableConfiguration
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// Version of the package.
|
||||
/// </summary>
|
||||
/// <value>Version of the package.</value>
|
||||
public const string Version = "1.0.0";
|
||||
|
||||
/// <summary>
|
||||
/// Identifier for ISO 8601 DateTime Format
|
||||
/// </summary>
|
||||
/// <remarks>See https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8 for more information.</remarks>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public const string ISO8601_DATETIME_FORMAT = "o";
|
||||
|
||||
#endregion Constants
|
||||
|
||||
#region Static Members
|
||||
|
||||
/// <summary>
|
||||
/// Default creation of exceptions for a given method name and response object
|
||||
/// </summary>
|
||||
public static readonly ExceptionFactory DefaultExceptionFactory = (methodName, response) =>
|
||||
{
|
||||
var status = (int)response.StatusCode;
|
||||
if (status >= 400)
|
||||
{
|
||||
return new ApiException(status,
|
||||
string.Format("Error calling {0}: {1}", methodName, response.RawContent),
|
||||
response.RawContent, response.Headers);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
#endregion Static Members
|
||||
|
||||
#region Private Members
|
||||
|
||||
/// <summary>
|
||||
/// Defines the base path of the target API server.
|
||||
/// Example: http://localhost:3000/v1/
|
||||
/// </summary>
|
||||
private string _basePath;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the API key based on the authentication name.
|
||||
/// This is the key and value comprising the "secret" for accessing an API.
|
||||
/// </summary>
|
||||
/// <value>The API key.</value>
|
||||
private IDictionary<string, string> _apiKey;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
||||
/// </summary>
|
||||
/// <value>The prefix of the API key.</value>
|
||||
private IDictionary<string, string> _apiKeyPrefix;
|
||||
|
||||
private string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
|
||||
private string _tempFolderPath = Path.GetTempPath();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the servers defined in the OpenAPI spec.
|
||||
/// </summary>
|
||||
/// <value>The servers</value>
|
||||
private IList<IReadOnlyDictionary<string, object>> _servers;
|
||||
#endregion Private Members
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Configuration" /> class
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
|
||||
public Configuration()
|
||||
{
|
||||
Proxy = null;
|
||||
UserAgent = "OpenAPI-Generator/1.0.0/csharp";
|
||||
BasePath = "http://petstore.swagger.io/v2";
|
||||
DefaultHeaders = new ConcurrentDictionary<string, string>();
|
||||
ApiKey = new ConcurrentDictionary<string, string>();
|
||||
ApiKeyPrefix = new ConcurrentDictionary<string, string>();
|
||||
Servers = new List<IReadOnlyDictionary<string, object>>()
|
||||
{
|
||||
{
|
||||
new Dictionary<string, object> {
|
||||
{"url", "http://petstore.swagger.io/v2"},
|
||||
{"description", "No description provided"},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Setting Timeout has side effects (forces ApiClient creation).
|
||||
Timeout = 100000;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Configuration" /> class
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
|
||||
public Configuration(
|
||||
IDictionary<string, string> defaultHeaders,
|
||||
IDictionary<string, string> apiKey,
|
||||
IDictionary<string, string> apiKeyPrefix,
|
||||
string basePath = "http://petstore.swagger.io/v2") : this()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(basePath))
|
||||
throw new ArgumentException("The provided basePath is invalid.", "basePath");
|
||||
if (defaultHeaders == null)
|
||||
throw new ArgumentNullException("defaultHeaders");
|
||||
if (apiKey == null)
|
||||
throw new ArgumentNullException("apiKey");
|
||||
if (apiKeyPrefix == null)
|
||||
throw new ArgumentNullException("apiKeyPrefix");
|
||||
|
||||
BasePath = basePath;
|
||||
|
||||
foreach (var keyValuePair in defaultHeaders)
|
||||
{
|
||||
DefaultHeaders.Add(keyValuePair);
|
||||
}
|
||||
|
||||
foreach (var keyValuePair in apiKey)
|
||||
{
|
||||
ApiKey.Add(keyValuePair);
|
||||
}
|
||||
|
||||
foreach (var keyValuePair in apiKeyPrefix)
|
||||
{
|
||||
ApiKeyPrefix.Add(keyValuePair);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Constructors
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the base path for API access.
|
||||
/// </summary>
|
||||
public virtual string BasePath {
|
||||
get { return _basePath; }
|
||||
set { _basePath = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default header.
|
||||
/// </summary>
|
||||
[Obsolete("Use DefaultHeaders instead.")]
|
||||
public virtual IDictionary<string, string> DefaultHeader
|
||||
{
|
||||
get
|
||||
{
|
||||
return DefaultHeaders;
|
||||
}
|
||||
set
|
||||
{
|
||||
DefaultHeaders = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default headers.
|
||||
/// </summary>
|
||||
public virtual IDictionary<string, string> DefaultHeaders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds.
|
||||
/// </summary>
|
||||
public virtual int Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the proxy
|
||||
/// </summary>
|
||||
/// <value>Proxy.</value>
|
||||
public virtual WebProxy Proxy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP user agent.
|
||||
/// </summary>
|
||||
/// <value>Http user agent.</value>
|
||||
public virtual string UserAgent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the username (HTTP basic authentication).
|
||||
/// </summary>
|
||||
/// <value>The username.</value>
|
||||
public virtual string Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the password (HTTP basic authentication).
|
||||
/// </summary>
|
||||
/// <value>The password.</value>
|
||||
public virtual string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the API key with prefix.
|
||||
/// </summary>
|
||||
/// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
|
||||
/// <returns>API key with prefix.</returns>
|
||||
public string GetApiKeyWithPrefix(string apiKeyIdentifier)
|
||||
{
|
||||
string apiKeyValue;
|
||||
ApiKey.TryGetValue(apiKeyIdentifier, out apiKeyValue);
|
||||
string apiKeyPrefix;
|
||||
if (ApiKeyPrefix.TryGetValue(apiKeyIdentifier, out apiKeyPrefix))
|
||||
{
|
||||
return apiKeyPrefix + " " + apiKeyValue;
|
||||
}
|
||||
|
||||
return apiKeyValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets certificate collection to be sent with requests.
|
||||
/// </summary>
|
||||
/// <value>X509 Certificate collection.</value>
|
||||
public X509CertificateCollection ClientCertificates { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the access token for OAuth2 authentication.
|
||||
///
|
||||
/// This helper property simplifies code generation.
|
||||
/// </summary>
|
||||
/// <value>The access token.</value>
|
||||
public virtual string AccessToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the temporary folder path to store the files downloaded from the server.
|
||||
/// </summary>
|
||||
/// <value>Folder path.</value>
|
||||
public virtual string TempFolderPath
|
||||
{
|
||||
get { return _tempFolderPath; }
|
||||
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
_tempFolderPath = Path.GetTempPath();
|
||||
return;
|
||||
}
|
||||
|
||||
// create the directory if it does not exist
|
||||
if (!Directory.Exists(value))
|
||||
{
|
||||
Directory.CreateDirectory(value);
|
||||
}
|
||||
|
||||
// check if the path contains directory separator at the end
|
||||
if (value[value.Length - 1] == Path.DirectorySeparatorChar)
|
||||
{
|
||||
_tempFolderPath = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_tempFolderPath = value + Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date time format used when serializing in the ApiClient
|
||||
/// By default, it's set to ISO 8601 - "o", for others see:
|
||||
/// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx
|
||||
/// and https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
|
||||
/// No validation is done to ensure that the string you're providing is valid
|
||||
/// </summary>
|
||||
/// <value>The DateTimeFormat string</value>
|
||||
public virtual string DateTimeFormat
|
||||
{
|
||||
get { return _dateTimeFormat; }
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
// Never allow a blank or null string, go back to the default
|
||||
_dateTimeFormat = ISO8601_DATETIME_FORMAT;
|
||||
return;
|
||||
}
|
||||
|
||||
// Caution, no validation when you choose date time format other than ISO 8601
|
||||
// Take a look at the above links
|
||||
_dateTimeFormat = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
|
||||
///
|
||||
/// Whatever you set here will be prepended to the value defined in AddApiKey.
|
||||
///
|
||||
/// An example invocation here might be:
|
||||
/// <example>
|
||||
/// ApiKeyPrefix["Authorization"] = "Bearer";
|
||||
/// </example>
|
||||
/// … where ApiKey["Authorization"] would then be used to set the value of your bearer token.
|
||||
///
|
||||
/// <remarks>
|
||||
/// OAuth2 workflows should set tokens via AccessToken.
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
/// <value>The prefix of the API key.</value>
|
||||
public virtual IDictionary<string, string> ApiKeyPrefix
|
||||
{
|
||||
get { return _apiKeyPrefix; }
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new InvalidOperationException("ApiKeyPrefix collection may not be null.");
|
||||
}
|
||||
_apiKeyPrefix = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the API key based on the authentication name.
|
||||
/// </summary>
|
||||
/// <value>The API key.</value>
|
||||
public virtual IDictionary<string, string> ApiKey
|
||||
{
|
||||
get { return _apiKey; }
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new InvalidOperationException("ApiKey collection may not be null.");
|
||||
}
|
||||
_apiKey = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the servers.
|
||||
/// </summary>
|
||||
/// <value>The servers.</value>
|
||||
public virtual IList<IReadOnlyDictionary<string, object>> Servers
|
||||
{
|
||||
get { return _servers; }
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new InvalidOperationException("Servers may not be null.");
|
||||
}
|
||||
_servers = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns URL based on server settings without providing values
|
||||
/// for the variables
|
||||
/// </summary>
|
||||
/// <param name="index">Array index of the server settings.</param>
|
||||
/// <return>The server URL.</return>
|
||||
public string GetServerUrl(int index)
|
||||
{
|
||||
return GetServerUrl(index, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns URL based on server settings.
|
||||
/// </summary>
|
||||
/// <param name="index">Array index of the server settings.</param>
|
||||
/// <param name="inputVariables">Dictionary of the variables and the corresponding values.</param>
|
||||
/// <return>The server URL.</return>
|
||||
public string GetServerUrl(int index, Dictionary<string, string> inputVariables)
|
||||
{
|
||||
if (index < 0 || index >= Servers.Count)
|
||||
{
|
||||
throw new InvalidOperationException($"Invalid index {index} when selecting the server. Must be less than {Servers.Count}.");
|
||||
}
|
||||
|
||||
if (inputVariables == null)
|
||||
{
|
||||
inputVariables = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
IReadOnlyDictionary<string, object> server = Servers[index];
|
||||
string url = (string)server["url"];
|
||||
|
||||
// go through variable and assign a value
|
||||
foreach (KeyValuePair<string, object> variable in (IReadOnlyDictionary<string, object>)server["variables"])
|
||||
{
|
||||
|
||||
IReadOnlyDictionary<string, object> serverVariables = (IReadOnlyDictionary<string, object>)(variable.Value);
|
||||
|
||||
if (inputVariables.ContainsKey(variable.Key))
|
||||
{
|
||||
if (((List<string>)serverVariables["enum_values"]).Contains(inputVariables[variable.Key]))
|
||||
{
|
||||
url = url.Replace("{" + variable.Key + "}", inputVariables[variable.Key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException($"The variable `{variable.Key}` in the server URL has invalid value #{inputVariables[variable.Key]}. Must be {(List<string>)serverVariables["enum_values"]}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// use default value
|
||||
url = url.Replace("{" + variable.Key + "}", (string)serverVariables["default_value"]);
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string with essential information for debugging.
|
||||
/// </summary>
|
||||
public static string ToDebugReport()
|
||||
{
|
||||
string report = "C# SDK (Org.OpenAPITools) Debug Report:\n";
|
||||
report += " OS: " + System.Environment.OSVersion + "\n";
|
||||
report += " .NET Framework Version: " + System.Environment.Version + "\n";
|
||||
report += " Version of the API: 1.0.0\n";
|
||||
report += " SDK Package Version: 1.0.0\n";
|
||||
|
||||
return report;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Api Key Header.
|
||||
/// </summary>
|
||||
/// <param name="key">Api Key name.</param>
|
||||
/// <param name="value">Api Key value.</param>
|
||||
/// <returns></returns>
|
||||
public void AddApiKey(string key, string value)
|
||||
{
|
||||
ApiKey[key] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the API key prefix.
|
||||
/// </summary>
|
||||
/// <param name="key">Api Key name.</param>
|
||||
/// <param name="value">Api Key value.</param>
|
||||
public void AddApiKeyPrefix(string key, string value)
|
||||
{
|
||||
ApiKeyPrefix[key] = value;
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
|
||||
#region Static Members
|
||||
/// <summary>
|
||||
/// Merge configurations.
|
||||
/// </summary>
|
||||
/// <param name="first">First configuration.</param>
|
||||
/// <param name="second">Second configuration.</param>
|
||||
/// <return>Merged configuration.</return>
|
||||
public static IReadableConfiguration MergeConfigurations(IReadableConfiguration first, IReadableConfiguration second)
|
||||
{
|
||||
if (second == null) return first ?? GlobalConfiguration.Instance;
|
||||
|
||||
Dictionary<string, string> apiKey = first.ApiKey.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
Dictionary<string, string> apiKeyPrefix = first.ApiKeyPrefix.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
Dictionary<string, string> defaultHeaders = first.DefaultHeaders.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||
|
||||
foreach (var kvp in second.ApiKey) apiKey[kvp.Key] = kvp.Value;
|
||||
foreach (var kvp in second.ApiKeyPrefix) apiKeyPrefix[kvp.Key] = kvp.Value;
|
||||
foreach (var kvp in second.DefaultHeaders) defaultHeaders[kvp.Key] = kvp.Value;
|
||||
|
||||
var config = new Configuration
|
||||
{
|
||||
ApiKey = apiKey,
|
||||
ApiKeyPrefix = apiKeyPrefix,
|
||||
DefaultHeaders = defaultHeaders,
|
||||
BasePath = second.BasePath ?? first.BasePath,
|
||||
Timeout = second.Timeout,
|
||||
Proxy = second.Proxy ?? first.Proxy,
|
||||
UserAgent = second.UserAgent ?? first.UserAgent,
|
||||
Username = second.Username ?? first.Username,
|
||||
Password = second.Password ?? first.Password,
|
||||
AccessToken = second.AccessToken ?? first.AccessToken,
|
||||
TempFolderPath = second.TempFolderPath ?? first.TempFolderPath,
|
||||
DateTimeFormat = second.DateTimeFormat ?? first.DateTimeFormat
|
||||
};
|
||||
return config;
|
||||
}
|
||||
#endregion Static Members
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.OpenAPITools.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// A delegate to ExceptionFactory method
|
||||
/// </summary>
|
||||
/// <param name="methodName">Method name</param>
|
||||
/// <param name="response">Response</param>
|
||||
/// <returns>Exceptions</returns>
|
||||
public delegate Exception ExceptionFactory(string methodName, IApiResponse response);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
namespace Org.OpenAPITools.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents configuration aspects required to interact with the API endpoints.
|
||||
/// </summary>
|
||||
public interface IApiAccessor
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the configuration object
|
||||
/// </summary>
|
||||
/// <value>An instance of the Configuration</value>
|
||||
IReadableConfiguration Configuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
string GetBasePath();
|
||||
|
||||
/// <summary>
|
||||
/// Provides a factory method hook for the creation of exceptions.
|
||||
/// </summary>
|
||||
ExceptionFactory ExceptionFactory { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace Org.OpenAPITools.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Formatter for 'date' openapi formats ss defined by full-date - RFC3339
|
||||
/// see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#data-types
|
||||
/// </summary>
|
||||
public class OpenAPIDateConverter : IsoDateTimeConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OpenAPIDateConverter" /> class.
|
||||
/// </summary>
|
||||
public OpenAPIDateConverter()
|
||||
{
|
||||
// full-date = date-fullyear "-" date-month "-" date-mday
|
||||
DateTimeFormat = "yyyy-MM-dd";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
|
||||
namespace Org.OpenAPITools.Apis
|
||||
{
|
||||
public partial class PetApi
|
||||
{
|
||||
[FunctionName("PetApi_AddPet")]
|
||||
public async Task<IActionResult> _AddPet([HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "/pet")]HttpRequest req, ExecutionContext context)
|
||||
{
|
||||
var method = this.GetType().GetMethod("AddPet");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("PetApi_DeletePet")]
|
||||
public async Task<IActionResult> _DeletePet([HttpTrigger(AuthorizationLevel.Anonymous, "DELETE", Route = "/pet/{petId}")]HttpRequest req, ExecutionContext context, long petId)
|
||||
{
|
||||
var method = this.GetType().GetMethod("DeletePet");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context, })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("PetApi_FindPetsByStatus")]
|
||||
public async Task<IActionResult> _FindPetsByStatus([HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "/pet/findByStatus")]HttpRequest req, ExecutionContext context)
|
||||
{
|
||||
var method = this.GetType().GetMethod("FindPetsByStatus");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("PetApi_FindPetsByTags")]
|
||||
public async Task<IActionResult> _FindPetsByTags([HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "/pet/findByTags")]HttpRequest req, ExecutionContext context)
|
||||
{
|
||||
var method = this.GetType().GetMethod("FindPetsByTags");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("PetApi_GetPetById")]
|
||||
public async Task<IActionResult> _GetPetById([HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "/pet/{petId}")]HttpRequest req, ExecutionContext context, long petId)
|
||||
{
|
||||
var method = this.GetType().GetMethod("GetPetById");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context, })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("PetApi_UpdatePet")]
|
||||
public async Task<IActionResult> _UpdatePet([HttpTrigger(AuthorizationLevel.Anonymous, "PUT", Route = "/pet")]HttpRequest req, ExecutionContext context)
|
||||
{
|
||||
var method = this.GetType().GetMethod("UpdatePet");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("PetApi_UpdatePetWithForm")]
|
||||
public async Task<IActionResult> _UpdatePetWithForm([HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "/pet/{petId}")]HttpRequest req, ExecutionContext context, long petId)
|
||||
{
|
||||
var method = this.GetType().GetMethod("UpdatePetWithForm");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context, })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("PetApi_UploadFile")]
|
||||
public async Task<IActionResult> _UploadFile([HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "/pet/{petId}/uploadImage")]HttpRequest req, ExecutionContext context, long petId)
|
||||
{
|
||||
var method = this.GetType().GetMethod("UploadFile");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context, })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
|
||||
namespace Org.OpenAPITools.Apis
|
||||
{
|
||||
public partial class StoreApi
|
||||
{
|
||||
[FunctionName("StoreApi_DeleteOrder")]
|
||||
public async Task<IActionResult> _DeleteOrder([HttpTrigger(AuthorizationLevel.Anonymous, "DELETE", Route = "/store/order/{orderId}")]HttpRequest req, ExecutionContext context, string orderId)
|
||||
{
|
||||
var method = this.GetType().GetMethod("DeleteOrder");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context, })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("StoreApi_GetInventory")]
|
||||
public async Task<IActionResult> _GetInventory([HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "/store/inventory")]HttpRequest req, ExecutionContext context)
|
||||
{
|
||||
var method = this.GetType().GetMethod("GetInventory");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("StoreApi_GetOrderById")]
|
||||
public async Task<IActionResult> _GetOrderById([HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "/store/order/{orderId}")]HttpRequest req, ExecutionContext context, [Range(1, 5)]long orderId)
|
||||
{
|
||||
var method = this.GetType().GetMethod("GetOrderById");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context, })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("StoreApi_PlaceOrder")]
|
||||
public async Task<IActionResult> _PlaceOrder([HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "/store/order")]HttpRequest req, ExecutionContext context)
|
||||
{
|
||||
var method = this.GetType().GetMethod("PlaceOrder");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
|
||||
namespace Org.OpenAPITools.Apis
|
||||
{
|
||||
public partial class UserApi
|
||||
{
|
||||
[FunctionName("UserApi_CreateUser")]
|
||||
public async Task<IActionResult> _CreateUser([HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "/user")]HttpRequest req, ExecutionContext context)
|
||||
{
|
||||
var method = this.GetType().GetMethod("CreateUser");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("UserApi_CreateUsersWithArrayInput")]
|
||||
public async Task<IActionResult> _CreateUsersWithArrayInput([HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "/user/createWithArray")]HttpRequest req, ExecutionContext context)
|
||||
{
|
||||
var method = this.GetType().GetMethod("CreateUsersWithArrayInput");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("UserApi_CreateUsersWithListInput")]
|
||||
public async Task<IActionResult> _CreateUsersWithListInput([HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "/user/createWithList")]HttpRequest req, ExecutionContext context)
|
||||
{
|
||||
var method = this.GetType().GetMethod("CreateUsersWithListInput");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("UserApi_DeleteUser")]
|
||||
public async Task<IActionResult> _DeleteUser([HttpTrigger(AuthorizationLevel.Anonymous, "DELETE", Route = "/user/{username}")]HttpRequest req, ExecutionContext context, string username)
|
||||
{
|
||||
var method = this.GetType().GetMethod("DeleteUser");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context, })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("UserApi_GetUserByName")]
|
||||
public async Task<IActionResult> _GetUserByName([HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "/user/{username}")]HttpRequest req, ExecutionContext context, string username)
|
||||
{
|
||||
var method = this.GetType().GetMethod("GetUserByName");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context, })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("UserApi_LoginUser")]
|
||||
public async Task<IActionResult> _LoginUser([HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "/user/login")]HttpRequest req, ExecutionContext context)
|
||||
{
|
||||
var method = this.GetType().GetMethod("LoginUser");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("UserApi_LogoutUser")]
|
||||
public async Task<IActionResult> _LogoutUser([HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "/user/logout")]HttpRequest req, ExecutionContext context)
|
||||
{
|
||||
var method = this.GetType().GetMethod("LogoutUser");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
|
||||
[FunctionName("UserApi_UpdateUser")]
|
||||
public async Task<IActionResult> _UpdateUser([HttpTrigger(AuthorizationLevel.Anonymous, "PUT", Route = "/user/{username}")]HttpRequest req, ExecutionContext context, string username)
|
||||
{
|
||||
var method = this.GetType().GetMethod("UpdateUser");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context, })).ConfigureAwait(false))
|
||||
: new StatusCodeResult((int)HttpStatusCode.NotImplemented);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* 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;
|
||||
|
||||
namespace Org.OpenAPITools.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes the result of uploading an image resource
|
||||
/// </summary>
|
||||
[DataContract(Name = "ApiResponse")]
|
||||
public partial class ApiResponse : IEquatable<ApiResponse>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiResponse" /> class.
|
||||
/// </summary>
|
||||
/// <param name="code">code.</param>
|
||||
/// <param name="type">type.</param>
|
||||
/// <param name="message">message.</param>
|
||||
public ApiResponse(int code = default(int), string type = default(string), string message = default(string))
|
||||
{
|
||||
this.Code = code;
|
||||
this.Type = type;
|
||||
this.Message = message;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Code
|
||||
/// </summary>
|
||||
[DataMember(Name = "code", EmitDefaultValue = false)]
|
||||
public int Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Type
|
||||
/// </summary>
|
||||
[DataMember(Name = "type", EmitDefaultValue = false)]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Message
|
||||
/// </summary>
|
||||
[DataMember(Name = "message", EmitDefaultValue = false)]
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <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 ApiResponse {\n");
|
||||
sb.Append(" Code: ").Append(Code).Append("\n");
|
||||
sb.Append(" Type: ").Append(Type).Append("\n");
|
||||
sb.Append(" Message: ").Append(Message).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 virtual string ToJson()
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
|
||||
}
|
||||
|
||||
/// <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 this.Equals(input as ApiResponse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if ApiResponse instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of ApiResponse to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(ApiResponse input)
|
||||
{
|
||||
if (input == null)
|
||||
return false;
|
||||
|
||||
return
|
||||
(
|
||||
this.Code == input.Code ||
|
||||
this.Code.Equals(input.Code)
|
||||
) &&
|
||||
(
|
||||
this.Type == input.Type ||
|
||||
(this.Type != null &&
|
||||
this.Type.Equals(input.Type))
|
||||
) &&
|
||||
(
|
||||
this.Message == input.Message ||
|
||||
(this.Message != null &&
|
||||
this.Message.Equals(input.Message))
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hashCode = 41;
|
||||
hashCode = hashCode * 59 + this.Code.GetHashCode();
|
||||
if (this.Type != null)
|
||||
hashCode = hashCode * 59 + this.Type.GetHashCode();
|
||||
if (this.Message != null)
|
||||
hashCode = hashCode * 59 + this.Message.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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* 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;
|
||||
|
||||
namespace Org.OpenAPITools.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A category for a pet
|
||||
/// </summary>
|
||||
[DataContract(Name = "Category")]
|
||||
public partial class Category : IEquatable<Category>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Category" /> class.
|
||||
/// </summary>
|
||||
/// <param name="id">id.</param>
|
||||
/// <param name="name">name.</param>
|
||||
public Category(long id = default(long), string name = default(string))
|
||||
{
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Id
|
||||
/// </summary>
|
||||
[DataMember(Name = "id", EmitDefaultValue = false)]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Name
|
||||
/// </summary>
|
||||
[DataMember(Name = "name", EmitDefaultValue = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <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 Category {\n");
|
||||
sb.Append(" Id: ").Append(Id).Append("\n");
|
||||
sb.Append(" Name: ").Append(Name).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 virtual string ToJson()
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
|
||||
}
|
||||
|
||||
/// <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 this.Equals(input as Category);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if Category instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of Category to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(Category input)
|
||||
{
|
||||
if (input == null)
|
||||
return false;
|
||||
|
||||
return
|
||||
(
|
||||
this.Id == input.Id ||
|
||||
this.Id.Equals(input.Id)
|
||||
) &&
|
||||
(
|
||||
this.Name == input.Name ||
|
||||
(this.Name != null &&
|
||||
this.Name.Equals(input.Name))
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hashCode = 41;
|
||||
hashCode = hashCode * 59 + this.Id.GetHashCode();
|
||||
if (this.Name != null)
|
||||
hashCode = hashCode * 59 + this.Name.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)
|
||||
{
|
||||
// Name (string) pattern
|
||||
Regex regexName = new Regex(@"^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$", RegexOptions.CultureInvariant);
|
||||
if (false == regexName.Match(this.Name).Success)
|
||||
{
|
||||
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Name, must match a pattern of " + regexName, new [] { "Name" });
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* 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;
|
||||
|
||||
namespace Org.OpenAPITools.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// An order for a pets from the pet store
|
||||
/// </summary>
|
||||
[DataContract(Name = "Order")]
|
||||
public partial class Order : IEquatable<Order>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Order Status
|
||||
/// </summary>
|
||||
/// <value>Order Status</value>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum StatusEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum Placed for value: placed
|
||||
/// </summary>
|
||||
[EnumMember(Value = "placed")]
|
||||
Placed = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Approved for value: approved
|
||||
/// </summary>
|
||||
[EnumMember(Value = "approved")]
|
||||
Approved = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Delivered for value: delivered
|
||||
/// </summary>
|
||||
[EnumMember(Value = "delivered")]
|
||||
Delivered = 3
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Order Status
|
||||
/// </summary>
|
||||
/// <value>Order Status</value>
|
||||
[DataMember(Name = "status", EmitDefaultValue = false)]
|
||||
public StatusEnum? Status { get; set; }
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Order" /> class.
|
||||
/// </summary>
|
||||
/// <param name="id">id.</param>
|
||||
/// <param name="petId">petId.</param>
|
||||
/// <param name="quantity">quantity.</param>
|
||||
/// <param name="shipDate">shipDate.</param>
|
||||
/// <param name="status">Order Status.</param>
|
||||
/// <param name="complete">complete (default to false).</param>
|
||||
public Order(long id = default(long), long petId = default(long), int quantity = default(int), DateTime shipDate = default(DateTime), StatusEnum? status = default(StatusEnum?), bool complete = false)
|
||||
{
|
||||
this.Id = id;
|
||||
this.PetId = petId;
|
||||
this.Quantity = quantity;
|
||||
this.ShipDate = shipDate;
|
||||
this.Status = status;
|
||||
this.Complete = complete;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Id
|
||||
/// </summary>
|
||||
[DataMember(Name = "id", EmitDefaultValue = false)]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets PetId
|
||||
/// </summary>
|
||||
[DataMember(Name = "petId", EmitDefaultValue = false)]
|
||||
public long PetId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Quantity
|
||||
/// </summary>
|
||||
[DataMember(Name = "quantity", EmitDefaultValue = false)]
|
||||
public int Quantity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets ShipDate
|
||||
/// </summary>
|
||||
[DataMember(Name = "shipDate", EmitDefaultValue = false)]
|
||||
public DateTime ShipDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Complete
|
||||
/// </summary>
|
||||
[DataMember(Name = "complete", EmitDefaultValue = true)]
|
||||
public bool Complete { get; set; }
|
||||
|
||||
/// <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 Order {\n");
|
||||
sb.Append(" Id: ").Append(Id).Append("\n");
|
||||
sb.Append(" PetId: ").Append(PetId).Append("\n");
|
||||
sb.Append(" Quantity: ").Append(Quantity).Append("\n");
|
||||
sb.Append(" ShipDate: ").Append(ShipDate).Append("\n");
|
||||
sb.Append(" Status: ").Append(Status).Append("\n");
|
||||
sb.Append(" Complete: ").Append(Complete).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 virtual string ToJson()
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
|
||||
}
|
||||
|
||||
/// <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 this.Equals(input as Order);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if Order instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of Order to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(Order input)
|
||||
{
|
||||
if (input == null)
|
||||
return false;
|
||||
|
||||
return
|
||||
(
|
||||
this.Id == input.Id ||
|
||||
this.Id.Equals(input.Id)
|
||||
) &&
|
||||
(
|
||||
this.PetId == input.PetId ||
|
||||
this.PetId.Equals(input.PetId)
|
||||
) &&
|
||||
(
|
||||
this.Quantity == input.Quantity ||
|
||||
this.Quantity.Equals(input.Quantity)
|
||||
) &&
|
||||
(
|
||||
this.ShipDate == input.ShipDate ||
|
||||
(this.ShipDate != null &&
|
||||
this.ShipDate.Equals(input.ShipDate))
|
||||
) &&
|
||||
(
|
||||
this.Status == input.Status ||
|
||||
this.Status.Equals(input.Status)
|
||||
) &&
|
||||
(
|
||||
this.Complete == input.Complete ||
|
||||
this.Complete.Equals(input.Complete)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hashCode = 41;
|
||||
hashCode = hashCode * 59 + this.Id.GetHashCode();
|
||||
hashCode = hashCode * 59 + this.PetId.GetHashCode();
|
||||
hashCode = hashCode * 59 + this.Quantity.GetHashCode();
|
||||
if (this.ShipDate != null)
|
||||
hashCode = hashCode * 59 + this.ShipDate.GetHashCode();
|
||||
hashCode = hashCode * 59 + this.Status.GetHashCode();
|
||||
hashCode = hashCode * 59 + this.Complete.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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* 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;
|
||||
|
||||
namespace Org.OpenAPITools.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A pet for sale in the pet store
|
||||
/// </summary>
|
||||
[DataContract(Name = "Pet")]
|
||||
public partial class Pet : IEquatable<Pet>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// pet status in the store
|
||||
/// </summary>
|
||||
/// <value>pet status in the store</value>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum StatusEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum Available for value: available
|
||||
/// </summary>
|
||||
[EnumMember(Value = "available")]
|
||||
Available = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Pending for value: pending
|
||||
/// </summary>
|
||||
[EnumMember(Value = "pending")]
|
||||
Pending = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Enum Sold for value: sold
|
||||
/// </summary>
|
||||
[EnumMember(Value = "sold")]
|
||||
Sold = 3
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// pet status in the store
|
||||
/// </summary>
|
||||
/// <value>pet status in the store</value>
|
||||
[DataMember(Name = "status", EmitDefaultValue = false)]
|
||||
public StatusEnum? Status { get; set; }
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Pet" /> class.
|
||||
/// </summary>
|
||||
[JsonConstructorAttribute]
|
||||
protected Pet() { }
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Pet" /> class.
|
||||
/// </summary>
|
||||
/// <param name="id">id.</param>
|
||||
/// <param name="category">category.</param>
|
||||
/// <param name="name">name (required).</param>
|
||||
/// <param name="photoUrls">photoUrls (required).</param>
|
||||
/// <param name="tags">tags.</param>
|
||||
/// <param name="status">pet status in the store.</param>
|
||||
public Pet(long id = default(long), Category category = default(Category), string name = default(string), List<string> photoUrls = default(List<string>), List<Tag> tags = default(List<Tag>), StatusEnum? status = default(StatusEnum?))
|
||||
{
|
||||
// to ensure "name" is required (not null)
|
||||
this.Name = name ?? throw new ArgumentNullException("name is a required property for Pet and cannot be null");
|
||||
// to ensure "photoUrls" is required (not null)
|
||||
this.PhotoUrls = photoUrls ?? throw new ArgumentNullException("photoUrls is a required property for Pet and cannot be null");
|
||||
this.Id = id;
|
||||
this.Category = category;
|
||||
this.Tags = tags;
|
||||
this.Status = status;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Id
|
||||
/// </summary>
|
||||
[DataMember(Name = "id", EmitDefaultValue = false)]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Category
|
||||
/// </summary>
|
||||
[DataMember(Name = "category", EmitDefaultValue = false)]
|
||||
public Category Category { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Name
|
||||
/// </summary>
|
||||
[DataMember(Name = "name", IsRequired = true, EmitDefaultValue = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets PhotoUrls
|
||||
/// </summary>
|
||||
[DataMember(Name = "photoUrls", IsRequired = true, EmitDefaultValue = false)]
|
||||
public List<string> PhotoUrls { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Tags
|
||||
/// </summary>
|
||||
[DataMember(Name = "tags", EmitDefaultValue = false)]
|
||||
public List<Tag> Tags { get; set; }
|
||||
|
||||
/// <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 Pet {\n");
|
||||
sb.Append(" Id: ").Append(Id).Append("\n");
|
||||
sb.Append(" Category: ").Append(Category).Append("\n");
|
||||
sb.Append(" Name: ").Append(Name).Append("\n");
|
||||
sb.Append(" PhotoUrls: ").Append(PhotoUrls).Append("\n");
|
||||
sb.Append(" Tags: ").Append(Tags).Append("\n");
|
||||
sb.Append(" Status: ").Append(Status).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 virtual string ToJson()
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
|
||||
}
|
||||
|
||||
/// <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 this.Equals(input as Pet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if Pet instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of Pet to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(Pet input)
|
||||
{
|
||||
if (input == null)
|
||||
return false;
|
||||
|
||||
return
|
||||
(
|
||||
this.Id == input.Id ||
|
||||
this.Id.Equals(input.Id)
|
||||
) &&
|
||||
(
|
||||
this.Category == input.Category ||
|
||||
(this.Category != null &&
|
||||
this.Category.Equals(input.Category))
|
||||
) &&
|
||||
(
|
||||
this.Name == input.Name ||
|
||||
(this.Name != null &&
|
||||
this.Name.Equals(input.Name))
|
||||
) &&
|
||||
(
|
||||
this.PhotoUrls == input.PhotoUrls ||
|
||||
this.PhotoUrls != null &&
|
||||
input.PhotoUrls != null &&
|
||||
this.PhotoUrls.SequenceEqual(input.PhotoUrls)
|
||||
) &&
|
||||
(
|
||||
this.Tags == input.Tags ||
|
||||
this.Tags != null &&
|
||||
input.Tags != null &&
|
||||
this.Tags.SequenceEqual(input.Tags)
|
||||
) &&
|
||||
(
|
||||
this.Status == input.Status ||
|
||||
this.Status.Equals(input.Status)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hashCode = 41;
|
||||
hashCode = hashCode * 59 + this.Id.GetHashCode();
|
||||
if (this.Category != null)
|
||||
hashCode = hashCode * 59 + this.Category.GetHashCode();
|
||||
if (this.Name != null)
|
||||
hashCode = hashCode * 59 + this.Name.GetHashCode();
|
||||
if (this.PhotoUrls != null)
|
||||
hashCode = hashCode * 59 + this.PhotoUrls.GetHashCode();
|
||||
if (this.Tags != null)
|
||||
hashCode = hashCode * 59 + this.Tags.GetHashCode();
|
||||
hashCode = hashCode * 59 + this.Status.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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* 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;
|
||||
|
||||
namespace Org.OpenAPITools.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A tag for a pet
|
||||
/// </summary>
|
||||
[DataContract(Name = "Tag")]
|
||||
public partial class Tag : IEquatable<Tag>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Tag" /> class.
|
||||
/// </summary>
|
||||
/// <param name="id">id.</param>
|
||||
/// <param name="name">name.</param>
|
||||
public Tag(long id = default(long), string name = default(string))
|
||||
{
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Id
|
||||
/// </summary>
|
||||
[DataMember(Name = "id", EmitDefaultValue = false)]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Name
|
||||
/// </summary>
|
||||
[DataMember(Name = "name", EmitDefaultValue = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <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 Tag {\n");
|
||||
sb.Append(" Id: ").Append(Id).Append("\n");
|
||||
sb.Append(" Name: ").Append(Name).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 virtual string ToJson()
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
|
||||
}
|
||||
|
||||
/// <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 this.Equals(input as Tag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if Tag instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of Tag to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(Tag input)
|
||||
{
|
||||
if (input == null)
|
||||
return false;
|
||||
|
||||
return
|
||||
(
|
||||
this.Id == input.Id ||
|
||||
this.Id.Equals(input.Id)
|
||||
) &&
|
||||
(
|
||||
this.Name == input.Name ||
|
||||
(this.Name != null &&
|
||||
this.Name.Equals(input.Name))
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hashCode = 41;
|
||||
hashCode = hashCode * 59 + this.Id.GetHashCode();
|
||||
if (this.Name != null)
|
||||
hashCode = hashCode * 59 + this.Name.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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* OpenAPI Petstore
|
||||
*
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* 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;
|
||||
|
||||
namespace Org.OpenAPITools.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A User who is purchasing from the pet store
|
||||
/// </summary>
|
||||
[DataContract(Name = "User")]
|
||||
public partial class User : IEquatable<User>, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="User" /> class.
|
||||
/// </summary>
|
||||
/// <param name="id">id.</param>
|
||||
/// <param name="username">username.</param>
|
||||
/// <param name="firstName">firstName.</param>
|
||||
/// <param name="lastName">lastName.</param>
|
||||
/// <param name="email">email.</param>
|
||||
/// <param name="password">password.</param>
|
||||
/// <param name="phone">phone.</param>
|
||||
/// <param name="userStatus">User Status.</param>
|
||||
public User(long id = default(long), string username = default(string), string firstName = default(string), string lastName = default(string), string email = default(string), string password = default(string), string phone = default(string), int userStatus = default(int))
|
||||
{
|
||||
this.Id = id;
|
||||
this.Username = username;
|
||||
this.FirstName = firstName;
|
||||
this.LastName = lastName;
|
||||
this.Email = email;
|
||||
this.Password = password;
|
||||
this.Phone = phone;
|
||||
this.UserStatus = userStatus;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Id
|
||||
/// </summary>
|
||||
[DataMember(Name = "id", EmitDefaultValue = false)]
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Username
|
||||
/// </summary>
|
||||
[DataMember(Name = "username", EmitDefaultValue = false)]
|
||||
public string Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets FirstName
|
||||
/// </summary>
|
||||
[DataMember(Name = "firstName", EmitDefaultValue = false)]
|
||||
public string FirstName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets LastName
|
||||
/// </summary>
|
||||
[DataMember(Name = "lastName", EmitDefaultValue = false)]
|
||||
public string LastName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Email
|
||||
/// </summary>
|
||||
[DataMember(Name = "email", EmitDefaultValue = false)]
|
||||
public string Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Password
|
||||
/// </summary>
|
||||
[DataMember(Name = "password", EmitDefaultValue = false)]
|
||||
public string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets Phone
|
||||
/// </summary>
|
||||
[DataMember(Name = "phone", EmitDefaultValue = false)]
|
||||
public string Phone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// User Status
|
||||
/// </summary>
|
||||
/// <value>User Status</value>
|
||||
[DataMember(Name = "userStatus", EmitDefaultValue = false)]
|
||||
public int UserStatus { get; set; }
|
||||
|
||||
/// <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 User {\n");
|
||||
sb.Append(" Id: ").Append(Id).Append("\n");
|
||||
sb.Append(" Username: ").Append(Username).Append("\n");
|
||||
sb.Append(" FirstName: ").Append(FirstName).Append("\n");
|
||||
sb.Append(" LastName: ").Append(LastName).Append("\n");
|
||||
sb.Append(" Email: ").Append(Email).Append("\n");
|
||||
sb.Append(" Password: ").Append(Password).Append("\n");
|
||||
sb.Append(" Phone: ").Append(Phone).Append("\n");
|
||||
sb.Append(" UserStatus: ").Append(UserStatus).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 virtual string ToJson()
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
|
||||
}
|
||||
|
||||
/// <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 this.Equals(input as User);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if User instances are equal
|
||||
/// </summary>
|
||||
/// <param name="input">Instance of User to be compared</param>
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(User input)
|
||||
{
|
||||
if (input == null)
|
||||
return false;
|
||||
|
||||
return
|
||||
(
|
||||
this.Id == input.Id ||
|
||||
this.Id.Equals(input.Id)
|
||||
) &&
|
||||
(
|
||||
this.Username == input.Username ||
|
||||
(this.Username != null &&
|
||||
this.Username.Equals(input.Username))
|
||||
) &&
|
||||
(
|
||||
this.FirstName == input.FirstName ||
|
||||
(this.FirstName != null &&
|
||||
this.FirstName.Equals(input.FirstName))
|
||||
) &&
|
||||
(
|
||||
this.LastName == input.LastName ||
|
||||
(this.LastName != null &&
|
||||
this.LastName.Equals(input.LastName))
|
||||
) &&
|
||||
(
|
||||
this.Email == input.Email ||
|
||||
(this.Email != null &&
|
||||
this.Email.Equals(input.Email))
|
||||
) &&
|
||||
(
|
||||
this.Password == input.Password ||
|
||||
(this.Password != null &&
|
||||
this.Password.Equals(input.Password))
|
||||
) &&
|
||||
(
|
||||
this.Phone == input.Phone ||
|
||||
(this.Phone != null &&
|
||||
this.Phone.Equals(input.Phone))
|
||||
) &&
|
||||
(
|
||||
this.UserStatus == input.UserStatus ||
|
||||
this.UserStatus.Equals(input.UserStatus)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code
|
||||
/// </summary>
|
||||
/// <returns>Hash code</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
int hashCode = 41;
|
||||
hashCode = hashCode * 59 + this.Id.GetHashCode();
|
||||
if (this.Username != null)
|
||||
hashCode = hashCode * 59 + this.Username.GetHashCode();
|
||||
if (this.FirstName != null)
|
||||
hashCode = hashCode * 59 + this.FirstName.GetHashCode();
|
||||
if (this.LastName != null)
|
||||
hashCode = hashCode * 59 + this.LastName.GetHashCode();
|
||||
if (this.Email != null)
|
||||
hashCode = hashCode * 59 + this.Email.GetHashCode();
|
||||
if (this.Password != null)
|
||||
hashCode = hashCode * 59 + this.Password.GetHashCode();
|
||||
if (this.Phone != null)
|
||||
hashCode = hashCode * 59 + this.Phone.GetHashCode();
|
||||
hashCode = hashCode * 59 + this.UserStatus.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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
159
samples/client/petstore/csharp-functions/generatedSrc/README.md
Normal file
159
samples/client/petstore/csharp-functions/generatedSrc/README.md
Normal file
@@ -0,0 +1,159 @@
|
||||
# Org.OpenAPITools - the C# library for the OpenAPI Petstore
|
||||
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
||||
|
||||
- API version: 1.0.0
|
||||
- SDK version: 1.0.0
|
||||
- Build package: org.openapitools.codegen.languages.CSharpFunctionsServerCodegen
|
||||
|
||||
<a name="frameworks-supported"></a>
|
||||
## Frameworks supported
|
||||
- .NET Core >=1.0
|
||||
- .NET Framework >=4.6
|
||||
- Mono/Xamarin >=vNext
|
||||
|
||||
<a name="dependencies"></a>
|
||||
## Dependencies
|
||||
|
||||
- [RestSharp](https://www.nuget.org/packages/RestSharp) - 106.11.7 or later
|
||||
- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 12.0.3 or later
|
||||
- [JsonSubTypes](https://www.nuget.org/packages/JsonSubTypes/) - 1.8.0 or later
|
||||
- [System.ComponentModel.Annotations](https://www.nuget.org/packages/System.ComponentModel.Annotations) - 5.0.0 or later
|
||||
|
||||
The DLLs included in the package may not be the latest version. We recommend using [NuGet](https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages:
|
||||
```
|
||||
Install-Package RestSharp
|
||||
Install-Package Newtonsoft.Json
|
||||
Install-Package JsonSubTypes
|
||||
Install-Package System.ComponentModel.Annotations
|
||||
```
|
||||
|
||||
NOTE: RestSharp versions greater than 105.1.0 have a bug which causes file uploads to fail. See [RestSharp#742](https://github.com/restsharp/RestSharp/issues/742).
|
||||
NOTE: RestSharp for .Net Core creates a new socket for each api call, which can lead to a socket exhaustion problem. See [RestSharp#1406](https://github.com/restsharp/RestSharp/issues/1406).
|
||||
|
||||
<a name="installation"></a>
|
||||
## Installation
|
||||
Generate the DLL using your preferred tool (e.g. `dotnet build`)
|
||||
|
||||
Then include the DLL (under the `bin` folder) in the C# project, and use the namespaces:
|
||||
```csharp
|
||||
using Org.OpenAPITools.Apis;
|
||||
using Org.OpenAPITools.Client;
|
||||
using Org.OpenAPITools.Models;
|
||||
```
|
||||
<a name="usage"></a>
|
||||
## Usage
|
||||
|
||||
To use the API client with a HTTP proxy, setup a `System.Net.WebProxy`
|
||||
```csharp
|
||||
Configuration c = new Configuration();
|
||||
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
|
||||
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
|
||||
c.Proxy = webProxy;
|
||||
```
|
||||
|
||||
<a name="getting-started"></a>
|
||||
## Getting Started
|
||||
|
||||
```csharp
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Org.OpenAPITools.Apis;
|
||||
using Org.OpenAPITools.Client;
|
||||
using Org.OpenAPITools.Models;
|
||||
|
||||
namespace Example
|
||||
{
|
||||
public class Example
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
|
||||
Configuration config = new Configuration();
|
||||
config.BasePath = "http://petstore.swagger.io/v2";
|
||||
// Configure OAuth2 access token for authorization: petstore_auth
|
||||
config.AccessToken = "YOUR_ACCESS_TOKEN";
|
||||
|
||||
var apiInstance = new PetApi(config);
|
||||
var pet = new Pet(); // Pet | Pet object that needs to be added to the store
|
||||
|
||||
try
|
||||
{
|
||||
// Add a new pet to the store
|
||||
Pet result = apiInstance.AddPet(pet);
|
||||
Debug.WriteLine(result);
|
||||
}
|
||||
catch (ApiException e)
|
||||
{
|
||||
Debug.Print("Exception when calling PetApi.AddPet: " + e.Message );
|
||||
Debug.Print("Status Code: "+ e.ErrorCode);
|
||||
Debug.Print(e.StackTrace);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<a name="documentation-for-api-endpoints"></a>
|
||||
## Documentation for API Endpoints
|
||||
|
||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
|
||||
Class | Method | HTTP request | Description
|
||||
------------ | ------------- | ------------- | -------------
|
||||
*PetApi* | [**AddPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store
|
||||
*PetApi* | [**DeletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
|
||||
*PetApi* | [**FindPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
|
||||
*PetApi* | [**FindPetsByTags**](docs/PetApi.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
|
||||
*PetApi* | [**GetPetById**](docs/PetApi.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
|
||||
*PetApi* | [**UpdatePet**](docs/PetApi.md#updatepet) | **PUT** /pet | Update an existing pet
|
||||
*PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
|
||||
*PetApi* | [**UploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
|
||||
*StoreApi* | [**DeleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
|
||||
*StoreApi* | [**GetInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status
|
||||
*StoreApi* | [**GetOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID
|
||||
*StoreApi* | [**PlaceOrder**](docs/StoreApi.md#placeorder) | **POST** /store/order | Place an order for a pet
|
||||
*UserApi* | [**CreateUser**](docs/UserApi.md#createuser) | **POST** /user | Create user
|
||||
*UserApi* | [**CreateUsersWithArrayInput**](docs/UserApi.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array
|
||||
*UserApi* | [**CreateUsersWithListInput**](docs/UserApi.md#createuserswithlistinput) | **POST** /user/createWithList | Creates list of users with given input array
|
||||
*UserApi* | [**DeleteUser**](docs/UserApi.md#deleteuser) | **DELETE** /user/{username} | Delete user
|
||||
*UserApi* | [**GetUserByName**](docs/UserApi.md#getuserbyname) | **GET** /user/{username} | Get user by user name
|
||||
*UserApi* | [**LoginUser**](docs/UserApi.md#loginuser) | **GET** /user/login | Logs user into the system
|
||||
*UserApi* | [**LogoutUser**](docs/UserApi.md#logoutuser) | **GET** /user/logout | Logs out current logged in user session
|
||||
*UserApi* | [**UpdateUser**](docs/UserApi.md#updateuser) | **PUT** /user/{username} | Updated user
|
||||
|
||||
|
||||
<a name="documentation-for-models"></a>
|
||||
## Documentation for Models
|
||||
|
||||
- [Models.ApiResponse](docs/ApiResponse.md)
|
||||
- [Models.Category](docs/Category.md)
|
||||
- [Models.Order](docs/Order.md)
|
||||
- [Models.Pet](docs/Pet.md)
|
||||
- [Models.Tag](docs/Tag.md)
|
||||
- [Models.User](docs/User.md)
|
||||
|
||||
|
||||
<a name="documentation-for-authorization"></a>
|
||||
## Documentation for Authorization
|
||||
|
||||
<a name="api_key"></a>
|
||||
### api_key
|
||||
|
||||
- **Type**: API key
|
||||
- **API key parameter name**: api_key
|
||||
- **Location**: HTTP header
|
||||
|
||||
<a name="petstore_auth"></a>
|
||||
### petstore_auth
|
||||
|
||||
- **Type**: OAuth
|
||||
- **Flow**: implicit
|
||||
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
|
||||
- **Scopes**:
|
||||
- write:pets: modify pets in your account
|
||||
- read:pets: read your pets
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"supports": {},
|
||||
"dependencies": {
|
||||
"FubarCoder.RestSharp.Portable.Core": "4.0.7",
|
||||
"FubarCoder.RestSharp.Portable.HttpClient": "4.0.7",
|
||||
"Newtonsoft.Json": "10.0.3",
|
||||
"JsonSubTypes": "1.2.0"
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.3": {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user