Fix package reference bug
This commit is contained in:
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Api Generator",
|
||||||
|
"type": "dotnet",
|
||||||
|
"request": "launch",
|
||||||
|
"projectPath": "C:/Users/Laurent/Desktop/api-generator/WebServer/WebServer.csproj"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"Environment": {
|
"Environment": {
|
||||||
"invite" : "powershell.exe",
|
"invite" : "powershell.exe",
|
||||||
"localRoot": "C:/Users/Laurent/Desktop/ag2/ApiGenerator/architecture/api/apis/example",
|
"localRoot": "C:/Users/Laurent/Desktop/api-generator/architecture/api/apis/",
|
||||||
"dockerRoot" : "/api/"
|
"dockerRoot" : "/api/"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ public class GenerationController : IController
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var task in process) await _genService.Launch(task);
|
foreach (var task in process)
|
||||||
|
{
|
||||||
|
await _genService.Launch(task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ namespace Generator.Daos;
|
|||||||
|
|
||||||
public abstract class AbstractDao
|
public abstract class AbstractDao
|
||||||
{
|
{
|
||||||
protected readonly ConfigManager ConfManager;
|
protected readonly ConfigManager _confManager;
|
||||||
|
protected readonly string _spec;
|
||||||
|
|
||||||
protected AbstractDao(ConfigManager confManager, string spec)
|
protected AbstractDao(ConfigManager confManager, string spec)
|
||||||
{
|
{
|
||||||
ConfManager = confManager;
|
_confManager = confManager;
|
||||||
|
_spec = spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractDao(ConfigManager confManager) : this(confManager, confManager.GetDefArgs().SpecIdentifier)
|
protected AbstractDao(ConfigManager confManager) : this(confManager, confManager.GetDefArgs().SpecIdentifier)
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ namespace Generator.Daos;
|
|||||||
|
|
||||||
public class CredentialsDao : AbstractDao
|
public class CredentialsDao : AbstractDao
|
||||||
{
|
{
|
||||||
public string Username => ConfManager.Credentials.Username;
|
public string Username => _confManager.Credentials.Username;
|
||||||
public string Password => ConfManager.Credentials.Password;
|
public string Password => _confManager.Credentials.Password;
|
||||||
|
|
||||||
public CredentialsDao(ConfigManager confManager)
|
public CredentialsDao(ConfigManager confManager)
|
||||||
: base(confManager, confManager.GetDefArgs().SpecIdentifier)
|
: base(confManager, confManager.GetDefArgs().SpecIdentifier)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public PackageDeletion GetPackageDeletion() => ConfManager.Credentials.ToPackageDeletion();
|
public PackageDeletion GetPackageDeletion() => _confManager.Credentials.ToPackageDeletion();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ public class DotnetDao : AbstractDao
|
|||||||
|
|
||||||
public DotnetConfig GetDotnetGenerate(GenerationType type, ISpecFile file)
|
public DotnetConfig GetDotnetGenerate(GenerationType type, ISpecFile file)
|
||||||
{
|
{
|
||||||
var config = ConfManager.Dotnet.Map(ConfManager, file);
|
var config = _confManager.Dotnet.Map(_confManager, file);
|
||||||
config.Type = type;
|
config.Type = type;
|
||||||
return config ;
|
return config ;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ namespace Generator.Daos;
|
|||||||
|
|
||||||
public class EnvironmentDao : AbstractDao
|
public class EnvironmentDao : AbstractDao
|
||||||
{
|
{
|
||||||
public Location ApiFolder() => new ([ConfManager.GetBase().LocalRoot, ConfManager.GetGeneral().ApiFolder]);
|
public Location ApiFolder() => new ([_confManager.GetBase().LocalRoot, _confManager.GetGeneral().ApiFolder]);
|
||||||
|
|
||||||
public string Invite => ConfManager.GetBase().Invite;
|
public string Invite => _confManager.GetBase().Invite;
|
||||||
|
|
||||||
public EnvironmentDao(ConfigManager confManager) : base(confManager)
|
public EnvironmentDao(ConfigManager confManager) : base(confManager)
|
||||||
{ }
|
{ }
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class JavaDao : AbstractDao
|
|||||||
public JavaDao(ConfigManager confManager) : base(confManager)
|
public JavaDao(ConfigManager confManager) : base(confManager)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public JavaConfig GetJavaGenerate(ISpecFile file) => ConfManager.Java.Map(ConfManager, file);
|
public JavaConfig GetJavaGenerate(ISpecFile file) => _confManager.Java.Map(_confManager, file);
|
||||||
|
|
||||||
public JavaPublish GetJavaPublish(GenerationType type, ISpecFile file)
|
public JavaPublish GetJavaPublish(GenerationType type, ISpecFile file)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class JavascriptDao : AbstractDao
|
|||||||
public JavascriptDao(ConfigManager confManager) : base(confManager, confManager.GetDefArgs().SpecIdentifier)
|
public JavascriptDao(ConfigManager confManager) : base(confManager, confManager.GetDefArgs().SpecIdentifier)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public JavascriptConfig GetJavascript(ISpecFile file) => ConfManager.Javascript.Map(ConfManager, file);
|
public JavascriptConfig GetJavascript(ISpecFile file) => _confManager.Javascript.Map(_confManager, file);
|
||||||
|
|
||||||
public JavascriptPublish GetJavascriptPublish(GenerationType type, ISpecFile file)
|
public JavascriptPublish GetJavascriptPublish(GenerationType type, ISpecFile file)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,11 +13,12 @@ public class OpenApiDao : AbstractDao
|
|||||||
|
|
||||||
public Location ConfigOf(string spec) => GetOpenApi(true, spec).SpecConfig;
|
public Location ConfigOf(string spec) => GetOpenApi(true, spec).SpecConfig;
|
||||||
|
|
||||||
public OpenApiConfig GetOpenApi(bool isLocal, string file)
|
public OpenApiConfig GetOpenApi(bool isLocal, string specPath)
|
||||||
{
|
{
|
||||||
var items = file.Split("/");
|
specPath = specPath ?? _spec;
|
||||||
var o = ConfManager.OpenApi.Map(ConfManager, items[0], items[1]);
|
string[] items = specPath.Split("/");
|
||||||
o.AddRoot(ConfManager.GetRoot(isLocal));
|
OpenApiConfig o = _confManager.OpenApi.Map(_confManager, items[0], items[1]);
|
||||||
|
o.AddRoot(_confManager.GetRoot(isLocal));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,12 +12,12 @@ public class TemplateDao : AbstractDao
|
|||||||
|
|
||||||
public PlantUmlExport PlantUml(ISpecFile file)
|
public PlantUmlExport PlantUml(ISpecFile file)
|
||||||
{
|
{
|
||||||
var config = ConfManager.Templates.Map();
|
var config = _confManager.Templates.Map();
|
||||||
return new PlantUmlExport
|
return new PlantUmlExport
|
||||||
{
|
{
|
||||||
LocalRoot = ConfManager.GetBase().LocalRoot,
|
LocalRoot = _confManager.GetBase().LocalRoot,
|
||||||
Template = config.PlantUml,
|
Template = config.PlantUml,
|
||||||
Output = ConfManager.GetGeneral().ApiFolder.ConcatenateWith([file.Folder, $"{file.Name}.puml"])
|
Output = _confManager.GetGeneral().ApiFolder.ConcatenateWith([file.Folder, $"{file.Name}.puml"])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,26 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<RootNamespace>Generator</RootNamespace>
|
<RootNamespace>Generator</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="appsettings.Development.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||||
|
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||||
|
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||||
<PackageReference Include="Microsoft.OpenApi" Version="1.6.13" />
|
<PackageReference Include="Microsoft.OpenApi" Version="1.6.13" />
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Core;
|
using Core;
|
||||||
using Core.Dto;
|
using Core.Dto;
|
||||||
using Core.Events;
|
using Core.Events;
|
||||||
|
using Core.Process;
|
||||||
using Generator.Controllers;
|
using Generator.Controllers;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@@ -44,9 +45,10 @@ public class GeneratorHostedService : IHostedService
|
|||||||
var startTime = DateTime.Now;
|
var startTime = DateTime.Now;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var extractor = new ArgumentsExtractor(_args);
|
ArgumentsExtractor extractor = new ArgumentsExtractor(_args);
|
||||||
|
string spec = extractor.Spec ?? "";
|
||||||
|
|
||||||
var genProcess = _preGenController.ComputeGeneration(extractor.Spec, extractor.GenType, extractor.PublishType);
|
GenerationProcess genProcess = _preGenController.ComputeGeneration(spec, extractor.GenType, extractor.PublishType);
|
||||||
|
|
||||||
if (extractor.ExportPuml) _exportController.PlantUml(genProcess.BaseFile);
|
if (extractor.ExportPuml) _exportController.PlantUml(genProcess.BaseFile);
|
||||||
|
|
||||||
@@ -55,7 +57,7 @@ public class GeneratorHostedService : IHostedService
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Critical, e, $"A critical exception was thrown. {e.Message}");
|
_logger.Log(LogLevel.Critical, "Critical failure : " + e.Message + "\nReason : " + e.StackTrace);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class CommandExecutor
|
|||||||
while (!output.EndOfStream)
|
while (!output.EndOfStream)
|
||||||
{
|
{
|
||||||
var line = await output.ReadLineAsync();
|
var line = await output.ReadLineAsync();
|
||||||
_emitter.Warn(this, line);
|
_emitter.Warn(this, line.ToString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,13 +40,17 @@ public class OpenApiDotnetServerBuilder : AbstractBuilder<OpenApiYaml>
|
|||||||
|
|
||||||
var templateFolder = new Location([_config.DockerRoot, _config.TemplateFolder]);
|
var templateFolder = new Location([_config.DockerRoot, _config.TemplateFolder]);
|
||||||
var packageFolder = new Location([_config.DockerRoot, _config.PackageFolderPath()]);
|
var packageFolder = new Location([_config.DockerRoot, _config.PackageFolderPath()]);
|
||||||
|
var outputDir =
|
||||||
|
_config.DockerRoot
|
||||||
|
.ConcatenateWith("generated")
|
||||||
|
.ConcatenateWith("localFeed");
|
||||||
|
|
||||||
var stringBuilder = new StringBuilder();
|
var stringBuilder = new StringBuilder();
|
||||||
stringBuilder
|
stringBuilder
|
||||||
.Append($"docker run --rm -it -v {_config.LocalRoot}:{_config.DockerRoot} {_config.BuildImage} /bin/sh -c '")
|
.Append($"docker run --rm -it -v {_config.LocalRoot}:{_config.DockerRoot} {_config.BuildImage} /bin/sh -c '")
|
||||||
.Append($"cp {templateFolder}/NuGet.config {packageFolder} && ")
|
.Append($"cp {templateFolder}/NuGet.config {packageFolder} && ")
|
||||||
.Append($"cd {packageFolder} && ")
|
.Append($"cd {packageFolder} && ")
|
||||||
.Append($"dotnet pack -c Release -o out -p:PackageVersion={SpecFile.Version}'");
|
.Append($"dotnet pack -c Release -o {outputDir} -p:PackageVersion={SpecFile.Version}'");
|
||||||
|
|
||||||
var command = stringBuilder.ToString();
|
var command = stringBuilder.ToString();
|
||||||
Executor.Register(command);
|
Executor.Register(command);
|
||||||
@@ -71,7 +75,7 @@ public class OpenApiDotnetServerBuilder : AbstractBuilder<OpenApiYaml>
|
|||||||
{"generatorVersion", "7.3.0"},
|
{"generatorVersion", "7.3.0"},
|
||||||
{"outputFolder", new Location([_config.DockerRoot, _config.OutputFolder()]).ToString()},
|
{"outputFolder", new Location([_config.DockerRoot, _config.OutputFolder()]).ToString()},
|
||||||
{"modelSuffix", SpecFile.Config.ModelSuffix},
|
{"modelSuffix", SpecFile.Config.ModelSuffix},
|
||||||
{"aspnetCoreVersion", "3.1"},
|
{"aspnetCoreVersion", "6.0"},
|
||||||
{"packageName", SpecFile.Config.NugetPackage},
|
{"packageName", SpecFile.Config.NugetPackage},
|
||||||
{"packageVersion", SpecFile.Info!["version"]},
|
{"packageVersion", SpecFile.Info!["version"]},
|
||||||
{"refs", SpecFile.ReferencedSchemas},
|
{"refs", SpecFile.ReferencedSchemas},
|
||||||
|
|||||||
33
Generator/Program.cs
Normal file
33
Generator/Program.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using CommandLine;
|
||||||
|
using Core.Dto;
|
||||||
|
using Core.Interfaces;
|
||||||
|
using Generator;
|
||||||
|
using Generator.DataSource;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Generator
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
|
||||||
|
public static async Task Main(string[] args)
|
||||||
|
{
|
||||||
|
var parserResult = LoadArguments(args);
|
||||||
|
var parsedArgs = parserResult.Value;
|
||||||
|
|
||||||
|
var hostBuilder = Host.CreateDefaultBuilder();
|
||||||
|
hostBuilder.ConfigureServices((hostContext, services) =>
|
||||||
|
{
|
||||||
|
IDataSourceLoader loader = new JsonLoader(services, hostContext.Configuration);
|
||||||
|
services.AddServices(loader, parsedArgs);
|
||||||
|
services.AddHostedService<GeneratorHostedService>();
|
||||||
|
});
|
||||||
|
await hostBuilder.Build().RunAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ParserResult<ArgumentsDto> LoadArguments(string[] args) => Parser.Default.ParseArguments<ArgumentsDto>(args);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Generator/Properties/launchSettings.json
Normal file
8
Generator/Properties/launchSettings.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"Generator": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "--name example/example"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using Core;
|
using Core;
|
||||||
|
using Core.Dto;
|
||||||
using Core.Interfaces;
|
using Core.Interfaces;
|
||||||
using Core.SpecConfig;
|
using Core.SpecConfig;
|
||||||
using Generator.Daos;
|
using Generator.Daos;
|
||||||
using Generator.DataSource.Packages;
|
|
||||||
using Generator.Mappers;
|
using Generator.Mappers;
|
||||||
|
|
||||||
namespace Generator.Repo;
|
namespace Generator.Repo;
|
||||||
@@ -15,17 +15,19 @@ public class RepositoryActions
|
|||||||
public RepositoryActions(CredentialsDao credentialsDao)
|
public RepositoryActions(CredentialsDao credentialsDao)
|
||||||
{
|
{
|
||||||
_credentialsDao = credentialsDao;
|
_credentialsDao = credentialsDao;
|
||||||
_requester = new NexusRequester(_credentialsDao.Username, _credentialsDao.Password);
|
//_requester = new NexusRequester(_credentialsDao.Username, _credentialsDao.Password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<PackageData>> GetVersions(Language language, string package)
|
public async Task<List<PackageData>> GetVersions(Language language, string package)
|
||||||
{
|
{
|
||||||
var packages = await _requester.GetVersions(language, package);
|
throw new NotImplementedException("Repository actions cannot be user for now. It is missing a repository requester");
|
||||||
|
List<PackageDataDto> packages = await _requester.GetVersions(language, package);
|
||||||
return packages.Map();
|
return packages.Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteVersion(string packageId)
|
public async Task DeleteVersion(string packageId)
|
||||||
{
|
{
|
||||||
|
throw new NotImplementedException("Repository actions cannot be user for now. It is missing a repository requester");
|
||||||
await _requester.DeleteVersion(packageId);
|
await _requester.DeleteVersion(packageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
81
Generator/appsettings.Development.json
Normal file
81
Generator/appsettings.Development.json
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"Environment": {
|
||||||
|
"invite": "powershell.exe",
|
||||||
|
"localRoot": "C:/Users/Laurent/Desktop/api-generator/architecture/api/apis/",
|
||||||
|
"dockerRoot": "/api/"
|
||||||
|
},
|
||||||
|
|
||||||
|
"DefaultArguments": {
|
||||||
|
"specIdentifier": "example/example",
|
||||||
|
"generatorVersion": "7.3.0"
|
||||||
|
},
|
||||||
|
|
||||||
|
"General": {
|
||||||
|
"apiFolder": "apis",
|
||||||
|
"outputFolder": "generated"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Dotnet": {
|
||||||
|
"ServerFolder": "dotnet-api",
|
||||||
|
"CommonFolder": "dotnet-models",
|
||||||
|
"ClientFolder": "dotnet-client"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Javascript": {
|
||||||
|
"Folder": "javascript-client"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Java": {
|
||||||
|
"Folder": "java"
|
||||||
|
},
|
||||||
|
|
||||||
|
"OpenApi": {
|
||||||
|
"OutputFolder": "openapi",
|
||||||
|
"GeneratorConfigFile": "openapi-generator-config.yaml",
|
||||||
|
"GeneratorIgnoreFile": ".openapi-generator-ignore",
|
||||||
|
"specExtension": ".yaml",
|
||||||
|
"schemasIdentifier": "-schemas",
|
||||||
|
"configExtension": ".json",
|
||||||
|
"configIdentifier": "-config"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Templates": {
|
||||||
|
"folder": "templates",
|
||||||
|
"plantUml": "plantUml.mustache",
|
||||||
|
"dotnetServerGeneratorConfig": "dotnet-server-generator-config.mustache",
|
||||||
|
"dotnetClientGeneratorConfig": "dotnet-client-generator-config.mustache",
|
||||||
|
"javaGeneratorConfig": "java-generator-config.mustache",
|
||||||
|
"serverIgnore": "dotnet-server-ignore.mustache",
|
||||||
|
"clientIgnore": "dotnet-client-ignore.mustache"
|
||||||
|
},
|
||||||
|
|
||||||
|
"DockerImages": {
|
||||||
|
"javascriptImage": "temporaly_missing_please_fill_javascripImage_field_in_appsettings.json",
|
||||||
|
"openapiGeneratorImageName": "openapitools/openapi-generator-cli",
|
||||||
|
"openapiGeneratorVersion": "7.3.0",
|
||||||
|
"openapiGeneratorImage": "openapitools/openapi-generator-cli:v7.3.0",
|
||||||
|
"dotnetSdkImage": "mcr.microsoft.com/dotnet/sdk:8.0",
|
||||||
|
"mavenImage": "maven:3.9.5"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Publish": {
|
||||||
|
"npmRegistry": "https://npm-registry-sample.url",
|
||||||
|
"nugetRegistry": "https://nuget-registry-sample.url",
|
||||||
|
"mavenRegistry": "https://maven-registry-sample.url"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Credentials": {
|
||||||
|
"token": "TOKEN_SAMPLE",
|
||||||
|
"email": "EMAIL_SAMPLE",
|
||||||
|
"username": "USERNAME_SAMPLE",
|
||||||
|
"password": "PASSWORD_SAMPLE",
|
||||||
|
"always-auth": "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
74
Generator/appsettings.json
Normal file
74
Generator/appsettings.json
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
{
|
||||||
|
"Environment": {
|
||||||
|
"invite" : "powershell.exe",
|
||||||
|
"localRoot": "C:/Users/Laurent/Desktop/api-generator/architecture/api/",
|
||||||
|
"dockerRoot" : "/api/"
|
||||||
|
},
|
||||||
|
|
||||||
|
"DefaultArguments": {
|
||||||
|
"specIdentifier" : "example/example",
|
||||||
|
"generatorVersion" : "7.3.0"
|
||||||
|
},
|
||||||
|
|
||||||
|
"General": {
|
||||||
|
"apiFolder" : "apis",
|
||||||
|
"outputFolder": "generated"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Dotnet" : {
|
||||||
|
"ServerFolder": "dotnet-api",
|
||||||
|
"CommonFolder": "dotnet-models",
|
||||||
|
"ClientFolder": "dotnet-client"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Javascript" : {
|
||||||
|
"Folder": "javascript-client"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Java": {
|
||||||
|
"Folder": "java"
|
||||||
|
},
|
||||||
|
|
||||||
|
"OpenApi" : {
|
||||||
|
"OutputFolder": "openapi",
|
||||||
|
"GeneratorConfigFile" : "openapi-generator-config.yaml",
|
||||||
|
"GeneratorIgnoreFile" : ".openapi-generator-ignore",
|
||||||
|
"specExtension": ".yaml",
|
||||||
|
"schemasIdentifier": "-schemas",
|
||||||
|
"configExtension": ".json",
|
||||||
|
"configIdentifier": "-config"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Templates" : {
|
||||||
|
"folder": "templates",
|
||||||
|
"plantUml": "plantUml.mustache",
|
||||||
|
"dotnetServerGeneratorConfig": "dotnet-server-generator-config.mustache",
|
||||||
|
"dotnetClientGeneratorConfig": "dotnet-client-generator-config.mustache",
|
||||||
|
"javaGeneratorConfig": "java-generator-config.mustache",
|
||||||
|
"serverIgnore": "dotnet-server-ignore.mustache",
|
||||||
|
"clientIgnore": "dotnet-client-ignore.mustache"
|
||||||
|
},
|
||||||
|
|
||||||
|
"DockerImages": {
|
||||||
|
"javascriptImage":"temporaly_missing_please_fill_javascripImage_field_in_appsettings.json",
|
||||||
|
"openapiGeneratorImageName":"openapitools/openapi-generator-cli",
|
||||||
|
"openapiGeneratorVersion":"7.3.0",
|
||||||
|
"openapiGeneratorImage":"openapitools/openapi-generator-cli:v7.3.0",
|
||||||
|
"dotnetSdkImage":"mcr.microsoft.com/dotnet/sdk:8.0",
|
||||||
|
"mavenImage":"maven:3.9.5"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Publish": {
|
||||||
|
"npmRegistry":"https://npm-registry-sample.url",
|
||||||
|
"nugetRegistry":"https://nuget-registry-sample.url",
|
||||||
|
"mavenRegistry":"https://maven-registry-sample.url"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Credentials": {
|
||||||
|
"token": "TOKEN_SAMPLE",
|
||||||
|
"email":"EMAIL_SAMPLE",
|
||||||
|
"username": "USERNAME_SAMPLE",
|
||||||
|
"password": "PASSWORD_SAMPLE",
|
||||||
|
"always-auth": "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"WebServer": {
|
"WebServer": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "--name example",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"DefaultArguments": {
|
|
||||||
"specIdentifier" : "meal/meal",
|
|
||||||
"generatorVersion" : "7.3.0"
|
|
||||||
},
|
|
||||||
|
|
||||||
"Environment": {
|
"Environment": {
|
||||||
"invite" : "powershell.exe",
|
"invite" : "powershell.exe",
|
||||||
"localRoot": "C:/Users/Laurent/Downloads/ApiGenerator/ApiGenerator/architecture/api",
|
"localRoot": "C:/Users/Laurent/Desktop/api-generator/architecture/api/apis/",
|
||||||
"dockerRoot" : "/api/"
|
"dockerRoot" : "/api/"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"DefaultArguments": {
|
||||||
|
"specIdentifier" : "example",
|
||||||
|
"generatorVersion" : "7.3.0"
|
||||||
|
},
|
||||||
|
|
||||||
"General": {
|
"General": {
|
||||||
"apiFolder" : "apis",
|
"apiFolder" : "apis",
|
||||||
"outputFolder": "generated"
|
"outputFolder": "generated"
|
||||||
@@ -50,31 +50,25 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"DockerImages": {
|
"DockerImages": {
|
||||||
"javascriptImage":"node:latest",
|
"javascriptImage":"temporaly_missing_please_fill_javascripImage_field_in_appsettings.json",
|
||||||
|
"openapiGeneratorImageName":"openapitools/openapi-generator-cli",
|
||||||
|
"openapiGeneratorVersion":"7.3.0",
|
||||||
"openapiGeneratorImage":"openapitools/openapi-generator-cli:v7.3.0",
|
"openapiGeneratorImage":"openapitools/openapi-generator-cli:v7.3.0",
|
||||||
"dotnetSdkImage":"mcr.microsoft.com/dotnet/sdk:8.0",
|
"dotnetSdkImage":"mcr.microsoft.com/dotnet/sdk:8.0",
|
||||||
"mavenImage":"maven:3.9.5"
|
"mavenImage":"maven:3.9.5"
|
||||||
},
|
},
|
||||||
|
|
||||||
"Publish": {
|
"Publish": {
|
||||||
"npmRegistry":"https://nexus.afelio.be/repository/fcsd-npm/",
|
"npmRegistry":"https://npm-registry-sample.url",
|
||||||
"nugetRegistry":"https://nexus.afelio.be/repository/fcsd-nuget/",
|
"nugetRegistry":"https://nuget-registry-sample.url",
|
||||||
"mavenRegistry":"https://nexus.afelio.be/repository/fcsd-maven-releases/"
|
"mavenRegistry":"https://maven-registry-sample.url"
|
||||||
},
|
},
|
||||||
|
|
||||||
"Credentials": {
|
"Credentials": {
|
||||||
"token": "b3a569a9-945a-3654-a78b-7da3e1d614d2",
|
"token": "TOKEN_SAMPLE",
|
||||||
"email":"laurent.crema@nrb.be",
|
"email":"EMAIL_SAMPLE",
|
||||||
"username": "fcsd",
|
"username": "USERNAME_SAMPLE",
|
||||||
"password": "@felio4FCSD2020",
|
"password": "PASSWORD_SAMPLE",
|
||||||
"always-auth": "true"
|
"always-auth": "true"
|
||||||
},
|
|
||||||
|
|
||||||
"Logging": {
|
|
||||||
"LogLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Microsoft.AspNetCore": "Warning"
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,4 +19,4 @@ components:
|
|||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
$ref: "example-schemas.yaml#/components/schemas/Example"
|
$ref: "example-schemas.yaml#/components/schemas/ExampleSchema"
|
||||||
@@ -25,7 +25,7 @@ components:
|
|||||||
schema:
|
schema:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: 'example-schemas.yaml#/components/schemas/Example'
|
$ref: 'example-schemas.yaml#/components/schemas/ExampleSchema'
|
||||||
400:
|
400:
|
||||||
description: 'The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).'
|
description: 'The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).'
|
||||||
403:
|
403:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ paths:
|
|||||||
|
|
||||||
components:
|
components:
|
||||||
schemas:
|
schemas:
|
||||||
Example:
|
ExampleSchema:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
src/**/Controllers/DefaultApi.cs
|
||||||
|
|
||||||
|
# Remove unused classes
|
||||||
|
src/**/Authentication/ApiAuthentication.cs
|
||||||
|
src/**/Formatters/InputFormatterStream.cs
|
||||||
|
src/**/OpenApi/TypeExtensions.cs
|
||||||
|
|
||||||
|
|
||||||
|
src/**/Converters/CustomEnumConverter.cs
|
||||||
|
# Remove all models
|
||||||
|
src/**/Models/*.cs
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
Example.API.sln
|
||||||
|
README.md
|
||||||
|
build.bat
|
||||||
|
build.sh
|
||||||
|
src/Example.API/.gitignore
|
||||||
|
src/Example.API/Attributes/ValidateModelStateAttribute.cs
|
||||||
|
src/Example.API/Controllers/ExampleApi.cs
|
||||||
|
src/Example.API/Example.API.csproj
|
||||||
|
src/Example.API/Example.API.nuspec
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
7.3.0
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.27428.2043
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.API", "src\Example.API\Example.API.csproj", "{FB3F427F-4893-4192-8CAD-BCC37BDB1232}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{FB3F427F-4893-4192-8CAD-BCC37BDB1232}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{FB3F427F-4893-4192-8CAD-BCC37BDB1232}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{FB3F427F-4893-4192-8CAD-BCC37BDB1232}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{FB3F427F-4893-4192-8CAD-BCC37BDB1232}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Example.API - ASP.NET Core 6.0 Server
|
||||||
|
|
||||||
|
Some demonstration stuff
|
||||||
|
|
||||||
|
## Upgrade NuGet Packages
|
||||||
|
|
||||||
|
NuGet packages get frequently updated.
|
||||||
|
|
||||||
|
To upgrade this solution to the latest version of all NuGet packages, use the dotnet-outdated tool.
|
||||||
|
|
||||||
|
|
||||||
|
Install dotnet-outdated tool:
|
||||||
|
|
||||||
|
```
|
||||||
|
dotnet tool install --global dotnet-outdated-tool
|
||||||
|
```
|
||||||
|
|
||||||
|
Upgrade only to new minor versions of packages
|
||||||
|
|
||||||
|
```
|
||||||
|
dotnet outdated --upgrade --version-lock Major
|
||||||
|
```
|
||||||
|
|
||||||
|
Upgrade to all new versions of packages (more likely to include breaking API changes)
|
||||||
|
|
||||||
|
```
|
||||||
|
dotnet outdated --upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
Linux/OS X:
|
||||||
|
|
||||||
|
```
|
||||||
|
sh build.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Windows:
|
||||||
|
|
||||||
|
```
|
||||||
|
build.bat
|
||||||
|
```
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
:: Generated by: https://openapi-generator.tech
|
||||||
|
::
|
||||||
|
|
||||||
|
@echo off
|
||||||
|
|
||||||
|
dotnet restore src\Example.API
|
||||||
|
dotnet build src\Example.API
|
||||||
|
echo Now, run the following to start the project: dotnet run -p src\Example.API\Example.API.csproj --launch-profile web.
|
||||||
|
echo.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Generated by: https://openapi-generator.tech
|
||||||
|
#
|
||||||
|
|
||||||
|
dotnet restore src/Example.API/ && \
|
||||||
|
dotnet build src/Example.API/ && \
|
||||||
|
echo "Now, run the following to start the project: dotnet run -p src/Example.API/Example.API.csproj --launch-profile web"
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
inputSpec: /api/generated/example/dotnet-api/example/openapi/openapi/openapi.yaml
|
||||||
|
generatorName: aspnetcore
|
||||||
|
templateDir: /api/templates/7.3.0/aspnetcore/
|
||||||
|
outputDir: /api/generated/example/dotnet-api/example
|
||||||
|
modelNameSuffix: Dto
|
||||||
|
|
||||||
|
typeMappings:
|
||||||
|
file: "IFormFile"
|
||||||
|
|
||||||
|
importMappings:
|
||||||
|
IFormFile: "Microsoft.AspNetCore.Http.IFormFile"
|
||||||
|
|
||||||
|
schemaMappings:
|
||||||
|
IFormFile: "Microsoft.AspNetCore.Http.IFormFile"
|
||||||
|
|
||||||
|
additionalProperties:
|
||||||
|
aspnetCoreVersion: "6.0"
|
||||||
|
packageName: "Example.API"
|
||||||
|
packageVersion: "1.0.0"
|
||||||
|
generateBody: "false"
|
||||||
|
classModifier: "abstract"
|
||||||
|
operationModifier: "abstract"
|
||||||
|
isLibrary: "true"
|
||||||
|
buildTarget: "library"
|
||||||
|
enumNameSuffix: ""
|
||||||
|
enumValueSuffix: ""
|
||||||
|
operationResultTask: true
|
||||||
|
operationIsAsync: true
|
||||||
|
removeModelPackage: true
|
||||||
|
|
||||||
|
packageReferences: [
|
||||||
|
{ include: "Example.Common", version: "1.0.0" },
|
||||||
|
]
|
||||||
|
|
||||||
|
modelNamespaces: [
|
||||||
|
"Example.Common.Models",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# OpenAPI Generator Ignore
|
||||||
|
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||||
|
|
||||||
|
# Use this file to prevent files from being overwritten by the generator.
|
||||||
|
# The patterns follow closely to .gitignore or .dockerignore.
|
||||||
|
|
||||||
|
# As an example, the C# client generator defines ApiClient.cs.
|
||||||
|
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||||
|
#ApiClient.cs
|
||||||
|
|
||||||
|
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||||
|
#foo/*/qux
|
||||||
|
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||||
|
#foo/**/qux
|
||||||
|
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can also negate patterns with an exclamation (!).
|
||||||
|
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||||
|
#docs/*.md
|
||||||
|
# Then explicitly reverse the ignore rule for a single file:
|
||||||
|
#!docs/README.md
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
README.md
|
||||||
|
openapi/openapi.yaml
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
7.3.0
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# OpenAPI YAML
|
||||||
|
This is a OpenAPI YAML built by the [openapi-generator](https://github.com/openapitools/openapi-generator) project.
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
openapi: 3.0.3
|
||||||
|
info:
|
||||||
|
description: Some demonstration stuff
|
||||||
|
title: Example API
|
||||||
|
version: 1.0.0
|
||||||
|
servers:
|
||||||
|
- url: /
|
||||||
|
paths:
|
||||||
|
/example/{exampleId}/:
|
||||||
|
get:
|
||||||
|
operationId: GetExampleById
|
||||||
|
parameters:
|
||||||
|
- description: the id of an example
|
||||||
|
in: path
|
||||||
|
name: exampleId
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/ExampleSchema'
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/ExampleSchema'
|
||||||
|
type: array
|
||||||
|
description: The example associated with this id
|
||||||
|
"400":
|
||||||
|
description: "The server cannot or will not process the request due to something\
|
||||||
|
\ that is perceived to be a client error (e.g., malformed request syntax,\
|
||||||
|
\ invalid request message framing, or deceptive request routing)."
|
||||||
|
"403":
|
||||||
|
description: "Forbidden: the server is refusing action, you do not have\
|
||||||
|
\ the necessary permissions this resource"
|
||||||
|
"500":
|
||||||
|
description: The server encountered an unexpected condition which prevented
|
||||||
|
it from fulfilling the request
|
||||||
|
summary: Get example associated with this id
|
||||||
|
tags:
|
||||||
|
- Example
|
||||||
|
components:
|
||||||
|
parameters:
|
||||||
|
exampleId:
|
||||||
|
description: the id of an example
|
||||||
|
in: path
|
||||||
|
name: exampleId
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/ExampleSchema'
|
||||||
|
schemas:
|
||||||
|
ExampleSchema:
|
||||||
|
example:
|
||||||
|
name: name
|
||||||
|
description: description
|
||||||
|
id: b1e0773f-ef0c-43cf-a1df-52d17f4a3017
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
example: b1e0773f-ef0c-43cf-a1df-52d17f4a3017
|
||||||
|
format: uuid
|
||||||
|
type: string
|
||||||
|
name:
|
||||||
|
nullable: false
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
nullable: true
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
362
architecture/api/generated/example/dotnet-api/example/src/Example.API/.gitignore
vendored
Normal file
362
architecture/api/generated/example/dotnet-api/example/src/Example.API/.gitignore
vendored
Normal file
@@ -0,0 +1,362 @@
|
|||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Coverlet is a free, cross platform Code Coverage Tool
|
||||||
|
coverage*.json
|
||||||
|
coverage*.xml
|
||||||
|
coverage*.info
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
|
.ionide/
|
||||||
|
|
||||||
|
# Fody - auto-generated XML schema
|
||||||
|
FodyWeavers.xsd
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
* Generated by: https://openapi-generator.tech
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Reflection;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
|
||||||
|
namespace Example.API.Attributes
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Model state validation attribute
|
||||||
|
/// </summary>
|
||||||
|
public class ValidateModelStateAttribute : ActionFilterAttribute
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Called before the action method is invoked
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
public override void OnActionExecuting(ActionExecutingContext context)
|
||||||
|
{
|
||||||
|
// Per https://blog.markvincze.com/how-to-validate-action-parameters-with-dataannotation-attributes/
|
||||||
|
if (context.ActionDescriptor is ControllerActionDescriptor descriptor)
|
||||||
|
{
|
||||||
|
foreach (var parameter in descriptor.MethodInfo.GetParameters())
|
||||||
|
{
|
||||||
|
object args = null;
|
||||||
|
if (context.ActionArguments.ContainsKey(parameter.Name))
|
||||||
|
{
|
||||||
|
args = context.ActionArguments[parameter.Name];
|
||||||
|
}
|
||||||
|
|
||||||
|
ValidateAttributes(parameter, args, context.ModelState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.ModelState.IsValid)
|
||||||
|
{
|
||||||
|
context.Result = new BadRequestObjectResult(context.ModelState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ValidateAttributes(ParameterInfo parameter, object args, ModelStateDictionary modelState)
|
||||||
|
{
|
||||||
|
foreach (var attributeData in parameter.CustomAttributes)
|
||||||
|
{
|
||||||
|
var attributeInstance = parameter.GetCustomAttribute(attributeData.AttributeType);
|
||||||
|
|
||||||
|
if (attributeInstance is ValidationAttribute validationAttribute)
|
||||||
|
{
|
||||||
|
var isValid = validationAttribute.IsValid(args);
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
modelState.AddModelError(parameter.Name, validationAttribute.FormatErrorMessage(parameter.Name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
* Generated by: https://openapi-generator.tech
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Example.API.Attributes;
|
||||||
|
using Example.Common.Models;
|
||||||
|
|
||||||
|
namespace Example.API.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[ApiController]
|
||||||
|
public abstract class ExampleApiController : ControllerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get example associated with this id
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exampleId">the id of an example</param>
|
||||||
|
/// <response code="200">The example associated with this id</response>
|
||||||
|
/// <response code="400">The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</response>
|
||||||
|
/// <response code="403">Forbidden: the server is refusing action, you do not have the necessary permissions this resource</response>
|
||||||
|
/// <response code="500">The server encountered an unexpected condition which prevented it from fulfilling the request</response>
|
||||||
|
[HttpGet]
|
||||||
|
[Route("/example/{exampleId}/")]
|
||||||
|
[ValidateModelState]
|
||||||
|
[ProducesResponseType(statusCode: 200, type: typeof(List<ExampleSchemaDto>))]
|
||||||
|
public abstract Task<ActionResult<List<ExampleSchemaDto>>> GetExampleById([FromRoute (Name = "exampleId")][Required]ExampleSchemaDto exampleId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Description>A library generated from a OpenAPI doc</Description>
|
||||||
|
<Copyright>No Copyright</Copyright>
|
||||||
|
<Authors>OpenAPI</Authors>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||||
|
<Version>1.0.0</Version>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AssemblyName>Example.API</AssemblyName>
|
||||||
|
<PackageId>Example.API</PackageId>
|
||||||
|
<UserSecretsId>b8788c5f-c835-4f90-b19b-4a8de7670ff5</UserSecretsId>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
<DockerfileContext>..\..</DockerfileContext>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0"/>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
|
||||||
|
<PackageReference Include="JsonSubTypes" Version="1.8.0" />
|
||||||
|
<PackageReference Include="Example.Common" Version="1.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<!--<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />-->
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<package >
|
||||||
|
<metadata>
|
||||||
|
<id>$id$</id>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<title>OpenAPI Library</title>
|
||||||
|
<authors>OpenAPI</authors>
|
||||||
|
<owners>OpenAPI</owners>
|
||||||
|
<licenseUrl>http://localhost</licenseUrl>
|
||||||
|
<!--
|
||||||
|
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
|
||||||
|
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
|
||||||
|
-->
|
||||||
|
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||||
|
<description>A library generated from a OpenAPI doc</description>
|
||||||
|
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
|
||||||
|
<copyright>No Copyright</copyright>
|
||||||
|
<tags>Example.API</tags>
|
||||||
|
</metadata>
|
||||||
|
</package>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<packageRestore>
|
||||||
|
<add key="enabled" value="True" />
|
||||||
|
<add key="automatic" value="True" />
|
||||||
|
</packageRestore>
|
||||||
|
<packageSources>
|
||||||
|
<add key="LocalFeed" value="/api/generated/localFeed/" />
|
||||||
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||||
|
</packageSources>
|
||||||
|
</configuration>
|
||||||
362
architecture/api/generated/example/dotnet-client/example/.gitignore
vendored
Normal file
362
architecture/api/generated/example/dotnet-client/example/.gitignore
vendored
Normal file
@@ -0,0 +1,362 @@
|
|||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Coverlet is a free, cross platform Code Coverage Tool
|
||||||
|
coverage*.json
|
||||||
|
coverage*.xml
|
||||||
|
coverage*.info
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
|
.ionide/
|
||||||
|
|
||||||
|
# Fody - auto-generated XML schema
|
||||||
|
FodyWeavers.xsd
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Remove unused
|
||||||
|
api/*.yaml
|
||||||
|
docs/*.md
|
||||||
|
|
||||||
|
src/**/Models/*Dto.cs
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
.gitignore
|
||||||
|
Example.API.sln
|
||||||
|
README.md
|
||||||
|
appveyor.yml
|
||||||
|
git_push.sh
|
||||||
|
src/Example.API/Api/ExampleApi.cs
|
||||||
|
src/Example.API/Client/ApiClient.cs
|
||||||
|
src/Example.API/Client/ApiException.cs
|
||||||
|
src/Example.API/Client/ApiResponse.cs
|
||||||
|
src/Example.API/Client/ClientUtils.cs
|
||||||
|
src/Example.API/Client/Configuration.cs
|
||||||
|
src/Example.API/Client/ExceptionFactory.cs
|
||||||
|
src/Example.API/Client/GlobalConfiguration.cs
|
||||||
|
src/Example.API/Client/HttpMethod.cs
|
||||||
|
src/Example.API/Client/IApiAccessor.cs
|
||||||
|
src/Example.API/Client/IAsynchronousClient.cs
|
||||||
|
src/Example.API/Client/IReadableConfiguration.cs
|
||||||
|
src/Example.API/Client/ISynchronousClient.cs
|
||||||
|
src/Example.API/Client/Multimap.cs
|
||||||
|
src/Example.API/Client/OpenAPIDateConverter.cs
|
||||||
|
src/Example.API/Client/RequestOptions.cs
|
||||||
|
src/Example.API/Client/RetryConfiguration.cs
|
||||||
|
src/Example.API/Example.API.csproj
|
||||||
|
src/Example.API/Models/AbstractOpenAPISchema.cs
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
7.3.0
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 2012
|
||||||
|
VisualStudioVersion = 12.0.0.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.0.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.API", "src\Example.API\Example.API.csproj", "{4012D40F-9D80-4032-AC82-156F90EE24E1}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{4012D40F-9D80-4032-AC82-156F90EE24E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4012D40F-9D80-4032-AC82-156F90EE24E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4012D40F-9D80-4032-AC82-156F90EE24E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4012D40F-9D80-4032-AC82-156F90EE24E1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
# Example.API - the C# library for the Example API
|
||||||
|
|
||||||
|
Some demonstration stuff
|
||||||
|
|
||||||
|
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.CSharpClientCodegen
|
||||||
|
|
||||||
|
<a id="frameworks-supported"></a>
|
||||||
|
## Frameworks supported
|
||||||
|
|
||||||
|
<a id="dependencies"></a>
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
- [RestSharp](https://www.nuget.org/packages/RestSharp) - 106.13.0 or later
|
||||||
|
- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 13.0.2 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 id="installation"></a>
|
||||||
|
## Installation
|
||||||
|
Run the following command to generate the DLL
|
||||||
|
- [Mac/Linux] `/bin/sh build.sh`
|
||||||
|
- [Windows] `build.bat`
|
||||||
|
|
||||||
|
Then include the DLL (under the `bin` folder) in the C# project, and use the namespaces:
|
||||||
|
```csharp
|
||||||
|
using Example.API.Api;
|
||||||
|
using Example.API.Client;
|
||||||
|
using Example.API.Models;
|
||||||
|
```
|
||||||
|
<a id="packaging"></a>
|
||||||
|
## Packaging
|
||||||
|
|
||||||
|
A `.nuspec` is included with the project. You can follow the Nuget quickstart to [create](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#create-the-package) and [publish](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#publish-the-package) packages.
|
||||||
|
|
||||||
|
This `.nuspec` uses placeholders from the `.csproj`, so build the `.csproj` directly:
|
||||||
|
|
||||||
|
```
|
||||||
|
nuget pack -Build -OutputDirectory out Example.API.csproj
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, publish to a [local feed](https://docs.microsoft.com/en-us/nuget/hosting-packages/local-feeds) or [other host](https://docs.microsoft.com/en-us/nuget/hosting-packages/overview) and consume the new package via Nuget as usual.
|
||||||
|
|
||||||
|
<a id="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 id="getting-started"></a>
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Example.API.Api;
|
||||||
|
using Example.API.Client;
|
||||||
|
using Example.API.Models;
|
||||||
|
|
||||||
|
namespace Example
|
||||||
|
{
|
||||||
|
public class Example
|
||||||
|
{
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
|
||||||
|
Configuration config = new Configuration();
|
||||||
|
config.BasePath = "http://localhost";
|
||||||
|
var apiInstance = new ExampleApi(config);
|
||||||
|
var exampleId = new ExampleSchemaDto(); // ExampleSchemaDto | the id of an example
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Get example associated with this id
|
||||||
|
List<ExampleSchemaDto> result = apiInstance.GetExampleById(exampleId);
|
||||||
|
Debug.WriteLine(result);
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
Debug.Print("Exception when calling ExampleApi.GetExampleById: " + e.Message );
|
||||||
|
Debug.Print("Status Code: "+ e.ErrorCode);
|
||||||
|
Debug.Print(e.StackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
<a id="documentation-for-api-endpoints"></a>
|
||||||
|
## Documentation for API Endpoints
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
Class | Method | HTTP request | Description
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
*ExampleApi* | [**GetExampleById**](docs/ExampleApi.md#getexamplebyid) | **GET** /example/{exampleId}/ | Get example associated with this id
|
||||||
|
|
||||||
|
|
||||||
|
<a id="documentation-for-models"></a>
|
||||||
|
## Documentation for Models
|
||||||
|
|
||||||
|
- [Models.ExampleSchemaDto](docs/ExampleSchemaDto.md)
|
||||||
|
|
||||||
|
|
||||||
|
<a id="documentation-for-authorization"></a>
|
||||||
|
## Documentation for Authorization
|
||||||
|
|
||||||
|
Endpoints do not require authorization.
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# auto-generated by OpenAPI Generator (https://github.com/OpenAPITools/openapi-generator)
|
||||||
|
#
|
||||||
|
image: Visual Studio 2019
|
||||||
|
clone_depth: 1
|
||||||
|
build_script:
|
||||||
|
- dotnet build -c Release
|
||||||
|
- dotnet test -c Release
|
||||||
|
after_build:
|
||||||
|
- dotnet pack .\src\Example.API\Example.API.csproj -o ../../output -c Release --no-build
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
||||||
|
#
|
||||||
|
# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
|
||||||
|
|
||||||
|
git_user_id=$1
|
||||||
|
git_repo_id=$2
|
||||||
|
release_note=$3
|
||||||
|
git_host=$4
|
||||||
|
|
||||||
|
if [ "$git_host" = "" ]; then
|
||||||
|
git_host="github.com"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$git_user_id" = "" ]; then
|
||||||
|
git_user_id="GIT_USER_ID"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$git_repo_id" = "" ]; then
|
||||||
|
git_repo_id="GIT_REPO_ID"
|
||||||
|
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$release_note" = "" ]; then
|
||||||
|
release_note="Minor update"
|
||||||
|
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initialize the local directory as a Git repository
|
||||||
|
git init
|
||||||
|
|
||||||
|
# Adds the files in the local repository and stages them for commit.
|
||||||
|
git add .
|
||||||
|
|
||||||
|
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
||||||
|
git commit -m "$release_note"
|
||||||
|
|
||||||
|
# Sets the new remote
|
||||||
|
git_remote=$(git remote)
|
||||||
|
if [ "$git_remote" = "" ]; then # git remote not defined
|
||||||
|
|
||||||
|
if [ "$GIT_TOKEN" = "" ]; then
|
||||||
|
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
|
||||||
|
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
|
||||||
|
else
|
||||||
|
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
git pull origin master
|
||||||
|
|
||||||
|
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||||
|
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
|
||||||
|
git push origin master 2>&1 | grep -v 'To https'
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
inputSpec: /api/generated/example/dotnet-client/example/openapi/openapi/openapi.yaml
|
||||||
|
generatorName: csharp
|
||||||
|
templateDir: /api/templates/7.3.0/csharp/
|
||||||
|
outputDir: /api/generated/example/dotnet-client/example
|
||||||
|
|
||||||
|
modelPackage: Models
|
||||||
|
excludeTests: true
|
||||||
|
|
||||||
|
modelNameSuffix: Dto
|
||||||
|
|
||||||
|
additionalProperties:
|
||||||
|
packageName: Example.API
|
||||||
|
packageVersion: 1.0.0
|
||||||
|
generateBody: "true"
|
||||||
|
classModifier: "abstract"
|
||||||
|
operationModifier: "abstract"
|
||||||
|
isLibrary: "true"
|
||||||
|
buildTarget: "library"
|
||||||
|
enumNameSuffix: ""
|
||||||
|
enumValueSuffix: ""
|
||||||
|
optionalEmitDefaultValues: true
|
||||||
|
operationIsAsync: false
|
||||||
|
|
||||||
|
packageReferences: [
|
||||||
|
{ include: "Example.Common", version: "1.0.0" },
|
||||||
|
]
|
||||||
|
|
||||||
|
modelNamespaces: [
|
||||||
|
"Example.Common.Models",
|
||||||
|
]
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# OpenAPI Generator Ignore
|
||||||
|
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||||
|
|
||||||
|
# Use this file to prevent files from being overwritten by the generator.
|
||||||
|
# The patterns follow closely to .gitignore or .dockerignore.
|
||||||
|
|
||||||
|
# As an example, the C# client generator defines ApiClient.cs.
|
||||||
|
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||||
|
#ApiClient.cs
|
||||||
|
|
||||||
|
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||||
|
#foo/*/qux
|
||||||
|
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||||
|
#foo/**/qux
|
||||||
|
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can also negate patterns with an exclamation (!).
|
||||||
|
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||||
|
#docs/*.md
|
||||||
|
# Then explicitly reverse the ignore rule for a single file:
|
||||||
|
#!docs/README.md
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.openapi-generator-ignore
|
||||||
|
README.md
|
||||||
|
openapi/openapi.yaml
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
7.3.0
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# OpenAPI YAML
|
||||||
|
This is a OpenAPI YAML built by the [openapi-generator](https://github.com/openapitools/openapi-generator) project.
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
openapi: 3.0.3
|
||||||
|
info:
|
||||||
|
description: Some demonstration stuff
|
||||||
|
title: Example API
|
||||||
|
version: 1.0.0
|
||||||
|
servers:
|
||||||
|
- url: /
|
||||||
|
paths:
|
||||||
|
/example/{exampleId}/:
|
||||||
|
get:
|
||||||
|
operationId: GetExampleById
|
||||||
|
parameters:
|
||||||
|
- description: the id of an example
|
||||||
|
in: path
|
||||||
|
name: exampleId
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/ExampleSchema'
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/ExampleSchema'
|
||||||
|
type: array
|
||||||
|
description: The example associated with this id
|
||||||
|
"400":
|
||||||
|
description: "The server cannot or will not process the request due to something\
|
||||||
|
\ that is perceived to be a client error (e.g., malformed request syntax,\
|
||||||
|
\ invalid request message framing, or deceptive request routing)."
|
||||||
|
"403":
|
||||||
|
description: "Forbidden: the server is refusing action, you do not have\
|
||||||
|
\ the necessary permissions this resource"
|
||||||
|
"500":
|
||||||
|
description: The server encountered an unexpected condition which prevented
|
||||||
|
it from fulfilling the request
|
||||||
|
summary: Get example associated with this id
|
||||||
|
tags:
|
||||||
|
- Example
|
||||||
|
components:
|
||||||
|
parameters:
|
||||||
|
exampleId:
|
||||||
|
description: the id of an example
|
||||||
|
in: path
|
||||||
|
name: exampleId
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/ExampleSchema'
|
||||||
|
schemas:
|
||||||
|
ExampleSchema:
|
||||||
|
example:
|
||||||
|
name: name
|
||||||
|
description: description
|
||||||
|
id: b1e0773f-ef0c-43cf-a1df-52d17f4a3017
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
example: b1e0773f-ef0c-43cf-a1df-52d17f4a3017
|
||||||
|
format: uuid
|
||||||
|
type: string
|
||||||
|
name:
|
||||||
|
nullable: false
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
nullable: true
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
@@ -0,0 +1,349 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* 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.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Mime;
|
||||||
|
using Example.API.Client;
|
||||||
|
using Example.API.Models;
|
||||||
|
using Example.Common.Models;
|
||||||
|
|
||||||
|
namespace Example.API.Api
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
|
/// </summary>
|
||||||
|
public interface IExampleApiSync : IApiAccessor
|
||||||
|
{
|
||||||
|
#region Synchronous Operations
|
||||||
|
/// <summary>
|
||||||
|
/// Get example associated with this id
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="Example.API.Client.ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="exampleId">the id of an example</param>
|
||||||
|
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||||
|
/// <returns>List<ExampleSchemaDto></returns>
|
||||||
|
List<ExampleSchemaDto> GetExampleById(ExampleSchemaDto exampleId, int operationIndex = 0);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get example associated with this id
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <exception cref="Example.API.Client.ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="exampleId">the id of an example</param>
|
||||||
|
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||||
|
/// <returns>ApiResponse of List<ExampleSchemaDto></returns>
|
||||||
|
ApiResponse<List<ExampleSchemaDto>> GetExampleByIdWithHttpInfo(ExampleSchemaDto exampleId, int operationIndex = 0);
|
||||||
|
#endregion Synchronous Operations
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
|
/// </summary>
|
||||||
|
public interface IExampleApiAsync : IApiAccessor
|
||||||
|
{
|
||||||
|
#region Asynchronous Operations
|
||||||
|
/// <summary>
|
||||||
|
/// Get example associated with this id
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <exception cref="Example.API.Client.ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="exampleId">the id of an example</param>
|
||||||
|
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns>Task of List<ExampleSchemaDto></returns>
|
||||||
|
System.Threading.Tasks.Task<List<ExampleSchemaDto>> GetExampleByIdAsync(ExampleSchemaDto exampleId, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get example associated with this id
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <exception cref="Example.API.Client.ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="exampleId">the id of an example</param>
|
||||||
|
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns>Task of ApiResponse (List<ExampleSchemaDto>)</returns>
|
||||||
|
System.Threading.Tasks.Task<ApiResponse<List<ExampleSchemaDto>>> GetExampleByIdWithHttpInfoAsync(ExampleSchemaDto exampleId, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
|
||||||
|
#endregion Asynchronous Operations
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
|
/// </summary>
|
||||||
|
public interface IExampleApi : IExampleApiSync, IExampleApiAsync
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
|
/// </summary>
|
||||||
|
public partial class ExampleApi : IExampleApi
|
||||||
|
{
|
||||||
|
private Example.API.Client.ExceptionFactory _exceptionFactory = (name, response) => null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ExampleApi"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ExampleApi() : this((string)null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ExampleApi"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ExampleApi(string basePath)
|
||||||
|
{
|
||||||
|
this.Configuration = Example.API.Client.Configuration.MergeConfigurations(
|
||||||
|
Example.API.Client.GlobalConfiguration.Instance,
|
||||||
|
new Example.API.Client.Configuration { BasePath = basePath }
|
||||||
|
);
|
||||||
|
this.Client = new Example.API.Client.ApiClient(this.Configuration.BasePath);
|
||||||
|
this.AsynchronousClient = new Example.API.Client.ApiClient(this.Configuration.BasePath);
|
||||||
|
this.ExceptionFactory = Example.API.Client.Configuration.DefaultExceptionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ExampleApi"/> class
|
||||||
|
/// using Configuration object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="configuration">An instance of Configuration</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ExampleApi(Example.API.Client.Configuration configuration)
|
||||||
|
{
|
||||||
|
if (configuration == null) throw new ArgumentNullException("configuration");
|
||||||
|
|
||||||
|
this.Configuration = Example.API.Client.Configuration.MergeConfigurations(
|
||||||
|
Example.API.Client.GlobalConfiguration.Instance,
|
||||||
|
configuration
|
||||||
|
);
|
||||||
|
this.Client = new Example.API.Client.ApiClient(this.Configuration.BasePath);
|
||||||
|
this.AsynchronousClient = new Example.API.Client.ApiClient(this.Configuration.BasePath);
|
||||||
|
ExceptionFactory = Example.API.Client.Configuration.DefaultExceptionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ExampleApi"/> class
|
||||||
|
/// using a Configuration object and client instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">The client interface for synchronous API access.</param>
|
||||||
|
/// <param name="asyncClient">The client interface for asynchronous API access.</param>
|
||||||
|
/// <param name="configuration">The configuration object.</param>
|
||||||
|
public ExampleApi(Example.API.Client.ISynchronousClient client, Example.API.Client.IAsynchronousClient asyncClient, Example.API.Client.IReadableConfiguration configuration)
|
||||||
|
{
|
||||||
|
if (client == null) throw new ArgumentNullException("client");
|
||||||
|
if (asyncClient == null) throw new ArgumentNullException("asyncClient");
|
||||||
|
if (configuration == null) throw new ArgumentNullException("configuration");
|
||||||
|
|
||||||
|
this.Client = client;
|
||||||
|
this.AsynchronousClient = asyncClient;
|
||||||
|
this.Configuration = configuration;
|
||||||
|
this.ExceptionFactory = Example.API.Client.Configuration.DefaultExceptionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The client for accessing this underlying API asynchronously.
|
||||||
|
/// </summary>
|
||||||
|
public Example.API.Client.IAsynchronousClient AsynchronousClient { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The client for accessing this underlying API synchronously.
|
||||||
|
/// </summary>
|
||||||
|
public Example.API.Client.ISynchronousClient Client { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the base path of the API client.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The base path</value>
|
||||||
|
public string GetBasePath()
|
||||||
|
{
|
||||||
|
return this.Configuration.BasePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the configuration object
|
||||||
|
/// </summary>
|
||||||
|
/// <value>An instance of the Configuration</value>
|
||||||
|
public Example.API.Client.IReadableConfiguration Configuration { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a factory method hook for the creation of exceptions.
|
||||||
|
/// </summary>
|
||||||
|
public Example.API.Client.ExceptionFactory ExceptionFactory
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported.");
|
||||||
|
}
|
||||||
|
return _exceptionFactory;
|
||||||
|
}
|
||||||
|
set { _exceptionFactory = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get example associated with this id
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="Example.API.Client.ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="exampleId">the id of an example</param>
|
||||||
|
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||||
|
/// <returns>List<ExampleSchemaDto></returns>
|
||||||
|
public List<ExampleSchemaDto> GetExampleById(ExampleSchemaDto exampleId, int operationIndex = 0)
|
||||||
|
{
|
||||||
|
Example.API.Client.ApiResponse<List<ExampleSchemaDto>> localVarResponse = GetExampleByIdWithHttpInfo(exampleId);
|
||||||
|
return localVarResponse.Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get example associated with this id
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="Example.API.Client.ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="exampleId">the id of an example</param>
|
||||||
|
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||||
|
/// <returns>ApiResponse of List<ExampleSchemaDto></returns>
|
||||||
|
public Example.API.Client.ApiResponse<List<ExampleSchemaDto>> GetExampleByIdWithHttpInfo(ExampleSchemaDto exampleId, int operationIndex = 0)
|
||||||
|
{
|
||||||
|
// verify the required parameter 'exampleId' is set
|
||||||
|
if (exampleId == null)
|
||||||
|
{
|
||||||
|
throw new Example.API.Client.ApiException(400, "Missing required parameter 'exampleId' when calling ExampleApi->GetExampleById");
|
||||||
|
}
|
||||||
|
|
||||||
|
Example.API.Client.RequestOptions localVarRequestOptions = new Example.API.Client.RequestOptions();
|
||||||
|
|
||||||
|
string[] _contentTypes = new string[] {
|
||||||
|
};
|
||||||
|
|
||||||
|
// to determine the Accept header
|
||||||
|
string[] _accepts = new string[] {
|
||||||
|
"application/json"
|
||||||
|
};
|
||||||
|
|
||||||
|
var localVarContentType = Example.API.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
|
||||||
|
if (localVarContentType != null)
|
||||||
|
{
|
||||||
|
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
var localVarAccept = Example.API.Client.ClientUtils.SelectHeaderAccept(_accepts);
|
||||||
|
if (localVarAccept != null)
|
||||||
|
{
|
||||||
|
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
|
||||||
|
}
|
||||||
|
|
||||||
|
localVarRequestOptions.PathParameters.Add("exampleId", Example.API.Client.ClientUtils.ParameterToString(exampleId)); // path parameter
|
||||||
|
|
||||||
|
localVarRequestOptions.Operation = "ExampleApi.GetExampleById";
|
||||||
|
localVarRequestOptions.OperationIndex = operationIndex;
|
||||||
|
|
||||||
|
|
||||||
|
// make the HTTP request
|
||||||
|
var localVarResponse = this.Client.Get<List<ExampleSchemaDto>>("/example/{exampleId}/", localVarRequestOptions, this.Configuration);
|
||||||
|
if (this.ExceptionFactory != null)
|
||||||
|
{
|
||||||
|
Exception _exception = this.ExceptionFactory("GetExampleById", localVarResponse);
|
||||||
|
if (_exception != null)
|
||||||
|
{
|
||||||
|
throw _exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return localVarResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get example associated with this id
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="Example.API.Client.ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="exampleId">the id of an example</param>
|
||||||
|
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns>Task of List<ExampleSchemaDto></returns>
|
||||||
|
public async System.Threading.Tasks.Task<List<ExampleSchemaDto>> GetExampleByIdAsync(ExampleSchemaDto exampleId, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||||
|
{
|
||||||
|
Example.API.Client.ApiResponse<List<ExampleSchemaDto>> localVarResponse = await GetExampleByIdWithHttpInfoAsync(exampleId, operationIndex, cancellationToken).ConfigureAwait(false);
|
||||||
|
return localVarResponse.Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get example associated with this id
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="Example.API.Client.ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="exampleId">the id of an example</param>
|
||||||
|
/// <param name="operationIndex">Index associated with the operation.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns>Task of ApiResponse (List<ExampleSchemaDto>)</returns>
|
||||||
|
public async System.Threading.Tasks.Task<Example.API.Client.ApiResponse<List<ExampleSchemaDto>>> GetExampleByIdWithHttpInfoAsync(ExampleSchemaDto exampleId, int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||||
|
{
|
||||||
|
// verify the required parameter 'exampleId' is set
|
||||||
|
if (exampleId == null)
|
||||||
|
{
|
||||||
|
throw new Example.API.Client.ApiException(400, "Missing required parameter 'exampleId' when calling ExampleApi->GetExampleById");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Example.API.Client.RequestOptions localVarRequestOptions = new Example.API.Client.RequestOptions();
|
||||||
|
|
||||||
|
string[] _contentTypes = new string[] {
|
||||||
|
};
|
||||||
|
|
||||||
|
// to determine the Accept header
|
||||||
|
string[] _accepts = new string[] {
|
||||||
|
"application/json"
|
||||||
|
};
|
||||||
|
|
||||||
|
var localVarContentType = Example.API.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
|
||||||
|
if (localVarContentType != null)
|
||||||
|
{
|
||||||
|
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
var localVarAccept = Example.API.Client.ClientUtils.SelectHeaderAccept(_accepts);
|
||||||
|
if (localVarAccept != null)
|
||||||
|
{
|
||||||
|
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
|
||||||
|
}
|
||||||
|
|
||||||
|
localVarRequestOptions.PathParameters.Add("exampleId", Example.API.Client.ClientUtils.ParameterToString(exampleId)); // path parameter
|
||||||
|
|
||||||
|
localVarRequestOptions.Operation = "ExampleApi.GetExampleById";
|
||||||
|
localVarRequestOptions.OperationIndex = operationIndex;
|
||||||
|
|
||||||
|
|
||||||
|
// make the HTTP request
|
||||||
|
var localVarResponse = await this.AsynchronousClient.GetAsync<List<ExampleSchemaDto>>("/example/{exampleId}/", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (this.ExceptionFactory != null)
|
||||||
|
{
|
||||||
|
Exception _exception = this.ExceptionFactory("GetExampleById", localVarResponse);
|
||||||
|
if (_exception != null)
|
||||||
|
{
|
||||||
|
throw _exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return localVarResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,833 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* 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 System.Web;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using RestSharp;
|
||||||
|
using RestSharp.Serializers;
|
||||||
|
using RestSharpMethod = RestSharp.Method;
|
||||||
|
using Polly;
|
||||||
|
|
||||||
|
namespace Example.API.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Allows RestSharp to Serialize/Deserialize JSON using our custom logic, but only when ContentType is JSON.
|
||||||
|
/// </summary>
|
||||||
|
internal class CustomJsonCodec : IRestSerializer, ISerializer, IDeserializer
|
||||||
|
{
|
||||||
|
private readonly IReadableConfiguration _configuration;
|
||||||
|
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 Example.API.Models.AbstractOpenAPISchema)
|
||||||
|
{
|
||||||
|
// the object to be serialized is an oneOf/anyOf schema
|
||||||
|
return ((Example.API.Models.AbstractOpenAPISchema)obj).ToJson();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return JsonConvert.SerializeObject(obj, _serializerSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Serialize(Parameter bodyParameter) => Serialize(bodyParameter.Value);
|
||||||
|
|
||||||
|
public T Deserialize<T>(RestResponse 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(RestResponse 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 ISerializer Serializer => this;
|
||||||
|
public IDeserializer Deserializer => this;
|
||||||
|
|
||||||
|
public string[] AcceptedContentTypes => RestSharp.ContentType.JsonAccept;
|
||||||
|
|
||||||
|
public SupportsContentType SupportsContentType => contentType =>
|
||||||
|
contentType.Value.EndsWith("json", StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
|
contentType.Value.EndsWith("javascript", StringComparison.InvariantCultureIgnoreCase);
|
||||||
|
|
||||||
|
public ContentType ContentType { get; set; } = RestSharp.ContentType.Json;
|
||||||
|
|
||||||
|
public DataFormat DataFormat => DataFormat.Json;
|
||||||
|
}
|
||||||
|
/// <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(RestRequest 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(RestRequest request, RestResponse response);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ApiClient" />, defaulting to the global configurations' base url.
|
||||||
|
/// </summary>
|
||||||
|
public ApiClient()
|
||||||
|
{
|
||||||
|
_baseUrl = Example.API.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(path, Method(method));
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
foreach (var file in fileParam.Value)
|
||||||
|
{
|
||||||
|
var bytes = ClientUtils.ReadAsBytes(file);
|
||||||
|
var fileStream = file as FileStream;
|
||||||
|
if (fileStream != null)
|
||||||
|
request.AddFile(fileParam.Key, bytes, System.IO.Path.GetFileName(fileStream.Name));
|
||||||
|
else
|
||||||
|
request.AddFile(fileParam.Key, bytes, "no_file_name_provided");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiResponse<T> ToApiResponse<T>(RestResponse<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.ContentHeaders != null)
|
||||||
|
{
|
||||||
|
foreach (var responseHeader in response.ContentHeaders)
|
||||||
|
{
|
||||||
|
transformed.Headers.Add(responseHeader.Name, ClientUtils.ParameterToString(responseHeader.Value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.Cookies != null)
|
||||||
|
{
|
||||||
|
foreach (var responseCookies in response.Cookies.Cast<Cookie>())
|
||||||
|
{
|
||||||
|
transformed.Cookies.Add(
|
||||||
|
new Cookie(
|
||||||
|
responseCookies.Name,
|
||||||
|
responseCookies.Value,
|
||||||
|
responseCookies.Path,
|
||||||
|
responseCookies.Domain)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return transformed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiResponse<T> Exec<T>(RestRequest request, RequestOptions options, IReadableConfiguration configuration)
|
||||||
|
{
|
||||||
|
var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl;
|
||||||
|
|
||||||
|
var cookies = new CookieContainer();
|
||||||
|
|
||||||
|
if (options.Cookies != null && options.Cookies.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var cookie in options.Cookies)
|
||||||
|
{
|
||||||
|
cookies.Add(new Cookie(cookie.Name, cookie.Value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var clientOptions = new RestClientOptions(baseUrl)
|
||||||
|
{
|
||||||
|
ClientCertificates = configuration.ClientCertificates,
|
||||||
|
CookieContainer = cookies,
|
||||||
|
MaxTimeout = configuration.Timeout,
|
||||||
|
Proxy = configuration.Proxy,
|
||||||
|
UserAgent = configuration.UserAgent,
|
||||||
|
UseDefaultCredentials = configuration.UseDefaultCredentials,
|
||||||
|
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||||
|
};
|
||||||
|
|
||||||
|
using (RestClient client = new RestClient(clientOptions,
|
||||||
|
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||||
|
{
|
||||||
|
InterceptRequest(request);
|
||||||
|
|
||||||
|
RestResponse<T> response;
|
||||||
|
if (RetryConfiguration.RetryPolicy != null)
|
||||||
|
{
|
||||||
|
var policy = RetryConfiguration.RetryPolicy;
|
||||||
|
var policyResult = policy.ExecuteAndCapture(() => client.Execute(request));
|
||||||
|
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||||
|
{
|
||||||
|
ErrorException = policyResult.FinalException
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response = client.Execute<T>(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||||
|
if (typeof(Example.API.Models.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response.Data = (T) typeof(T).GetMethod("FromJson").Invoke(null, new object[] { response.Content });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw ex.InnerException != null ? ex.InnerException : ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (typeof(T).Name == "Stream") // for binary response
|
||||||
|
{
|
||||||
|
response.Data = (T)(object)new MemoryStream(response.RawBytes);
|
||||||
|
}
|
||||||
|
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||||
|
{
|
||||||
|
response.Data = (T)(object)response.RawBytes;
|
||||||
|
}
|
||||||
|
else if (typeof(T).Name == "String") // for string response
|
||||||
|
{
|
||||||
|
response.Data = (T)(object)response.Content;
|
||||||
|
}
|
||||||
|
|
||||||
|
InterceptResponse(request, 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.Cast<Cookie>())
|
||||||
|
{
|
||||||
|
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 request, RequestOptions options, IReadableConfiguration configuration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
|
||||||
|
{
|
||||||
|
var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl;
|
||||||
|
|
||||||
|
var clientOptions = new RestClientOptions(baseUrl)
|
||||||
|
{
|
||||||
|
ClientCertificates = configuration.ClientCertificates,
|
||||||
|
MaxTimeout = configuration.Timeout,
|
||||||
|
Proxy = configuration.Proxy,
|
||||||
|
UserAgent = configuration.UserAgent,
|
||||||
|
UseDefaultCredentials = configuration.UseDefaultCredentials,
|
||||||
|
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
|
||||||
|
};
|
||||||
|
|
||||||
|
using (RestClient client = new RestClient(clientOptions,
|
||||||
|
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
|
||||||
|
{
|
||||||
|
InterceptRequest(request);
|
||||||
|
|
||||||
|
RestResponse<T> response;
|
||||||
|
if (RetryConfiguration.AsyncRetryPolicy != null)
|
||||||
|
{
|
||||||
|
var policy = RetryConfiguration.AsyncRetryPolicy;
|
||||||
|
var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false);
|
||||||
|
response = (policyResult.Outcome == OutcomeType.Successful) ? client.Deserialize<T>(policyResult.Result) : new RestResponse<T>(request)
|
||||||
|
{
|
||||||
|
ErrorException = policyResult.FinalException
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response = await client.ExecuteAsync<T>(request, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
|
||||||
|
if (typeof(Example.API.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);
|
||||||
|
}
|
||||||
|
else if (typeof(T).Name == "Byte[]") // for byte response
|
||||||
|
{
|
||||||
|
response.Data = (T)(object)response.RawBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
InterceptResponse(request, 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.Cast<Cookie>())
|
||||||
|
{
|
||||||
|
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), options, 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), options, 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), options, 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), options, 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), options, 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), options, 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), options, 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), options, 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), options, 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), options, 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), options, 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), options, 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), options, 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), options, config);
|
||||||
|
}
|
||||||
|
#endregion ISynchronousClient
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Example.API.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 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* 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 Example.API.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,247 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* 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.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace Example.API.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Utility functions providing some benefit to API client consumers.
|
||||||
|
/// </summary>
|
||||||
|
public static class ClientUtils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sanitize filename by removing the path
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Filename</param>
|
||||||
|
/// <returns>Filename</returns>
|
||||||
|
public static string SanitizeFilename(string filename)
|
||||||
|
{
|
||||||
|
Match match = Regex.Match(filename, @".*[/\\](.*)$");
|
||||||
|
return match.Success ? match.Groups[1].Value : filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert params to key/value pairs.
|
||||||
|
/// Use collectionFormat to properly format lists and collections.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collectionFormat">The swagger-supported collection format, one of: csv, tsv, ssv, pipes, multi</param>
|
||||||
|
/// <param name="name">Key name.</param>
|
||||||
|
/// <param name="value">Value object.</param>
|
||||||
|
/// <returns>A multimap of keys with 1..n associated values.</returns>
|
||||||
|
public static Multimap<string, string> ParameterToMultiMap(string collectionFormat, string name, object value)
|
||||||
|
{
|
||||||
|
var parameters = new Multimap<string, string>();
|
||||||
|
|
||||||
|
if (value is ICollection collection && collectionFormat == "multi")
|
||||||
|
{
|
||||||
|
foreach (var item in collection)
|
||||||
|
{
|
||||||
|
parameters.Add(name, ParameterToString(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (value is IDictionary dictionary)
|
||||||
|
{
|
||||||
|
if(collectionFormat == "deepObject") {
|
||||||
|
foreach (DictionaryEntry entry in dictionary)
|
||||||
|
{
|
||||||
|
parameters.Add(name + "[" + entry.Key + "]", ParameterToString(entry.Value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foreach (DictionaryEntry entry in dictionary)
|
||||||
|
{
|
||||||
|
parameters.Add(entry.Key.ToString(), ParameterToString(entry.Value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parameters.Add(name, ParameterToString(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
|
||||||
|
/// If parameter is a list, join the list with ",".
|
||||||
|
/// Otherwise just return the string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The parameter (header, path, query, form).</param>
|
||||||
|
/// <param name="configuration">An optional configuration instance, providing formatting options used in processing.</param>
|
||||||
|
/// <returns>Formatted string.</returns>
|
||||||
|
public static string ParameterToString(object obj, IReadableConfiguration configuration = null)
|
||||||
|
{
|
||||||
|
if (obj is DateTime dateTime)
|
||||||
|
// Return a formatted date string - Can be customized with Configuration.DateTimeFormat
|
||||||
|
// Defaults to an ISO 8601, using the known as a Round-trip date/time pattern ("o")
|
||||||
|
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
|
||||||
|
// For example: 2009-06-15T13:45:30.0000000
|
||||||
|
return dateTime.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat);
|
||||||
|
if (obj is DateTimeOffset dateTimeOffset)
|
||||||
|
// Return a formatted date string - Can be customized with Configuration.DateTimeFormat
|
||||||
|
// Defaults to an ISO 8601, using the known as a Round-trip date/time pattern ("o")
|
||||||
|
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
|
||||||
|
// For example: 2009-06-15T13:45:30.0000000
|
||||||
|
return dateTimeOffset.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat);
|
||||||
|
if (obj is bool boolean)
|
||||||
|
return boolean ? "true" : "false";
|
||||||
|
if (obj is ICollection collection) {
|
||||||
|
List<string> entries = new List<string>();
|
||||||
|
foreach (var entry in collection)
|
||||||
|
entries.Add(ParameterToString(entry, configuration));
|
||||||
|
return string.Join(",", entries);
|
||||||
|
}
|
||||||
|
if (obj is Enum && HasEnumMemberAttrValue(obj))
|
||||||
|
return GetEnumMemberAttrValue(obj);
|
||||||
|
|
||||||
|
return Convert.ToString(obj, CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializes the given object when not null. Otherwise return null.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The object to serialize.</param>
|
||||||
|
/// <returns>Serialized string.</returns>
|
||||||
|
public static string Serialize(object obj)
|
||||||
|
{
|
||||||
|
return obj != null ? Newtonsoft.Json.JsonConvert.SerializeObject(obj) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encode string in base64 format.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">string to be encoded.</param>
|
||||||
|
/// <returns>Encoded string.</returns>
|
||||||
|
public static string Base64Encode(string text)
|
||||||
|
{
|
||||||
|
return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert stream to byte array
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inputStream">Input stream to be converted</param>
|
||||||
|
/// <returns>Byte array</returns>
|
||||||
|
public static byte[] ReadAsBytes(Stream inputStream)
|
||||||
|
{
|
||||||
|
using (var ms = new MemoryStream())
|
||||||
|
{
|
||||||
|
inputStream.CopyTo(ms);
|
||||||
|
return ms.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Select the Content-Type header's value from the given content-type array:
|
||||||
|
/// if JSON type exists in the given array, use it;
|
||||||
|
/// otherwise use the first one defined in 'consumes'
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="contentTypes">The Content-Type array to select from.</param>
|
||||||
|
/// <returns>The Content-Type header to use.</returns>
|
||||||
|
public static string SelectHeaderContentType(string[] contentTypes)
|
||||||
|
{
|
||||||
|
if (contentTypes.Length == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
foreach (var contentType in contentTypes)
|
||||||
|
{
|
||||||
|
if (IsJsonMime(contentType))
|
||||||
|
return contentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
return contentTypes[0]; // use the first content type specified in 'consumes'
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Select the Accept header's value from the given accepts array:
|
||||||
|
/// if JSON exists in the given array, use it;
|
||||||
|
/// otherwise use all of them (joining into a string)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="accepts">The accepts array to select from.</param>
|
||||||
|
/// <returns>The Accept header to use.</returns>
|
||||||
|
public static string SelectHeaderAccept(string[] accepts)
|
||||||
|
{
|
||||||
|
if (accepts.Length == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (accepts.Contains("application/json", StringComparer.OrdinalIgnoreCase))
|
||||||
|
return "application/json";
|
||||||
|
|
||||||
|
return string.Join(",", accepts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
|
||||||
|
/// </summary>
|
||||||
|
public static readonly Regex JsonRegex = new Regex("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the given MIME is a JSON MIME.
|
||||||
|
/// JSON MIME examples:
|
||||||
|
/// application/json
|
||||||
|
/// application/json; charset=UTF8
|
||||||
|
/// APPLICATION/JSON
|
||||||
|
/// application/vnd.company+json
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mime">MIME</param>
|
||||||
|
/// <returns>Returns True if MIME type is json.</returns>
|
||||||
|
public static bool IsJsonMime(string mime)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(mime)) return false;
|
||||||
|
|
||||||
|
return JsonRegex.IsMatch(mime) || mime.Equals("application/json-patch+json");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is the Enum decorated with EnumMember Attribute
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="enumVal"></param>
|
||||||
|
/// <returns>true if found</returns>
|
||||||
|
private static bool HasEnumMemberAttrValue(object enumVal)
|
||||||
|
{
|
||||||
|
if (enumVal == null)
|
||||||
|
throw new ArgumentNullException(nameof(enumVal));
|
||||||
|
var enumType = enumVal.GetType();
|
||||||
|
var memInfo = enumType.GetMember(enumVal.ToString() ?? throw new InvalidOperationException());
|
||||||
|
var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType<EnumMemberAttribute>().FirstOrDefault();
|
||||||
|
if (attr != null) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the EnumMember value
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="enumVal"></param>
|
||||||
|
/// <returns>EnumMember value as string otherwise null</returns>
|
||||||
|
private static string GetEnumMemberAttrValue(object enumVal)
|
||||||
|
{
|
||||||
|
if (enumVal == null)
|
||||||
|
throw new ArgumentNullException(nameof(enumVal));
|
||||||
|
var enumType = enumVal.GetType();
|
||||||
|
var memInfo = enumType.GetMember(enumVal.ToString() ?? throw new InvalidOperationException());
|
||||||
|
var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType<EnumMemberAttribute>().FirstOrDefault();
|
||||||
|
if (attr != null)
|
||||||
|
{
|
||||||
|
return attr.Value;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,612 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Security;
|
||||||
|
|
||||||
|
namespace Example.API.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);
|
||||||
|
}
|
||||||
|
if (status == 0)
|
||||||
|
{
|
||||||
|
return new ApiException(status,
|
||||||
|
string.Format("Error calling {0}: {1}", methodName, response.ErrorText), response.ErrorText);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
|
||||||
|
private bool _useDefaultCredentials = false;
|
||||||
|
|
||||||
|
/// <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;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the operation servers defined in the OpenAPI spec.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The operation servers</value>
|
||||||
|
private IReadOnlyDictionary<string, List<IReadOnlyDictionary<string, object>>> _operationServers;
|
||||||
|
|
||||||
|
#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 = WebUtility.UrlEncode("OpenAPI-Generator/1.0.0/csharp");
|
||||||
|
BasePath = "http://localhost";
|
||||||
|
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", ""},
|
||||||
|
{"description", "No description provided"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
OperationServers = new Dictionary<string, List<IReadOnlyDictionary<string, object>>>()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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://localhost") : 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>
|
||||||
|
/// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) will be sent along to the server. The default is false.
|
||||||
|
/// </summary>
|
||||||
|
public virtual bool UseDefaultCredentials
|
||||||
|
{
|
||||||
|
get { return _useDefaultCredentials; }
|
||||||
|
set { _useDefaultCredentials = 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>
|
||||||
|
/// Gets or sets the operation servers.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The operation servers.</value>
|
||||||
|
public virtual IReadOnlyDictionary<string, List<IReadOnlyDictionary<string, object>>> OperationServers
|
||||||
|
{
|
||||||
|
get { return _operationServers; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Operation servers may not be null.");
|
||||||
|
}
|
||||||
|
_operationServers = 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(Servers, 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)
|
||||||
|
{
|
||||||
|
return GetServerUrl(Servers, index, inputVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns URL based on operation server settings.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="operation">Operation associated with the request path.</param>
|
||||||
|
/// <param name="index">Array index of the server settings.</param>
|
||||||
|
/// <return>The operation server URL.</return>
|
||||||
|
public string GetOperationServerUrl(string operation, int index)
|
||||||
|
{
|
||||||
|
return GetOperationServerUrl(operation, index, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns URL based on operation server settings.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="operation">Operation associated with the request path.</param>
|
||||||
|
/// <param name="index">Array index of the server settings.</param>
|
||||||
|
/// <param name="inputVariables">Dictionary of the variables and the corresponding values.</param>
|
||||||
|
/// <return>The operation server URL.</return>
|
||||||
|
public string GetOperationServerUrl(string operation, int index, Dictionary<string, string> inputVariables)
|
||||||
|
{
|
||||||
|
if (operation != null && OperationServers.TryGetValue(operation, out var operationServer))
|
||||||
|
{
|
||||||
|
return GetServerUrl(operationServer, index, inputVariables);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns URL based on server settings.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="servers">Dictionary of server settings.</param>
|
||||||
|
/// <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>
|
||||||
|
private string GetServerUrl(IList<IReadOnlyDictionary<string, object>> servers, 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"];
|
||||||
|
|
||||||
|
if (server.ContainsKey("variables"))
|
||||||
|
{
|
||||||
|
// go through each 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets and Sets the RemoteCertificateValidationCallback
|
||||||
|
/// </summary>
|
||||||
|
public RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; set; }
|
||||||
|
|
||||||
|
#endregion Properties
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a string with essential information for debugging.
|
||||||
|
/// </summary>
|
||||||
|
public static string ToDebugReport()
|
||||||
|
{
|
||||||
|
string report = "C# SDK (Example.API) 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,
|
||||||
|
ClientCertificates = second.ClientCertificates ?? first.ClientCertificates,
|
||||||
|
UseDefaultCredentials = second.UseDefaultCredentials,
|
||||||
|
RemoteCertificateValidationCallback = second.RemoteCertificateValidationCallback ?? first.RemoteCertificateValidationCallback,
|
||||||
|
};
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
#endregion Static Members
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Example.API.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,67 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Example.API.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="GlobalConfiguration"/> provides a compile-time extension point for globally configuring
|
||||||
|
/// API Clients.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// A customized implementation via partial class may reside in another file and may
|
||||||
|
/// be excluded from automatic generation via a .openapi-generator-ignore file.
|
||||||
|
/// </remarks>
|
||||||
|
public partial class GlobalConfiguration : Configuration
|
||||||
|
{
|
||||||
|
#region Private Members
|
||||||
|
|
||||||
|
private static readonly object GlobalConfigSync = new { };
|
||||||
|
private static IReadableConfiguration _globalConfiguration;
|
||||||
|
|
||||||
|
#endregion Private Members
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
private GlobalConfiguration()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public GlobalConfiguration(IDictionary<string, string> defaultHeader, IDictionary<string, string> apiKey, IDictionary<string, string> apiKeyPrefix, string basePath = "http://localhost:3000/api") : base(defaultHeader, apiKey, apiKeyPrefix, basePath)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static GlobalConfiguration()
|
||||||
|
{
|
||||||
|
Instance = new GlobalConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Constructors
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the default Configuration.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Configuration.</value>
|
||||||
|
public static IReadableConfiguration Instance
|
||||||
|
{
|
||||||
|
get { return _globalConfiguration; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
lock (GlobalConfigSync)
|
||||||
|
{
|
||||||
|
_globalConfiguration = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace Example.API.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Http methods supported by swagger
|
||||||
|
/// </summary>
|
||||||
|
public enum HttpMethod
|
||||||
|
{
|
||||||
|
/// <summary>HTTP GET request.</summary>
|
||||||
|
Get,
|
||||||
|
/// <summary>HTTP POST request.</summary>
|
||||||
|
Post,
|
||||||
|
/// <summary>HTTP PUT request.</summary>
|
||||||
|
Put,
|
||||||
|
/// <summary>HTTP DELETE request.</summary>
|
||||||
|
Delete,
|
||||||
|
/// <summary>HTTP HEAD request.</summary>
|
||||||
|
Head,
|
||||||
|
/// <summary>HTTP OPTIONS request.</summary>
|
||||||
|
Options,
|
||||||
|
/// <summary>HTTP PATCH request.</summary>
|
||||||
|
Patch
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Example.API.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,100 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Example.API.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contract for Asynchronous RESTful API interactions.
|
||||||
|
///
|
||||||
|
/// This interface allows consumers to provide a custom API accessor client.
|
||||||
|
/// </summary>
|
||||||
|
public interface IAsynchronousClient
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a non-blocking call to some <paramref name="path"/> using the GET http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>A task eventually representing the response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
Task<ApiResponse<T>> GetAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a non-blocking call to some <paramref name="path"/> using the POST http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>A task eventually representing the response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
Task<ApiResponse<T>> PostAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a non-blocking call to some <paramref name="path"/> using the PUT http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>A task eventually representing the response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
Task<ApiResponse<T>> PutAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a non-blocking call to some <paramref name="path"/> using the DELETE http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>A task eventually representing the response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
Task<ApiResponse<T>> DeleteAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a non-blocking call to some <paramref name="path"/> using the HEAD http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>A task eventually representing the response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
Task<ApiResponse<T>> HeadAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a non-blocking call to some <paramref name="path"/> using the OPTIONS http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>A task eventually representing the response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
Task<ApiResponse<T>> OptionsAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a non-blocking call to some <paramref name="path"/> using the PATCH http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>A task eventually representing the response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
Task<ApiResponse<T>> PatchAsync<T>(string path, RequestOptions options, IReadableConfiguration configuration = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
using System.Net.Security;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
|
||||||
|
namespace Example.API.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a readable-only configuration contract.
|
||||||
|
/// </summary>
|
||||||
|
public interface IReadableConfiguration
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the access token.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Access token.</value>
|
||||||
|
string AccessToken { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the API key.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>API key.</value>
|
||||||
|
IDictionary<string, string> ApiKey { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the API key prefix.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>API key prefix.</value>
|
||||||
|
IDictionary<string, string> ApiKeyPrefix { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the base path.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Base path.</value>
|
||||||
|
string BasePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the date time format.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Date time format.</value>
|
||||||
|
string DateTimeFormat { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the default header.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Default header.</value>
|
||||||
|
[Obsolete("Use DefaultHeaders instead.")]
|
||||||
|
IDictionary<string, string> DefaultHeader { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the default headers.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Default headers.</value>
|
||||||
|
IDictionary<string, string> DefaultHeaders { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the temp folder path.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Temp folder path.</value>
|
||||||
|
string TempFolderPath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the HTTP connection timeout (in milliseconds)
|
||||||
|
/// </summary>
|
||||||
|
/// <value>HTTP connection timeout.</value>
|
||||||
|
int Timeout { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the proxy.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Proxy.</value>
|
||||||
|
WebProxy Proxy { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the user agent.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>User agent.</value>
|
||||||
|
string UserAgent { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the username.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Username.</value>
|
||||||
|
string Username { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the password.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Password.</value>
|
||||||
|
string Password { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determine whether or not the "default credentials" (e.g. the user account under which the current process is running) will be sent along to the server. The default is false.
|
||||||
|
/// </summary>
|
||||||
|
bool UseDefaultCredentials { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the servers associated with the operation.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>Operation servers.</value>
|
||||||
|
IReadOnlyDictionary<string, List<IReadOnlyDictionary<string, object>>> OperationServers { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the API key with prefix.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
|
||||||
|
/// <returns>API key with prefix.</returns>
|
||||||
|
string GetApiKeyWithPrefix(string apiKeyIdentifier);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Operation server url at the provided index.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="operation">Operation server name.</param>
|
||||||
|
/// <param name="index">Index of the operation server settings.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
string GetOperationServerUrl(string operation, int index);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets certificate collection to be sent with requests.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>X509 Certificate collection.</value>
|
||||||
|
X509CertificateCollection ClientCertificates { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Callback function for handling the validation of remote certificates. Useful for certificate pinning and
|
||||||
|
/// overriding certificate errors in the scope of a request.
|
||||||
|
/// </summary>
|
||||||
|
RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Example.API.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contract for Synchronous RESTful API interactions.
|
||||||
|
///
|
||||||
|
/// This interface allows consumers to provide a custom API accessor client.
|
||||||
|
/// </summary>
|
||||||
|
public interface ISynchronousClient
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a blocking call to some <paramref name="path"/> using the GET http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>The response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
ApiResponse<T> Get<T>(string path, RequestOptions options, IReadableConfiguration configuration = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a blocking call to some <paramref name="path"/> using the POST http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>The response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
ApiResponse<T> Post<T>(string path, RequestOptions options, IReadableConfiguration configuration = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a blocking call to some <paramref name="path"/> using the PUT http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>The response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
ApiResponse<T> Put<T>(string path, RequestOptions options, IReadableConfiguration configuration = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a blocking call to some <paramref name="path"/> using the DELETE http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>The response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
ApiResponse<T> Delete<T>(string path, RequestOptions options, IReadableConfiguration configuration = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a blocking call to some <paramref name="path"/> using the HEAD http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>The response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
ApiResponse<T> Head<T>(string path, RequestOptions options, IReadableConfiguration configuration = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a blocking call to some <paramref name="path"/> using the OPTIONS http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>The response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
ApiResponse<T> Options<T>(string path, RequestOptions options, IReadableConfiguration configuration = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Executes a blocking call to some <paramref name="path"/> using the PATCH http verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The relative path to invoke.</param>
|
||||||
|
/// <param name="options">The request parameters to pass along to the client.</param>
|
||||||
|
/// <param name="configuration">Per-request configurable settings.</param>
|
||||||
|
/// <typeparam name="T">The return type.</typeparam>
|
||||||
|
/// <returns>The response data, decorated with <see cref="ApiResponse{T}"/></returns>
|
||||||
|
ApiResponse<T> Patch<T>(string path, RequestOptions options, IReadableConfiguration configuration = null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,295 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
namespace Example.API.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A dictionary in which one key has many associated values.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TKey">The type of the key</typeparam>
|
||||||
|
/// <typeparam name="TValue">The type of the value associated with the key.</typeparam>
|
||||||
|
public class Multimap<TKey, TValue> : IDictionary<TKey, IList<TValue>>
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly Dictionary<TKey, IList<TValue>> _dictionary;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Empty Constructor.
|
||||||
|
/// </summary>
|
||||||
|
public Multimap()
|
||||||
|
{
|
||||||
|
_dictionary = new Dictionary<TKey, IList<TValue>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor with comparer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
public Multimap(IEqualityComparer<TKey> comparer)
|
||||||
|
{
|
||||||
|
_dictionary = new Dictionary<TKey, IList<TValue>>(comparer);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Constructors
|
||||||
|
|
||||||
|
#region Enumerators
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To get the enumerator.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Enumerator</returns>
|
||||||
|
public IEnumerator<KeyValuePair<TKey, IList<TValue>>> GetEnumerator()
|
||||||
|
{
|
||||||
|
return _dictionary.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To get the enumerator.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Enumerator</returns>
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return _dictionary.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Enumerators
|
||||||
|
|
||||||
|
#region Public Members
|
||||||
|
/// <summary>
|
||||||
|
/// Add values to Multimap
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">Key value pair</param>
|
||||||
|
public void Add(KeyValuePair<TKey, IList<TValue>> item)
|
||||||
|
{
|
||||||
|
if (!TryAdd(item.Key, item.Value))
|
||||||
|
throw new InvalidOperationException("Could not add values to Multimap.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add Multimap to Multimap
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="multimap">Multimap</param>
|
||||||
|
public void Add(Multimap<TKey, TValue> multimap)
|
||||||
|
{
|
||||||
|
foreach (var item in multimap)
|
||||||
|
{
|
||||||
|
if (!TryAdd(item.Key, item.Value))
|
||||||
|
throw new InvalidOperationException("Could not add values to Multimap.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clear Multimap
|
||||||
|
/// </summary>
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
_dictionary.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether Multimap contains the specified item.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">Key value pair</param>
|
||||||
|
/// <exception cref="NotImplementedException">Method needs to be implemented</exception>
|
||||||
|
/// <returns>true if the Multimap contains the item; otherwise, false.</returns>
|
||||||
|
public bool Contains(KeyValuePair<TKey, IList<TValue>> item)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Copy items of the Multimap to an array,
|
||||||
|
/// starting at a particular array index.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="array">The array that is the destination of the items copied
|
||||||
|
/// from Multimap. The array must have zero-based indexing.</param>
|
||||||
|
/// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
|
||||||
|
/// <exception cref="NotImplementedException">Method needs to be implemented</exception>
|
||||||
|
public void CopyTo(KeyValuePair<TKey, IList<TValue>>[] array, int arrayIndex)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the specified item from the Multimap.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">Key value pair</param>
|
||||||
|
/// <returns>true if the item is successfully removed; otherwise, false.</returns>
|
||||||
|
/// <exception cref="NotImplementedException">Method needs to be implemented</exception>
|
||||||
|
public bool Remove(KeyValuePair<TKey, IList<TValue>> item)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the number of items contained in the Multimap.
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _dictionary.Count;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the Multimap is read-only.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsReadOnly => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds an item with the provided key and value to the Multimap.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The object to use as the key of the item to add.</param>
|
||||||
|
/// <param name="value">The object to use as the value of the item to add.</param>
|
||||||
|
/// <exception cref="InvalidOperationException">Thrown when couldn't add the value to Multimap.</exception>
|
||||||
|
public void Add(TKey key, IList<TValue> value)
|
||||||
|
{
|
||||||
|
if (value != null && value.Count > 0)
|
||||||
|
{
|
||||||
|
if (_dictionary.TryGetValue(key, out var list))
|
||||||
|
{
|
||||||
|
foreach (var k in value) list.Add(k);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list = new List<TValue>(value);
|
||||||
|
if (!TryAdd(key, list))
|
||||||
|
throw new InvalidOperationException("Could not add values to Multimap.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the Multimap contains an item with the specified key.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The key to locate in the Multimap.</param>
|
||||||
|
/// <returns>true if the Multimap contains an item with
|
||||||
|
/// the key; otherwise, false.</returns>
|
||||||
|
public bool ContainsKey(TKey key)
|
||||||
|
{
|
||||||
|
return _dictionary.ContainsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes item with the specified key from the Multimap.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The key to locate in the Multimap.</param>
|
||||||
|
/// <returns>true if the item is successfully removed; otherwise, false.</returns>
|
||||||
|
public bool Remove(TKey key)
|
||||||
|
{
|
||||||
|
return TryRemove(key, out var _);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the value associated with the specified key.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The key whose value to get.</param>
|
||||||
|
/// <param name="value">When this method returns, the value associated with the specified key, if the
|
||||||
|
/// key is found; otherwise, the default value for the type of the value parameter.
|
||||||
|
/// This parameter is passed uninitialized.</param>
|
||||||
|
/// <returns> true if the object that implements Multimap contains
|
||||||
|
/// an item with the specified key; otherwise, false.</returns>
|
||||||
|
public bool TryGetValue(TKey key, out IList<TValue> value)
|
||||||
|
{
|
||||||
|
return _dictionary.TryGetValue(key, out value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the item with the specified key.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The key of the item to get or set.</param>
|
||||||
|
/// <returns>The value of the specified key.</returns>
|
||||||
|
public IList<TValue> this[TKey key]
|
||||||
|
{
|
||||||
|
get => _dictionary[key];
|
||||||
|
set => _dictionary[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a System.Collections.Generic.ICollection containing the keys of the Multimap.
|
||||||
|
/// </summary>
|
||||||
|
public ICollection<TKey> Keys => _dictionary.Keys;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a System.Collections.Generic.ICollection containing the values of the Multimap.
|
||||||
|
/// </summary>
|
||||||
|
public ICollection<IList<TValue>> Values => _dictionary.Values;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Copy the items of the Multimap to an System.Array,
|
||||||
|
/// starting at a particular System.Array index.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="array">The one-dimensional System.Array that is the destination of the items copied
|
||||||
|
/// from Multimap. The System.Array must have zero-based indexing.</param>
|
||||||
|
/// <param name="index">The zero-based index in array at which copying begins.</param>
|
||||||
|
public void CopyTo(Array array, int index)
|
||||||
|
{
|
||||||
|
((ICollection)_dictionary).CopyTo(array, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds an item with the provided key and value to the Multimap.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The object to use as the key of the item to add.</param>
|
||||||
|
/// <param name="value">The object to use as the value of the item to add.</param>
|
||||||
|
/// <exception cref="InvalidOperationException">Thrown when couldn't add value to Multimap.</exception>
|
||||||
|
public void Add(TKey key, TValue value)
|
||||||
|
{
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
if (_dictionary.TryGetValue(key, out var list))
|
||||||
|
{
|
||||||
|
list.Add(value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list = new List<TValue> { value };
|
||||||
|
if (!TryAdd(key, list))
|
||||||
|
throw new InvalidOperationException("Could not add value to Multimap.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Members
|
||||||
|
|
||||||
|
#region Private Members
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to encapsulate generator differences between dictionary types.
|
||||||
|
*/
|
||||||
|
private bool TryRemove(TKey key, out IList<TValue> value)
|
||||||
|
{
|
||||||
|
_dictionary.TryGetValue(key, out value);
|
||||||
|
return _dictionary.Remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to encapsulate generator differences between dictionary types.
|
||||||
|
*/
|
||||||
|
private bool TryAdd(TKey key, IList<TValue> value)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_dictionary.Add(key, value);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endregion Private Members
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
|
namespace Example.API.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,84 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* 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.IO;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace Example.API.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A container for generalized request inputs. This type allows consumers to extend the request functionality
|
||||||
|
/// by abstracting away from the default (built-in) request framework (e.g. RestSharp).
|
||||||
|
/// </summary>
|
||||||
|
public class RequestOptions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Parameters to be bound to path parts of the Request's URL
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, string> PathParameters { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query parameters to be applied to the request.
|
||||||
|
/// Keys may have 1 or more values associated.
|
||||||
|
/// </summary>
|
||||||
|
public Multimap<string, string> QueryParameters { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Header parameters to be applied to the request.
|
||||||
|
/// Keys may have 1 or more values associated.
|
||||||
|
/// </summary>
|
||||||
|
public Multimap<string, string> HeaderParameters { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Form parameters to be sent along with the request.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, string> FormParameters { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// File parameters to be sent along with the request.
|
||||||
|
/// </summary>
|
||||||
|
public Multimap<string, Stream> FileParameters { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cookies to be sent along with the request.
|
||||||
|
/// </summary>
|
||||||
|
public List<Cookie> Cookies { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Operation associated with the request path.
|
||||||
|
/// </summary>
|
||||||
|
public string Operation { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Index associated with the operation.
|
||||||
|
/// </summary>
|
||||||
|
public int OperationIndex { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Any data associated with a request body.
|
||||||
|
/// </summary>
|
||||||
|
public Object Data { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs a new instance of <see cref="RequestOptions"/>
|
||||||
|
/// </summary>
|
||||||
|
public RequestOptions()
|
||||||
|
{
|
||||||
|
PathParameters = new Dictionary<string, string>();
|
||||||
|
QueryParameters = new Multimap<string, string>();
|
||||||
|
HeaderParameters = new Multimap<string, string>();
|
||||||
|
FormParameters = new Dictionary<string, string>();
|
||||||
|
FileParameters = new Multimap<string, Stream>();
|
||||||
|
Cookies = new List<Cookie>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using Polly;
|
||||||
|
using RestSharp;
|
||||||
|
|
||||||
|
namespace Example.API.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Configuration class to set the polly retry policies to be applied to the requests.
|
||||||
|
/// </summary>
|
||||||
|
public static class RetryConfiguration
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Retry policy
|
||||||
|
/// </summary>
|
||||||
|
public static Policy<RestResponse> RetryPolicy { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Async retry policy
|
||||||
|
/// </summary>
|
||||||
|
public static AsyncPolicy<RestResponse> AsyncRetryPolicy { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo><!-- setting GenerateAssemblyInfo to false causes this bug https://github.com/dotnet/project-system/issues/3934 -->
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<AssemblyName>Example.API</AssemblyName>
|
||||||
|
<PackageId>Example.API</PackageId>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<Authors>OpenAPI</Authors>
|
||||||
|
<Company>OpenAPI</Company>
|
||||||
|
<AssemblyTitle>OpenAPI Library</AssemblyTitle>
|
||||||
|
<Description>A library generated from a OpenAPI doc</Description>
|
||||||
|
<Copyright>No Copyright</Copyright>
|
||||||
|
<RootNamespace>Example.API</RootNamespace>
|
||||||
|
<Version>1.0.0</Version>
|
||||||
|
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\Example.API.xml</DocumentationFile>
|
||||||
|
<RepositoryUrl>https://github.com/GIT_USER_ID/GIT_REPO_ID.git</RepositoryUrl>
|
||||||
|
<RepositoryType>git</RepositoryType>
|
||||||
|
<PackageReleaseNotes>Minor update</PackageReleaseNotes>
|
||||||
|
<Nullable>annotations</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="JsonSubTypes" Version="2.0.1" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="RestSharp" Version="110.2.0" />
|
||||||
|
<PackageReference Include="Polly" Version="8.1.0" />
|
||||||
|
<PackageReference Include="Example.Common" Version="1.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="System.Web" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System.Web" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Example API
|
||||||
|
*
|
||||||
|
* Some demonstration stuff
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Example.API.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Abstract base class for oneOf, anyOf schemas in the OpenAPI specification
|
||||||
|
/// </summary>
|
||||||
|
public abstract partial class AbstractOpenAPISchema
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Custom JSON serializer
|
||||||
|
/// </summary>
|
||||||
|
static public readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
// OpenAPI generated types generally hide default constructors.
|
||||||
|
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
|
||||||
|
MissingMemberHandling = MissingMemberHandling.Error,
|
||||||
|
ContractResolver = new DefaultContractResolver
|
||||||
|
{
|
||||||
|
NamingStrategy = new CamelCaseNamingStrategy
|
||||||
|
{
|
||||||
|
OverrideSpecifiedNames = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Custom JSON serializer for objects with additional properties
|
||||||
|
/// </summary>
|
||||||
|
static public readonly JsonSerializerSettings AdditionalPropertiesSerializerSettings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
// OpenAPI generated types generally hide default constructors.
|
||||||
|
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
|
||||||
|
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||||
|
ContractResolver = new DefaultContractResolver
|
||||||
|
{
|
||||||
|
NamingStrategy = new CamelCaseNamingStrategy
|
||||||
|
{
|
||||||
|
OverrideSpecifiedNames = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets the actual instance
|
||||||
|
/// </summary>
|
||||||
|
public abstract Object ActualInstance { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets IsNullable to indicate whether the instance is nullable
|
||||||
|
/// </summary>
|
||||||
|
public bool IsNullable { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets the schema type, which can be either `oneOf` or `anyOf`
|
||||||
|
/// </summary>
|
||||||
|
public string SchemaType { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the instance into JSON string.
|
||||||
|
/// </summary>
|
||||||
|
public abstract string ToJson();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<packageRestore>
|
||||||
|
<add key="enabled" value="True" />
|
||||||
|
<add key="automatic" value="True" />
|
||||||
|
</packageRestore>
|
||||||
|
<packageSources>
|
||||||
|
<add key="LocalFeed" value="/api/generated/localFeed/" />
|
||||||
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||||
|
</packageSources>
|
||||||
|
</configuration>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
src/**/Controllers/DefaultApi.cs
|
||||||
|
|
||||||
|
# Remove unused classes
|
||||||
|
src/**/Authentication/ApiAuthentication.cs
|
||||||
|
src/**/Formatters/InputFormatterStream.cs
|
||||||
|
src/**/OpenApi/TypeExtensions.cs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
src/**/Attributes/ValidateModelStateAttribute.cs
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
Example.Common.sln
|
||||||
|
README.md
|
||||||
|
build.bat
|
||||||
|
build.sh
|
||||||
|
src/Example.Common/.gitignore
|
||||||
|
src/Example.Common/Converters/CustomEnumConverter.cs
|
||||||
|
src/Example.Common/Example.Common.csproj
|
||||||
|
src/Example.Common/Example.Common.nuspec
|
||||||
|
src/Example.Common/Models/ExampleSchemaDto.cs
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
7.3.0
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.27428.2043
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Common", "src\Example.Common\Example.Common.csproj", "{6FC4CFBD-1A07-4F15-A921-39E4D59FF83F}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{6FC4CFBD-1A07-4F15-A921-39E4D59FF83F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6FC4CFBD-1A07-4F15-A921-39E4D59FF83F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6FC4CFBD-1A07-4F15-A921-39E4D59FF83F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6FC4CFBD-1A07-4F15-A921-39E4D59FF83F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Example.Common - ASP.NET Core 6.0 Server
|
||||||
|
|
||||||
|
Defines all the schemas used in example API
|
||||||
|
|
||||||
|
## Upgrade NuGet Packages
|
||||||
|
|
||||||
|
NuGet packages get frequently updated.
|
||||||
|
|
||||||
|
To upgrade this solution to the latest version of all NuGet packages, use the dotnet-outdated tool.
|
||||||
|
|
||||||
|
|
||||||
|
Install dotnet-outdated tool:
|
||||||
|
|
||||||
|
```
|
||||||
|
dotnet tool install --global dotnet-outdated-tool
|
||||||
|
```
|
||||||
|
|
||||||
|
Upgrade only to new minor versions of packages
|
||||||
|
|
||||||
|
```
|
||||||
|
dotnet outdated --upgrade --version-lock Major
|
||||||
|
```
|
||||||
|
|
||||||
|
Upgrade to all new versions of packages (more likely to include breaking API changes)
|
||||||
|
|
||||||
|
```
|
||||||
|
dotnet outdated --upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
Linux/OS X:
|
||||||
|
|
||||||
|
```
|
||||||
|
sh build.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Windows:
|
||||||
|
|
||||||
|
```
|
||||||
|
build.bat
|
||||||
|
```
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
:: Generated by: https://openapi-generator.tech
|
||||||
|
::
|
||||||
|
|
||||||
|
@echo off
|
||||||
|
|
||||||
|
dotnet restore src\Example.Common
|
||||||
|
dotnet build src\Example.Common
|
||||||
|
echo Now, run the following to start the project: dotnet run -p src\Example.Common\Example.Common.csproj --launch-profile web.
|
||||||
|
echo.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Generated by: https://openapi-generator.tech
|
||||||
|
#
|
||||||
|
|
||||||
|
dotnet restore src/Example.Common/ && \
|
||||||
|
dotnet build src/Example.Common/ && \
|
||||||
|
echo "Now, run the following to start the project: dotnet run -p src/Example.Common/Example.Common.csproj --launch-profile web"
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
inputSpec: /api/generated/example/dotnet-models/example-schemas/openapi/openapi/openapi.yaml
|
||||||
|
generatorName: aspnetcore
|
||||||
|
templateDir: /api/templates/7.3.0/aspnetcore/
|
||||||
|
outputDir: /api/generated/example/dotnet-models/example-schemas
|
||||||
|
modelNameSuffix: Dto
|
||||||
|
|
||||||
|
typeMappings:
|
||||||
|
file: "IFormFile"
|
||||||
|
|
||||||
|
importMappings:
|
||||||
|
IFormFile: "Microsoft.AspNetCore.Http.IFormFile"
|
||||||
|
|
||||||
|
schemaMappings:
|
||||||
|
IFormFile: "Microsoft.AspNetCore.Http.IFormFile"
|
||||||
|
|
||||||
|
additionalProperties:
|
||||||
|
aspnetCoreVersion: "6.0"
|
||||||
|
packageName: "Example.Common"
|
||||||
|
packageVersion: "1.0.0"
|
||||||
|
generateBody: "false"
|
||||||
|
classModifier: "abstract"
|
||||||
|
operationModifier: "abstract"
|
||||||
|
isLibrary: "true"
|
||||||
|
buildTarget: "library"
|
||||||
|
enumNameSuffix: ""
|
||||||
|
enumValueSuffix: ""
|
||||||
|
operationResultTask: true
|
||||||
|
operationIsAsync: true
|
||||||
|
removeModelPackage: true
|
||||||
|
|
||||||
|
packageReferences: [
|
||||||
|
]
|
||||||
|
|
||||||
|
modelNamespaces: [
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# OpenAPI Generator Ignore
|
||||||
|
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||||
|
|
||||||
|
# Use this file to prevent files from being overwritten by the generator.
|
||||||
|
# The patterns follow closely to .gitignore or .dockerignore.
|
||||||
|
|
||||||
|
# As an example, the C# client generator defines ApiClient.cs.
|
||||||
|
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||||
|
#ApiClient.cs
|
||||||
|
|
||||||
|
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||||
|
#foo/*/qux
|
||||||
|
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||||
|
#foo/**/qux
|
||||||
|
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can also negate patterns with an exclamation (!).
|
||||||
|
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||||
|
#docs/*.md
|
||||||
|
# Then explicitly reverse the ignore rule for a single file:
|
||||||
|
#!docs/README.md
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
README.md
|
||||||
|
openapi/openapi.yaml
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
7.3.0
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# OpenAPI YAML
|
||||||
|
This is a OpenAPI YAML built by the [openapi-generator](https://github.com/openapitools/openapi-generator) project.
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
openapi: 3.0.3
|
||||||
|
info:
|
||||||
|
description: Defines all the schemas used in example API
|
||||||
|
title: Schemas for example
|
||||||
|
version: 1.0.0
|
||||||
|
servers:
|
||||||
|
- url: /
|
||||||
|
paths:
|
||||||
|
/fake_path_required_for_model_generation:
|
||||||
|
get:
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
ExampleSchema:
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
example: b1e0773f-ef0c-43cf-a1df-52d17f4a3017
|
||||||
|
format: uuid
|
||||||
|
type: string
|
||||||
|
name:
|
||||||
|
nullable: false
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
nullable: true
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
362
architecture/api/generated/example/dotnet-models/example-schemas/src/Example.Common/.gitignore
vendored
Normal file
362
architecture/api/generated/example/dotnet-models/example-schemas/src/Example.Common/.gitignore
vendored
Normal file
@@ -0,0 +1,362 @@
|
|||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Coverlet is a free, cross platform Code Coverage Tool
|
||||||
|
coverage*.json
|
||||||
|
coverage*.xml
|
||||||
|
coverage*.info
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
|
.ionide/
|
||||||
|
|
||||||
|
# Fody - auto-generated XML schema
|
||||||
|
FodyWeavers.xsd
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Schemas for example
|
||||||
|
*
|
||||||
|
* Defines all the schemas used in example API
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
* Generated by: https://openapi-generator.tech
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Globalization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Example.Common.Converters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Custom string to enum converter
|
||||||
|
/// </summary>
|
||||||
|
public class CustomEnumConverter<T> : TypeConverter
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Determine if we can convert a type to an enum
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <param name="sourceType"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||||
|
{
|
||||||
|
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert from a type value to an enum
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <param name="culture"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||||
|
{
|
||||||
|
var s = value as string;
|
||||||
|
if (string.IsNullOrEmpty(s))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonConvert.DeserializeObject<T>(@"""" + value + @"""");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Description>A library generated from a OpenAPI doc</Description>
|
||||||
|
<Copyright>No Copyright</Copyright>
|
||||||
|
<Authors>OpenAPI</Authors>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||||
|
<Version>1.0.0</Version>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AssemblyName>Example.Common</AssemblyName>
|
||||||
|
<PackageId>Example.Common</PackageId>
|
||||||
|
<UserSecretsId>c65ceed4-31e0-4bfd-9255-5a7e2215eb25</UserSecretsId>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
<DockerfileContext>..\..</DockerfileContext>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0"/>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
|
||||||
|
<PackageReference Include="JsonSubTypes" Version="1.8.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<!--<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />-->
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<package >
|
||||||
|
<metadata>
|
||||||
|
<id>$id$</id>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<title>OpenAPI Library</title>
|
||||||
|
<authors>OpenAPI</authors>
|
||||||
|
<owners>OpenAPI</owners>
|
||||||
|
<licenseUrl>http://localhost</licenseUrl>
|
||||||
|
<!--
|
||||||
|
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
|
||||||
|
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
|
||||||
|
-->
|
||||||
|
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||||
|
<description>A library generated from a OpenAPI doc</description>
|
||||||
|
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
|
||||||
|
<copyright>No Copyright</copyright>
|
||||||
|
<tags>Example.Common</tags>
|
||||||
|
</metadata>
|
||||||
|
</package>
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
/*
|
||||||
|
* Schemas for example
|
||||||
|
*
|
||||||
|
* Defines all the schemas used in example API
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
* Generated by: https://openapi-generator.tech
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Example.Common.Converters;
|
||||||
|
|
||||||
|
namespace Example.Common.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[DataContract]
|
||||||
|
public class ExampleSchemaDto : IEquatable<ExampleSchemaDto>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets Id
|
||||||
|
/// </summary>
|
||||||
|
/// <example>b1e0773f-ef0c-43cf-a1df-52d17f4a3017</example>
|
||||||
|
[DataMember(Name="id", EmitDefaultValue=false)]
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets Name
|
||||||
|
/// </summary>
|
||||||
|
[DataMember(Name="name", EmitDefaultValue=false)]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets Description
|
||||||
|
/// </summary>
|
||||||
|
[DataMember(Name="description", EmitDefaultValue=true)]
|
||||||
|
public string Description { 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 ExampleSchemaDto {\n");
|
||||||
|
sb.Append(" Id: ").Append(Id).Append("\n");
|
||||||
|
sb.Append(" Name: ").Append(Name).Append("\n");
|
||||||
|
sb.Append(" Description: ").Append(Description).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 string ToJson()
|
||||||
|
{
|
||||||
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if objects are equal
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Object to be compared</param>
|
||||||
|
/// <returns>Boolean</returns>
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj is null) return false;
|
||||||
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
return obj.GetType() == GetType() && Equals((ExampleSchemaDto)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if ExampleSchemaDto instances are equal
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other">Instance of ExampleSchemaDto to be compared</param>
|
||||||
|
/// <returns>Boolean</returns>
|
||||||
|
public bool Equals(ExampleSchemaDto other)
|
||||||
|
{
|
||||||
|
if (other is null) return false;
|
||||||
|
if (ReferenceEquals(this, other)) return true;
|
||||||
|
|
||||||
|
return
|
||||||
|
(
|
||||||
|
Id == other.Id ||
|
||||||
|
Id != null &&
|
||||||
|
Id.Equals(other.Id)
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
Name == other.Name ||
|
||||||
|
Name != null &&
|
||||||
|
Name.Equals(other.Name)
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
Description == other.Description ||
|
||||||
|
Description != null &&
|
||||||
|
Description.Equals(other.Description)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the hash code
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Hash code</returns>
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
unchecked // Overflow is fine, just wrap
|
||||||
|
{
|
||||||
|
var hashCode = 41;
|
||||||
|
// Suitable nullity checks etc, of course :)
|
||||||
|
if (Id != null)
|
||||||
|
hashCode = hashCode * 59 + Id.GetHashCode();
|
||||||
|
if (Name != null)
|
||||||
|
hashCode = hashCode * 59 + Name.GetHashCode();
|
||||||
|
if (Description != null)
|
||||||
|
hashCode = hashCode * 59 + Description.GetHashCode();
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Operators
|
||||||
|
#pragma warning disable 1591
|
||||||
|
|
||||||
|
public static bool operator ==(ExampleSchemaDto left, ExampleSchemaDto right)
|
||||||
|
{
|
||||||
|
return Equals(left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(ExampleSchemaDto left, ExampleSchemaDto right)
|
||||||
|
{
|
||||||
|
return !Equals(left, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning restore 1591
|
||||||
|
#endregion Operators
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<packageRestore>
|
||||||
|
<add key="enabled" value="True" />
|
||||||
|
<add key="automatic" value="True" />
|
||||||
|
</packageRestore>
|
||||||
|
<packageSources>
|
||||||
|
<add key="LocalFeed" value="/api/generated/localFeed/" />
|
||||||
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||||
|
</packageSources>
|
||||||
|
</configuration>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# OpenAPI Generator Ignore
|
||||||
|
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||||
|
|
||||||
|
# Use this file to prevent files from being overwritten by the generator.
|
||||||
|
# The patterns follow closely to .gitignore or .dockerignore.
|
||||||
|
|
||||||
|
# As an example, the C# client generator defines ApiClient.cs.
|
||||||
|
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||||
|
#ApiClient.cs
|
||||||
|
|
||||||
|
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||||
|
#foo/*/qux
|
||||||
|
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||||
|
#foo/**/qux
|
||||||
|
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can also negate patterns with an exclamation (!).
|
||||||
|
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||||
|
#docs/*.md
|
||||||
|
# Then explicitly reverse the ignore rule for a single file:
|
||||||
|
#!docs/README.md
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
.openapi-generator-ignore
|
||||||
|
README.md
|
||||||
|
pom.xml
|
||||||
|
src/main/java/api/ApiUtil.java
|
||||||
|
src/main/java/api/ExampleApi.java
|
||||||
|
src/main/java/model/ExampleSchema.java
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
7.3.0
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user