forked from loafle/openapi-generator-original
[csharp][generichost] Added 4.8 samples (#18791)
* added 4.8 samples * easer to understand diff * build samples again * build samples again
This commit is contained in:
parent
353320cb04
commit
368110a631
22
.github/workflows/openapi-generator.yaml
vendored
22
.github/workflows/openapi-generator.yaml
vendored
@ -154,13 +154,21 @@ jobs:
|
|||||||
|
|
||||||
rm -rf samples/client/petstore/csharp/generichost/standard2.0/Petstore
|
rm -rf samples/client/petstore/csharp/generichost/standard2.0/Petstore
|
||||||
|
|
||||||
rm -rf samples/client/petstore/csharp/generichost/net8/AllOf
|
rm -rf samples/client/petstore/csharp/generichost/net4.8/AllOf
|
||||||
rm -rf samples/client/petstore/csharp/generichost/net8/AnyOf
|
rm -rf samples/client/petstore/csharp/generichost/net4.8/AnyOf
|
||||||
rm -rf samples/client/petstore/csharp/generichost/net8/AnyOfNoCompare
|
rm -rf samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare
|
||||||
rm -rf samples/client/petstore/csharp/generichost/net8/FormModels
|
rm -rf samples/client/petstore/csharp/generichost/net4.8/FormModels
|
||||||
rm -rf samples/client/petstore/csharp/generichost/net8/OneOf
|
rm -rf samples/client/petstore/csharp/generichost/net4.8/OneOf
|
||||||
rm -rf samples/client/petstore/csharp/generichost/net8/Petstore
|
rm -rf samples/client/petstore/csharp/generichost/net4.8/Petstore
|
||||||
rm -rf samples/client/petstore/csharp/generichost/net8/UseDateTimeForDate
|
rm -rf samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate
|
||||||
|
|
||||||
|
rm -rf samples/client/petstore/csharp/generichost/net4.7/AllOf
|
||||||
|
rm -rf samples/client/petstore/csharp/generichost/net4.7/AnyOf
|
||||||
|
rm -rf samples/client/petstore/csharp/generichost/net4.7/AnyOfNoCompare
|
||||||
|
rm -rf samples/client/petstore/csharp/generichost/net4.7/FormModels
|
||||||
|
rm -rf samples/client/petstore/csharp/generichost/net4.7/OneOf
|
||||||
|
rm -rf samples/client/petstore/csharp/generichost/net4.7/Petstore
|
||||||
|
rm -rf samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate
|
||||||
- name: Generate samples
|
- name: Generate samples
|
||||||
run: |
|
run: |
|
||||||
bash bin/generate-samples.sh
|
bash bin/generate-samples.sh
|
||||||
|
8
.github/workflows/samples-dotnet-net47.yaml
vendored
8
.github/workflows/samples-dotnet-net47.yaml
vendored
@ -22,6 +22,14 @@ jobs:
|
|||||||
- samples/client/petstore/csharp/generichost/net4.7/OneOf
|
- samples/client/petstore/csharp/generichost/net4.7/OneOf
|
||||||
- samples/client/petstore/csharp/generichost/net4.7/Petstore
|
- samples/client/petstore/csharp/generichost/net4.7/Petstore
|
||||||
- samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate
|
- samples/client/petstore/csharp/generichost/net4.7/UseDateTimeForDate
|
||||||
|
|
||||||
|
- samples/client/petstore/csharp/generichost/net4.8/AllOf
|
||||||
|
- samples/client/petstore/csharp/generichost/net4.8/AnyOf
|
||||||
|
- samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare
|
||||||
|
- samples/client/petstore/csharp/generichost/net4.8/FormModels
|
||||||
|
- samples/client/petstore/csharp/generichost/net4.8/OneOf
|
||||||
|
- samples/client/petstore/csharp/generichost/net4.8/Petstore
|
||||||
|
- samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Build
|
- name: Build
|
||||||
|
22
appveyor.yml
22
appveyor.yml
@ -57,13 +57,21 @@ test_script:
|
|||||||
|
|
||||||
- dotnet test samples\client\petstore\csharp\generichost\standard2.0\Petstore\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
- dotnet test samples\client\petstore\csharp\generichost\standard2.0\Petstore\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
|
|
||||||
- dotnet test samples\client\petstore\csharp\generichost\net8\AllOf\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
- dotnet test samples\client\petstore\csharp\generichost\net4.8\AllOf\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
- dotnet test samples\client\petstore\csharp\generichost\net8\AnyOf\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
- dotnet test samples\client\petstore\csharp\generichost\net4.8\AnyOf\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
- dotnet test samples\client\petstore\csharp\generichost\net8\AnyOfNoCompare\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
- dotnet test samples\client\petstore\csharp\generichost\net4.8\AnyOfNoCompare\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
- dotnet test samples\client\petstore\csharp\generichost\net8\FormModels\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
- dotnet test samples\client\petstore\csharp\generichost\net4.8\FormModels\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
- dotnet test samples\client\petstore\csharp\generichost\net8\OneOf\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
- dotnet test samples\client\petstore\csharp\generichost\net4.8\OneOf\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
- dotnet test samples\client\petstore\csharp\generichost\net8\Petstore\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
- dotnet test samples\client\petstore\csharp\generichost\net4.8\Petstore\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
- dotnet test samples\client\petstore\csharp\generichost\net8\UseDateTimeForDate\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
- dotnet test samples\client\petstore\csharp\generichost\net4.8\UseDateTimeForDate\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
|
|
||||||
|
- dotnet test samples\client\petstore\csharp\generichost\net4.7\AllOf\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
|
- dotnet test samples\client\petstore\csharp\generichost\net4.7\AnyOf\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
|
- dotnet test samples\client\petstore\csharp\generichost\net4.7\AnyOfNoCompare\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
|
- dotnet test samples\client\petstore\csharp\generichost\net4.7\FormModels\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
|
- dotnet test samples\client\petstore\csharp\generichost\net4.7\OneOf\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
|
- dotnet test samples\client\petstore\csharp\generichost\net4.7\Petstore\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
|
- dotnet test samples\client\petstore\csharp\generichost\net4.7\UseDateTimeForDate\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
|
|
||||||
- dotnet test samples\client\petstore\csharp\httpclient\standard2.0\Petstore\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
- dotnet test samples\client\petstore\csharp\httpclient\standard2.0\Petstore\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||||
|
|
||||||
|
13
bin/configs/csharp-generichost-net4.8-allOf.yaml
Normal file
13
bin/configs/csharp-generichost-net4.8-allOf.yaml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# for csharp generichost
|
||||||
|
generatorName: csharp
|
||||||
|
outputDir: samples/client/petstore/csharp/generichost/net4.8/AllOf
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/allOf.yaml
|
||||||
|
library: generichost
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/csharp
|
||||||
|
additionalProperties:
|
||||||
|
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||||
|
useCompareNetObjects: true
|
||||||
|
disallowAdditionalPropertiesIfNotPresent: false
|
||||||
|
nullableReferenceTypes: false
|
||||||
|
equatable: true
|
||||||
|
targetFramework: net48
|
13
bin/configs/csharp-generichost-net4.8-anyOf.yaml
Normal file
13
bin/configs/csharp-generichost-net4.8-anyOf.yaml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# for csharp generichost
|
||||||
|
generatorName: csharp
|
||||||
|
outputDir: samples/client/petstore/csharp/generichost/net4.8/AnyOf
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/anyOf.yaml
|
||||||
|
library: generichost
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/csharp
|
||||||
|
additionalProperties:
|
||||||
|
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||||
|
useCompareNetObjects: true
|
||||||
|
disallowAdditionalPropertiesIfNotPresent: false
|
||||||
|
nullableReferenceTypes: false
|
||||||
|
equatable: true
|
||||||
|
targetFramework: net48
|
13
bin/configs/csharp-generichost-net4.8-anyOfNoCompare.yaml
Normal file
13
bin/configs/csharp-generichost-net4.8-anyOfNoCompare.yaml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# for csharp generichost
|
||||||
|
generatorName: csharp
|
||||||
|
outputDir: samples/client/petstore/csharp/generichost/net4.8/AnyOfNoCompare
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/anyOf.yaml
|
||||||
|
library: generichost
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/csharp
|
||||||
|
additionalProperties:
|
||||||
|
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||||
|
useCompareNetObjects: false
|
||||||
|
disallowAdditionalPropertiesIfNotPresent: false
|
||||||
|
nullableReferenceTypes: false
|
||||||
|
equatable: true
|
||||||
|
targetFramework: net48
|
16
bin/configs/csharp-generichost-net4.8-formModels.yaml
Normal file
16
bin/configs/csharp-generichost-net4.8-formModels.yaml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# for csharp generichost
|
||||||
|
generatorName: csharp
|
||||||
|
outputDir: samples/client/petstore/csharp/generichost/net4.8/FormModels
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||||
|
library: generichost
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/csharp
|
||||||
|
additionalProperties:
|
||||||
|
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||||
|
useCompareNetObjects: true
|
||||||
|
disallowAdditionalPropertiesIfNotPresent: false
|
||||||
|
nullableReferenceTypes: false
|
||||||
|
equatable: true
|
||||||
|
targetFramework: net48
|
||||||
|
skipFormModel: false
|
||||||
|
inlineSchemaOptions:
|
||||||
|
RESOLVE_INLINE_ENUMS: true
|
13
bin/configs/csharp-generichost-net4.8-oneOf.yaml
Normal file
13
bin/configs/csharp-generichost-net4.8-oneOf.yaml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# for csharp generichost
|
||||||
|
generatorName: csharp
|
||||||
|
outputDir: samples/client/petstore/csharp/generichost/net4.8/OneOf
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf.yaml
|
||||||
|
library: generichost
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/csharp
|
||||||
|
additionalProperties:
|
||||||
|
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||||
|
useCompareNetObjects: true
|
||||||
|
disallowAdditionalPropertiesIfNotPresent: false
|
||||||
|
nullableReferenceTypes: false
|
||||||
|
equatable: true
|
||||||
|
targetFramework: net48
|
@ -0,0 +1,10 @@
|
|||||||
|
# for csharp generichost
|
||||||
|
generatorName: csharp
|
||||||
|
outputDir: samples/client/petstore/csharp/generichost/net4.8/UseDateTimeForDate
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/dates-api.yaml
|
||||||
|
library: generichost
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/csharp
|
||||||
|
additionalProperties:
|
||||||
|
packageGuid: '{2E60EF87-DB0B-4D01-A36E-F5E90F7EC757}'
|
||||||
|
useDateTimeForDate: true
|
||||||
|
targetFramework: net48
|
13
bin/configs/csharp-generichost-net4.8.yaml
Normal file
13
bin/configs/csharp-generichost-net4.8.yaml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# for csharp generichost
|
||||||
|
generatorName: csharp
|
||||||
|
outputDir: samples/client/petstore/csharp/generichost/net4.8/Petstore
|
||||||
|
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||||
|
library: generichost
|
||||||
|
templateDir: modules/openapi-generator/src/main/resources/csharp
|
||||||
|
additionalProperties:
|
||||||
|
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
|
||||||
|
useCompareNetObjects: true
|
||||||
|
disallowAdditionalPropertiesIfNotPresent: false
|
||||||
|
nullableReferenceTypes: false
|
||||||
|
equatable: true
|
||||||
|
targetFramework: net48
|
362
samples/client/petstore/csharp/generichost/net4.8/AllOf/.gitignore
vendored
Normal file
362
samples/client/petstore/csharp/generichost/net4.8/AllOf/.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,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,40 @@
|
|||||||
|
.gitignore
|
||||||
|
Org.OpenAPITools.sln
|
||||||
|
README.md
|
||||||
|
api/openapi.yaml
|
||||||
|
appveyor.yml
|
||||||
|
docs/apis/DefaultApi.md
|
||||||
|
docs/models/Adult.md
|
||||||
|
docs/models/Child.md
|
||||||
|
docs/models/Person.md
|
||||||
|
docs/scripts/git_push.ps1
|
||||||
|
docs/scripts/git_push.sh
|
||||||
|
src/Org.OpenAPITools.Test/Api/DependencyInjectionTests.cs
|
||||||
|
src/Org.OpenAPITools.Test/Org.OpenAPITools.Test.csproj
|
||||||
|
src/Org.OpenAPITools.Test/README.md
|
||||||
|
src/Org.OpenAPITools/Api/DefaultApi.cs
|
||||||
|
src/Org.OpenAPITools/Api/IApi.cs
|
||||||
|
src/Org.OpenAPITools/Client/ApiException.cs
|
||||||
|
src/Org.OpenAPITools/Client/ApiFactory.cs
|
||||||
|
src/Org.OpenAPITools/Client/ApiResponseEventArgs.cs
|
||||||
|
src/Org.OpenAPITools/Client/ApiResponse`1.cs
|
||||||
|
src/Org.OpenAPITools/Client/ClientUtils.cs
|
||||||
|
src/Org.OpenAPITools/Client/CookieContainer.cs
|
||||||
|
src/Org.OpenAPITools/Client/DateTimeJsonConverter.cs
|
||||||
|
src/Org.OpenAPITools/Client/DateTimeNullableJsonConverter.cs
|
||||||
|
src/Org.OpenAPITools/Client/ExceptionEventArgs.cs
|
||||||
|
src/Org.OpenAPITools/Client/HostConfiguration.cs
|
||||||
|
src/Org.OpenAPITools/Client/JsonSerializerOptionsProvider.cs
|
||||||
|
src/Org.OpenAPITools/Client/Option.cs
|
||||||
|
src/Org.OpenAPITools/Client/RateLimitProvider`1.cs
|
||||||
|
src/Org.OpenAPITools/Client/TokenBase.cs
|
||||||
|
src/Org.OpenAPITools/Client/TokenContainer`1.cs
|
||||||
|
src/Org.OpenAPITools/Client/TokenProvider`1.cs
|
||||||
|
src/Org.OpenAPITools/Extensions/IHostBuilderExtensions.cs
|
||||||
|
src/Org.OpenAPITools/Extensions/IHttpClientBuilderExtensions.cs
|
||||||
|
src/Org.OpenAPITools/Extensions/IServiceCollectionExtensions.cs
|
||||||
|
src/Org.OpenAPITools/Model/Adult.cs
|
||||||
|
src/Org.OpenAPITools/Model/Child.cs
|
||||||
|
src/Org.OpenAPITools/Model/Person.cs
|
||||||
|
src/Org.OpenAPITools/Org.OpenAPITools.csproj
|
||||||
|
src/Org.OpenAPITools/README.md
|
@ -0,0 +1 @@
|
|||||||
|
7.7.0-SNAPSHOT
|
@ -0,0 +1,27 @@
|
|||||||
|
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}") = "Org.OpenAPITools", "src\Org.OpenAPITools\Org.OpenAPITools.csproj", "{321C8C3F-0156-40C1-AE42-D59761FB9B6C}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Org.OpenAPITools.Test", "src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.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 @@
|
|||||||
|
# Created with Openapi Generator
|
@ -0,0 +1,71 @@
|
|||||||
|
openapi: 3.0.1
|
||||||
|
info:
|
||||||
|
license:
|
||||||
|
name: MIT
|
||||||
|
title: Example
|
||||||
|
version: 1.0.0
|
||||||
|
servers:
|
||||||
|
- url: http://api.example.xyz/v1
|
||||||
|
paths:
|
||||||
|
/person/display/{personId}:
|
||||||
|
get:
|
||||||
|
operationId: list
|
||||||
|
parameters:
|
||||||
|
- description: The id of the person to retrieve
|
||||||
|
explode: false
|
||||||
|
in: path
|
||||||
|
name: personId
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
style: simple
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Person'
|
||||||
|
description: OK
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
Person:
|
||||||
|
discriminator:
|
||||||
|
mapping:
|
||||||
|
a: '#/components/schemas/Adult'
|
||||||
|
c: Child
|
||||||
|
propertyName: $_type
|
||||||
|
example:
|
||||||
|
lastName: lastName
|
||||||
|
firstName: firstName
|
||||||
|
$_type: $_type
|
||||||
|
properties:
|
||||||
|
$_type:
|
||||||
|
type: string
|
||||||
|
lastName:
|
||||||
|
type: string
|
||||||
|
firstName:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
Adult:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/components/schemas/Person'
|
||||||
|
- properties:
|
||||||
|
children:
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Child'
|
||||||
|
type: array
|
||||||
|
type: object
|
||||||
|
description: A representation of an adult
|
||||||
|
Child:
|
||||||
|
allOf:
|
||||||
|
- properties:
|
||||||
|
age:
|
||||||
|
format: int32
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
|
- $ref: '#/components/schemas/Person'
|
||||||
|
description: A representation of a child
|
||||||
|
properties:
|
||||||
|
boosterSeat:
|
||||||
|
type: boolean
|
||||||
|
|
@ -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\Org.OpenAPITools\Org.OpenAPITools.csproj -o ../../output -c Release --no-build
|
@ -0,0 +1,95 @@
|
|||||||
|
# Org.OpenAPITools.Api.DefaultApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://api.example.xyz/v1*
|
||||||
|
|
||||||
|
| Method | HTTP request | Description |
|
||||||
|
|--------|--------------|-------------|
|
||||||
|
| [**List**](DefaultApi.md#list) | **GET** /person/display/{personId} | |
|
||||||
|
|
||||||
|
<a id="list"></a>
|
||||||
|
# **List**
|
||||||
|
> Person List (string personId)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Example
|
||||||
|
```csharp
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Org.OpenAPITools.Api;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
|
||||||
|
namespace Example
|
||||||
|
{
|
||||||
|
public class ListExample
|
||||||
|
{
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
Configuration config = new Configuration();
|
||||||
|
config.BasePath = "http://api.example.xyz/v1";
|
||||||
|
var apiInstance = new DefaultApi(config);
|
||||||
|
var personId = "personId_example"; // string | The id of the person to retrieve
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Person result = apiInstance.List(personId);
|
||||||
|
Debug.WriteLine(result);
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
Debug.Print("Exception when calling DefaultApi.List: " + e.Message);
|
||||||
|
Debug.Print("Status Code: " + e.ErrorCode);
|
||||||
|
Debug.Print(e.StackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Using the ListWithHttpInfo variant
|
||||||
|
This returns an ApiResponse object which contains the response data, status code and headers.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ApiResponse<Person> response = apiInstance.ListWithHttpInfo(personId);
|
||||||
|
Debug.Write("Status Code: " + response.StatusCode);
|
||||||
|
Debug.Write("Response Headers: " + response.Headers);
|
||||||
|
Debug.Write("Response Body: " + response.Data);
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
Debug.Print("Exception when calling DefaultApi.ListWithHttpInfo: " + e.Message);
|
||||||
|
Debug.Print("Status Code: " + e.ErrorCode);
|
||||||
|
Debug.Print(e.StackTrace);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
| Name | Type | Description | Notes |
|
||||||
|
|------|------|-------------|-------|
|
||||||
|
| **personId** | **string** | The id of the person to retrieve | |
|
||||||
|
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
[**Person**](Person.md)
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: application/json
|
||||||
|
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
| **200** | OK | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md)
|
||||||
|
|
@ -0,0 +1,14 @@
|
|||||||
|
# Org.OpenAPITools.Model.Adult
|
||||||
|
A representation of an adult
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**FirstName** | **string** | | [optional]
|
||||||
|
**LastName** | **string** | | [optional]
|
||||||
|
**Type** | **string** | | [optional]
|
||||||
|
**Children** | [**List<Child>**](Child.md) | | [optional]
|
||||||
|
|
||||||
|
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
|
||||||
|
|
@ -0,0 +1,15 @@
|
|||||||
|
# Org.OpenAPITools.Model.Child
|
||||||
|
A representation of a child
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**FirstName** | **string** | | [optional]
|
||||||
|
**LastName** | **string** | | [optional]
|
||||||
|
**Type** | **string** | | [optional]
|
||||||
|
**Age** | **int** | | [optional]
|
||||||
|
**BoosterSeat** | **bool** | | [optional]
|
||||||
|
|
||||||
|
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
# Org.OpenAPITools.Model.Person
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**FirstName** | **string** | | [optional]
|
||||||
|
**LastName** | **string** | | [optional]
|
||||||
|
**Type** | **string** | | [optional]
|
||||||
|
|
||||||
|
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
|
||||||
|
|
@ -0,0 +1,75 @@
|
|||||||
|
param(
|
||||||
|
[Parameter()][Alias("g")][String]$GitHost = "github.com",
|
||||||
|
[Parameter()][Alias("u")][String]$GitUserId = "GIT_USER_ID",
|
||||||
|
[Parameter()][Alias("r")][String]$GitRepoId = "GIT_REPO_ID",
|
||||||
|
[Parameter()][Alias("m")][string]$Message = "Minor update",
|
||||||
|
[Parameter()][Alias("h")][switch]$Help
|
||||||
|
)
|
||||||
|
|
||||||
|
function Publish-ToGitHost{
|
||||||
|
if ([string]::IsNullOrWhiteSpace($Message) -or $Message -eq "Minor update"){
|
||||||
|
# it seems unlikely that we would want our git commit message to be the default, so lets prompt the user
|
||||||
|
$Message = Read-Host -Prompt "Please provide a commit message or press enter"
|
||||||
|
$Message = if([string]::IsNullOrWhiteSpace($Message)) { "no message provided" } else { $Message }
|
||||||
|
}
|
||||||
|
|
||||||
|
git init
|
||||||
|
git add .
|
||||||
|
git commit -am "${Message}"
|
||||||
|
$branchName=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
$gitRemote=$(git remote)
|
||||||
|
|
||||||
|
if([string]::IsNullOrWhiteSpace($gitRemote)){
|
||||||
|
git remote add origin https://${GitHost}/${GitUserId}/${GitRepoId}.git
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "Pulling from https://${GitHost}/${GitUserId}/${GitRepoId}.git"
|
||||||
|
git pull origin $branchName --ff-only
|
||||||
|
|
||||||
|
if ($LastExitCode -ne 0){
|
||||||
|
if (${GitHost} -eq "github.com"){
|
||||||
|
Write-Output "The ${GitRepoId} repository may not exist yet. Creating it now with the GitHub CLI."
|
||||||
|
gh auth login --hostname github.com --web
|
||||||
|
gh repo create $GitRepoId --private
|
||||||
|
# sleep 2 seconds to ensure git finishes creation of the repo
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw "There was an issue pulling the origin branch. The remote repository may not exist yet."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "Pushing to https://${GitHost}/${GitUserId}/${GitRepoId}.git"
|
||||||
|
git push origin $branchName
|
||||||
|
}
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
Set-StrictMode -Version 3.0
|
||||||
|
|
||||||
|
if ($Help){
|
||||||
|
Write-Output "
|
||||||
|
This script will initialize a git repository, then add and commit all files.
|
||||||
|
The local repository will then be pushed to your preferred git provider.
|
||||||
|
If the remote repository does not exist yet and you are using GitHub,
|
||||||
|
the repository will be created for you provided you have the GitHub CLI installed.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
-g | -GitHost -> ex: github.com
|
||||||
|
-m | -Message -> the git commit message
|
||||||
|
-r | -GitRepoId -> the name of the repository
|
||||||
|
-u | -GitUserId -> your user id
|
||||||
|
"
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$rootPath=Resolve-Path -Path $PSScriptRoot/../..
|
||||||
|
|
||||||
|
Push-Location $rootPath
|
||||||
|
|
||||||
|
try {
|
||||||
|
Publish-ToGitHost $GitHost $GitUserId $GitRepoId $Message
|
||||||
|
}
|
||||||
|
finally{
|
||||||
|
Pop-Location
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
#!/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_USER_ID}
|
||||||
|
git_repo_id=${2:-GIT_REPO_ID}
|
||||||
|
release_note=${3:-Minor update}
|
||||||
|
git_host=${4:-github.com}
|
||||||
|
|
||||||
|
starting_directory=$(pwd)
|
||||||
|
script_root="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||||
|
cd $script_root
|
||||||
|
cd ../..
|
||||||
|
|
||||||
|
if [ "$release_note" = "" ] || [ "$release_note" = "Minor update" ]; then
|
||||||
|
# it seems unlikely that we would want our git commit message to be the default, so lets prompt the user
|
||||||
|
echo "Please provide a commit message or press enter"
|
||||||
|
read user_input
|
||||||
|
release_note=$user_input
|
||||||
|
if [ "$release_note" = "" ]; then
|
||||||
|
release_note="no message provided"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
git init
|
||||||
|
git add .
|
||||||
|
git commit -am "$release_note"
|
||||||
|
branch_name=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
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
|
||||||
|
|
||||||
|
echo "[INFO] Pulling from https://${git_host}/${git_user_id}/${git_repo_id}.git"
|
||||||
|
git pull origin $branch_name --ff-only
|
||||||
|
|
||||||
|
echo "[INFO] Pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
|
||||||
|
git push origin $branch_name
|
||||||
|
|
||||||
|
cd $starting_directory
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* 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.Security.Cryptography;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using Org.OpenAPITools.Extensions;
|
||||||
|
|
||||||
|
|
||||||
|
/* *********************************************************************************
|
||||||
|
* Follow these manual steps to construct tests.
|
||||||
|
* This file will not be overwritten.
|
||||||
|
* *********************************************************************************
|
||||||
|
* 1. Navigate to ApiTests.Base.cs and ensure any tokens are being created correctly.
|
||||||
|
* Take care not to commit credentials to any repository.
|
||||||
|
*
|
||||||
|
* 2. Mocking is coordinated by ApiTestsBase#AddApiHttpClients.
|
||||||
|
* To mock the client, use the generic AddApiHttpClients.
|
||||||
|
* To mock the server, change the client's BaseAddress.
|
||||||
|
*
|
||||||
|
* 3. Locate the test you want below
|
||||||
|
* - remove the skip property from the Fact attribute
|
||||||
|
* - set the value of any variables if necessary
|
||||||
|
*
|
||||||
|
* 4. Run the tests and ensure they work.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for API tests
|
||||||
|
/// </summary>
|
||||||
|
public class ApiTestsBase
|
||||||
|
{
|
||||||
|
protected readonly IHost _host;
|
||||||
|
|
||||||
|
public ApiTestsBase(string[] args)
|
||||||
|
{
|
||||||
|
_host = CreateHostBuilder(args).Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
|
||||||
|
.ConfigureApi((context, services, options) =>
|
||||||
|
{
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* 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.Threading.Tasks;
|
||||||
|
using Xunit;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Org.OpenAPITools.Api;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
|
||||||
|
|
||||||
|
/* *********************************************************************************
|
||||||
|
* Follow these manual steps to construct tests.
|
||||||
|
* This file will not be overwritten.
|
||||||
|
* *********************************************************************************
|
||||||
|
* 1. Navigate to ApiTests.Base.cs and ensure any tokens are being created correctly.
|
||||||
|
* Take care not to commit credentials to any repository.
|
||||||
|
*
|
||||||
|
* 2. Mocking is coordinated by ApiTestsBase#AddApiHttpClients.
|
||||||
|
* To mock the client, use the generic AddApiHttpClients.
|
||||||
|
* To mock the server, change the client's BaseAddress.
|
||||||
|
*
|
||||||
|
* 3. Locate the test you want below
|
||||||
|
* - remove the skip property from the Fact attribute
|
||||||
|
* - set the value of any variables if necessary
|
||||||
|
*
|
||||||
|
* 4. Run the tests and ensure they work.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class for testing DefaultApi
|
||||||
|
/// </summary>
|
||||||
|
public sealed class DefaultApiTests : ApiTestsBase
|
||||||
|
{
|
||||||
|
private readonly IDefaultApi _instance;
|
||||||
|
|
||||||
|
public DefaultApiTests(): base(Array.Empty<string>())
|
||||||
|
{
|
||||||
|
_instance = _host.Services.GetRequiredService<IDefaultApi>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test List
|
||||||
|
/// </summary>
|
||||||
|
[Fact (Skip = "not implemented")]
|
||||||
|
public async Task ListAsyncTest()
|
||||||
|
{
|
||||||
|
string personId = default;
|
||||||
|
var response = await _instance.ListAsync(personId);
|
||||||
|
var model = response.Ok();
|
||||||
|
Assert.IsType<Person>(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using Org.OpenAPITools.Api;
|
||||||
|
using Org.OpenAPITools.Extensions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the dependency injection.
|
||||||
|
/// </summary>
|
||||||
|
public class DependencyInjectionTest
|
||||||
|
{
|
||||||
|
private readonly IHost _hostUsingConfigureWithoutAClient =
|
||||||
|
Host.CreateDefaultBuilder(Array.Empty<string>()).ConfigureApi((context, services, options) =>
|
||||||
|
{
|
||||||
|
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
private readonly IHost _hostUsingConfigureWithAClient =
|
||||||
|
Host.CreateDefaultBuilder(Array.Empty<string>()).ConfigureApi((context, services, options) =>
|
||||||
|
{
|
||||||
|
|
||||||
|
options.AddApiHttpClients(client => client.BaseAddress = new Uri(ClientUtils.BASE_ADDRESS));
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
private readonly IHost _hostUsingAddWithoutAClient =
|
||||||
|
Host.CreateDefaultBuilder(Array.Empty<string>()).ConfigureServices((host, services) =>
|
||||||
|
{
|
||||||
|
services.AddApi(options =>
|
||||||
|
{
|
||||||
|
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
private readonly IHost _hostUsingAddWithAClient =
|
||||||
|
Host.CreateDefaultBuilder(Array.Empty<string>()).ConfigureServices((host, services) =>
|
||||||
|
{
|
||||||
|
services.AddApi(options =>
|
||||||
|
{
|
||||||
|
|
||||||
|
options.AddApiHttpClients(client => client.BaseAddress = new Uri(ClientUtils.BASE_ADDRESS));
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test dependency injection when using the configure method
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void ConfigureApiWithAClientTest()
|
||||||
|
{
|
||||||
|
var defaultApi = _hostUsingConfigureWithAClient.Services.GetRequiredService<IDefaultApi>();
|
||||||
|
Assert.True(defaultApi.HttpClient.BaseAddress != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test dependency injection when using the configure method
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void ConfigureApiWithoutAClientTest()
|
||||||
|
{
|
||||||
|
var defaultApi = _hostUsingConfigureWithoutAClient.Services.GetRequiredService<IDefaultApi>();
|
||||||
|
Assert.True(defaultApi.HttpClient.BaseAddress != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test dependency injection when using the add method
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void AddApiWithAClientTest()
|
||||||
|
{
|
||||||
|
var defaultApi = _hostUsingAddWithAClient.Services.GetRequiredService<IDefaultApi>();
|
||||||
|
Assert.True(defaultApi.HttpClient.BaseAddress != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test dependency injection when using the add method
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void AddApiWithoutAClientTest()
|
||||||
|
{
|
||||||
|
var defaultApi = _hostUsingAddWithoutAClient.Services.GetRequiredService<IDefaultApi>();
|
||||||
|
Assert.True(defaultApi.HttpClient.BaseAddress != null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Model
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class for testing Adult
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
/// Please update the test case below to test the model.
|
||||||
|
/// </remarks>
|
||||||
|
public class AdultTests : IDisposable
|
||||||
|
{
|
||||||
|
// TODO uncomment below to declare an instance variable for Adult
|
||||||
|
//private Adult instance;
|
||||||
|
|
||||||
|
public AdultTests()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to create an instance of Adult
|
||||||
|
//instance = new Adult();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
// Cleanup when everything is done.
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test an instance of Adult
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void AdultInstanceTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test "IsType" Adult
|
||||||
|
//Assert.IsType<Adult>(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the property 'Children'
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void ChildrenTest()
|
||||||
|
{
|
||||||
|
// TODO unit test for the property 'Children'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Model
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class for testing Child
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
/// Please update the test case below to test the model.
|
||||||
|
/// </remarks>
|
||||||
|
public class ChildTests : IDisposable
|
||||||
|
{
|
||||||
|
// TODO uncomment below to declare an instance variable for Child
|
||||||
|
//private Child instance;
|
||||||
|
|
||||||
|
public ChildTests()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to create an instance of Child
|
||||||
|
//instance = new Child();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
// Cleanup when everything is done.
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test an instance of Child
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void ChildInstanceTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test "IsType" Child
|
||||||
|
//Assert.IsType<Child>(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the property 'Age'
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void AgeTest()
|
||||||
|
{
|
||||||
|
// TODO unit test for the property 'Age'
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the property 'BoosterSeat'
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void BoosterSeatTest()
|
||||||
|
{
|
||||||
|
// TODO unit test for the property 'BoosterSeat'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Model
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class for testing Person
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
/// Please update the test case below to test the model.
|
||||||
|
/// </remarks>
|
||||||
|
public class PersonTests : IDisposable
|
||||||
|
{
|
||||||
|
// TODO uncomment below to declare an instance variable for Person
|
||||||
|
//private Person instance;
|
||||||
|
|
||||||
|
public PersonTests()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to create an instance of Person
|
||||||
|
//instance = new Person();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
// Cleanup when everything is done.
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test an instance of Person
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void PersonInstanceTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test "IsType" Person
|
||||||
|
//Assert.IsType<Person>(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test deserialize a Adult from type Person
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void AdultDeserializeFromPersonTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test deserialize a Adult from type Person
|
||||||
|
//Assert.IsType<Person>(JsonConvert.DeserializeObject<Person>(new Adult().ToJson()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test deserialize a Child from type Person
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void ChildDeserializeFromPersonTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test deserialize a Child from type Person
|
||||||
|
//Assert.IsType<Person>(JsonConvert.DeserializeObject<Person>(new Child().ToJson()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the property 'FirstName'
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void FirstNameTest()
|
||||||
|
{
|
||||||
|
// TODO unit test for the property 'FirstName'
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the property 'LastName'
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void LastNameTest()
|
||||||
|
{
|
||||||
|
// TODO unit test for the property 'LastName'
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the property 'Type'
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void TypeTest()
|
||||||
|
{
|
||||||
|
// TODO unit test for the property 'Type'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<AssemblyName>Org.OpenAPITools.Test</AssemblyName>
|
||||||
|
<RootNamespace>Org.OpenAPITools.Test</RootNamespace>
|
||||||
|
<TargetFramework>net48</TargetFramework>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.7.0" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Org.OpenAPITools\Org.OpenAPITools.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
@ -0,0 +1,355 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* 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.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
|
/// This class is registered as transient.
|
||||||
|
/// </summary>
|
||||||
|
public interface IDefaultApi : IApi
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The class containing the events
|
||||||
|
/// </summary>
|
||||||
|
DefaultApiEvents Events { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="personId">The id of the person to retrieve</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns><see cref="Task"/><<see cref="IListApiResponse"/>></returns>
|
||||||
|
Task<IListApiResponse> ListAsync(string personId, System.Threading.CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="personId">The id of the person to retrieve</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns><see cref="Task"/><<see cref="IListApiResponse"/>></returns>
|
||||||
|
Task<IListApiResponse> ListOrDefaultAsync(string personId, System.Threading.CancellationToken cancellationToken = default);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="IListApiResponse"/>
|
||||||
|
/// </summary>
|
||||||
|
public interface IListApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk<Org.OpenAPITools.Model.Person>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the response is 200 Ok
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool IsOk { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
|
/// </summary>
|
||||||
|
public class DefaultApiEvents
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The event raised after the server response
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<ApiResponseEventArgs> OnList;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The event raised after an error querying the server
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<ExceptionEventArgs> OnErrorList;
|
||||||
|
|
||||||
|
internal void ExecuteOnList(DefaultApi.ListApiResponse apiResponse)
|
||||||
|
{
|
||||||
|
OnList?.Invoke(this, new ApiResponseEventArgs(apiResponse));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void ExecuteOnErrorList(Exception exception)
|
||||||
|
{
|
||||||
|
OnErrorList?.Invoke(this, new ExceptionEventArgs(exception));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class DefaultApi : IDefaultApi
|
||||||
|
{
|
||||||
|
private JsonSerializerOptions _jsonSerializerOptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The logger factory
|
||||||
|
/// </summary>
|
||||||
|
public ILoggerFactory LoggerFactory { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The logger
|
||||||
|
/// </summary>
|
||||||
|
public ILogger<DefaultApi> Logger { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The HttpClient
|
||||||
|
/// </summary>
|
||||||
|
public HttpClient HttpClient { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The class containing the events
|
||||||
|
/// </summary>
|
||||||
|
public DefaultApiEvents Events { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="DefaultApi"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public DefaultApi(ILogger<DefaultApi> logger, ILoggerFactory loggerFactory, HttpClient httpClient, JsonSerializerOptionsProvider jsonSerializerOptionsProvider, DefaultApiEvents defaultApiEvents)
|
||||||
|
{
|
||||||
|
_jsonSerializerOptions = jsonSerializerOptionsProvider.Options;
|
||||||
|
LoggerFactory = loggerFactory;
|
||||||
|
Logger = LoggerFactory.CreateLogger<DefaultApi>();
|
||||||
|
HttpClient = httpClient;
|
||||||
|
Events = defaultApiEvents;
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void FormatList(ref string personId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validates the request parameters
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="personId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private void ValidateList(string personId)
|
||||||
|
{
|
||||||
|
if (personId == null)
|
||||||
|
throw new ArgumentNullException(nameof(personId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Processes the server response
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiResponseLocalVar"></param>
|
||||||
|
/// <param name="personId"></param>
|
||||||
|
private void AfterListDefaultImplementation(IListApiResponse apiResponseLocalVar, string personId)
|
||||||
|
{
|
||||||
|
bool suppressDefaultLog = false;
|
||||||
|
AfterList(ref suppressDefaultLog, apiResponseLocalVar, personId);
|
||||||
|
if (!suppressDefaultLog)
|
||||||
|
Logger.LogInformation("{0,-9} | {1} | {3}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Processes the server response
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="suppressDefaultLog"></param>
|
||||||
|
/// <param name="apiResponseLocalVar"></param>
|
||||||
|
/// <param name="personId"></param>
|
||||||
|
partial void AfterList(ref bool suppressDefaultLog, IListApiResponse apiResponseLocalVar, string personId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logs exceptions that occur while retrieving the server response
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exception"></param>
|
||||||
|
/// <param name="pathFormat"></param>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <param name="personId"></param>
|
||||||
|
private void OnErrorListDefaultImplementation(Exception exception, string pathFormat, string path, string personId)
|
||||||
|
{
|
||||||
|
bool suppressDefaultLog = false;
|
||||||
|
OnErrorList(ref suppressDefaultLog, exception, pathFormat, path, personId);
|
||||||
|
if (!suppressDefaultLog)
|
||||||
|
Logger.LogError(exception, "An error occurred while sending the request to the server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A partial method that gives developers a way to provide customized exception handling
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="suppressDefaultLog"></param>
|
||||||
|
/// <param name="exception"></param>
|
||||||
|
/// <param name="pathFormat"></param>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <param name="personId"></param>
|
||||||
|
partial void OnErrorList(ref bool suppressDefaultLog, Exception exception, string pathFormat, string path, string personId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="personId">The id of the person to retrieve</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns><see cref="Task"/><<see cref="IListApiResponse"/>></returns>
|
||||||
|
public async Task<IListApiResponse> ListOrDefaultAsync(string personId, System.Threading.CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await ListAsync(personId, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="personId">The id of the person to retrieve</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns><see cref="Task"/><<see cref="IListApiResponse"/>></returns>
|
||||||
|
public async Task<IListApiResponse> ListAsync(string personId, System.Threading.CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
UriBuilder uriBuilderLocalVar = new UriBuilder();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ValidateList(personId);
|
||||||
|
|
||||||
|
FormatList(ref personId);
|
||||||
|
|
||||||
|
using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage())
|
||||||
|
{
|
||||||
|
uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host;
|
||||||
|
uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port;
|
||||||
|
uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme;
|
||||||
|
uriBuilderLocalVar.Path = ClientUtils.CONTEXT_PATH + "/person/display/{personId}";
|
||||||
|
uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7BpersonId%7D", Uri.EscapeDataString(personId.ToString()));
|
||||||
|
|
||||||
|
httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;
|
||||||
|
|
||||||
|
string[] acceptLocalVars = new string[] {
|
||||||
|
"application/json"
|
||||||
|
};
|
||||||
|
|
||||||
|
string acceptLocalVar = ClientUtils.SelectHeaderAccept(acceptLocalVars);
|
||||||
|
|
||||||
|
if (acceptLocalVar != null)
|
||||||
|
httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptLocalVar));
|
||||||
|
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
|
||||||
|
|
||||||
|
DateTime requestedAtLocalVar = DateTime.UtcNow;
|
||||||
|
|
||||||
|
using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
ILogger<ListApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<ListApiResponse>();
|
||||||
|
|
||||||
|
ListApiResponse apiResponseLocalVar = new ListApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/person/display/{personId}", requestedAtLocalVar, _jsonSerializerOptions);
|
||||||
|
|
||||||
|
AfterListDefaultImplementation(apiResponseLocalVar, personId);
|
||||||
|
|
||||||
|
Events.ExecuteOnList(apiResponseLocalVar);
|
||||||
|
|
||||||
|
return apiResponseLocalVar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
OnErrorListDefaultImplementation(e, "/person/display/{personId}", uriBuilderLocalVar.Path, personId);
|
||||||
|
Events.ExecuteOnErrorList(e);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="ListApiResponse"/>
|
||||||
|
/// </summary>
|
||||||
|
public partial class ListApiResponse : Org.OpenAPITools.Client.ApiResponse, IListApiResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The logger
|
||||||
|
/// </summary>
|
||||||
|
public ILogger<ListApiResponse> Logger { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="ListApiResponse"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logger"></param>
|
||||||
|
/// <param name="httpRequestMessage"></param>
|
||||||
|
/// <param name="httpResponseMessage"></param>
|
||||||
|
/// <param name="rawContent"></param>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <param name="requestedAt"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
public ListApiResponse(ILogger<ListApiResponse> logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
Logger = logger;
|
||||||
|
OnCreated(httpRequestMessage, httpResponseMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnCreated(System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the response is 200 Ok
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool IsOk => 200 == (int)StatusCode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the response if the response is 200 Ok
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Org.OpenAPITools.Model.Person Ok()
|
||||||
|
{
|
||||||
|
// This logic may be modified with the AsModel.mustache template
|
||||||
|
return IsOk
|
||||||
|
? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.Person>(RawContent, _jsonSerializerOptions)
|
||||||
|
: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the response is 200 Ok and the deserialized response is not null
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="result"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool TryOk(out Org.OpenAPITools.Model.Person result)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = Ok();
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode)
|
||||||
|
{
|
||||||
|
bool suppressDefaultLog = false;
|
||||||
|
OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode);
|
||||||
|
if (!suppressDefaultLog)
|
||||||
|
Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using System.Net.Http;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Any Api client
|
||||||
|
/// </summary>
|
||||||
|
public interface IApi
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The HttpClient
|
||||||
|
/// </summary>
|
||||||
|
HttpClient HttpClient { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// API Exception
|
||||||
|
/// </summary>
|
||||||
|
public class ApiException : Exception
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The reason the api request failed
|
||||||
|
/// </summary>
|
||||||
|
public string ReasonPhrase { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The HttpStatusCode
|
||||||
|
/// </summary>
|
||||||
|
public System.Net.HttpStatusCode StatusCode { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The raw data returned by the api
|
||||||
|
/// </summary>
|
||||||
|
public string RawContent { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Construct the ApiException from parts of the response
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reasonPhrase"></param>
|
||||||
|
/// <param name="statusCode"></param>
|
||||||
|
/// <param name="rawContent"></param>
|
||||||
|
public ApiException(string reasonPhrase, System.Net.HttpStatusCode statusCode, string rawContent) : base(reasonPhrase ?? rawContent)
|
||||||
|
{
|
||||||
|
ReasonPhrase = reasonPhrase;
|
||||||
|
|
||||||
|
StatusCode = statusCode;
|
||||||
|
|
||||||
|
RawContent = rawContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Org.OpenAPITools.Api;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An IApiFactory interface
|
||||||
|
/// </summary>
|
||||||
|
public interface IApiFactory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A method to create an IApi of type IResult
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="IResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
IResult Create<IResult>() where IResult : IApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An ApiFactory
|
||||||
|
/// </summary>
|
||||||
|
public class ApiFactory : IApiFactory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The service provider
|
||||||
|
/// </summary>
|
||||||
|
public IServiceProvider Services { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ApiFactory"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services"></param>
|
||||||
|
public ApiFactory(IServiceProvider services)
|
||||||
|
{
|
||||||
|
Services = services;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A method to create an IApi of type IResult
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="IResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IResult Create<IResult>() where IResult : IApi
|
||||||
|
{
|
||||||
|
return Services.GetRequiredService<IResult>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Useful for tracking server health
|
||||||
|
/// </summary>
|
||||||
|
public class ApiResponseEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The ApiResponse
|
||||||
|
/// </summary>
|
||||||
|
public ApiResponse ApiResponse { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ApiResponseEventArgs
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiResponse"></param>
|
||||||
|
public ApiResponseEventArgs(ApiResponse apiResponse)
|
||||||
|
{
|
||||||
|
ApiResponse = apiResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,170 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a non-generic contract for the ApiResponse wrapper.
|
||||||
|
/// </summary>
|
||||||
|
public partial interface IApiResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The IsSuccessStatusCode from the api response
|
||||||
|
/// </summary>
|
||||||
|
bool IsSuccessStatusCode { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the status code (HTTP status code)
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The status code.</value>
|
||||||
|
HttpStatusCode StatusCode { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The raw content of this response.
|
||||||
|
/// </summary>
|
||||||
|
string RawContent { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The DateTime when the request was retrieved.
|
||||||
|
/// </summary>
|
||||||
|
DateTime DownloadedAt { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The headers contained in the api response
|
||||||
|
/// </summary>
|
||||||
|
System.Net.Http.Headers.HttpResponseHeaders Headers { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The path used when making the request.
|
||||||
|
/// </summary>
|
||||||
|
string Path { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The reason phrase contained in the api response
|
||||||
|
/// </summary>
|
||||||
|
string ReasonPhrase { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The DateTime when the request was sent.
|
||||||
|
/// </summary>
|
||||||
|
DateTime RequestedAt { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Uri used when making the request.
|
||||||
|
/// </summary>
|
||||||
|
Uri RequestUri { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API Response
|
||||||
|
/// </summary>
|
||||||
|
public partial class ApiResponse : IApiResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the status code (HTTP status code)
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The status code.</value>
|
||||||
|
public HttpStatusCode StatusCode { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The raw data
|
||||||
|
/// </summary>
|
||||||
|
public string RawContent { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The IsSuccessStatusCode from the api response
|
||||||
|
/// </summary>
|
||||||
|
public bool IsSuccessStatusCode { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The reason phrase contained in the api response
|
||||||
|
/// </summary>
|
||||||
|
public string ReasonPhrase { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The headers contained in the api response
|
||||||
|
/// </summary>
|
||||||
|
public System.Net.Http.Headers.HttpResponseHeaders Headers { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The DateTime when the request was retrieved.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime DownloadedAt { get; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The DateTime when the request was sent.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime RequestedAt { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The path used when making the request.
|
||||||
|
/// </summary>
|
||||||
|
public string Path { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Uri used when making the request.
|
||||||
|
/// </summary>
|
||||||
|
public Uri RequestUri { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="System.Text.Json.JsonSerializerOptions"/>
|
||||||
|
/// </summary>
|
||||||
|
protected System.Text.Json.JsonSerializerOptions _jsonSerializerOptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Construct the response using an HttpResponseMessage
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="httpRequestMessage"></param>
|
||||||
|
/// <param name="httpResponseMessage"></param>
|
||||||
|
/// <param name="rawContent"></param>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <param name="requestedAt"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
public ApiResponse(System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
StatusCode = httpResponseMessage.StatusCode;
|
||||||
|
Headers = httpResponseMessage.Headers;
|
||||||
|
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
|
||||||
|
ReasonPhrase = httpResponseMessage.ReasonPhrase;
|
||||||
|
RawContent = rawContent;
|
||||||
|
Path = path;
|
||||||
|
RequestUri = httpRequestMessage.RequestUri;
|
||||||
|
RequestedAt = requestedAt;
|
||||||
|
_jsonSerializerOptions = jsonSerializerOptions;
|
||||||
|
OnCreated(httpRequestMessage, httpResponseMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnCreated(System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An interface for responses of type
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TType"></typeparam>
|
||||||
|
public interface IOk<TType> : IApiResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the response if the response is Ok
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
TType Ok();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the response is Ok and the deserialized response is not null
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="result"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool TryOk(out TType result);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,329 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using KellermanSoftware.CompareNetObjects;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
[assembly: InternalsVisibleTo("Org.OpenAPITools.Test")]
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Utility functions providing some benefit to API client consumers.
|
||||||
|
/// </summary>
|
||||||
|
public static class ClientUtils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An instance of CompareLogic.
|
||||||
|
/// </summary>
|
||||||
|
public static CompareLogic compareLogic;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Static constructor to initialise compareLogic.
|
||||||
|
/// </summary>
|
||||||
|
static ClientUtils()
|
||||||
|
{
|
||||||
|
ComparisonConfig comparisonConfig = new ComparisonConfig();
|
||||||
|
comparisonConfig.UseHashCodeIdentifier = true;
|
||||||
|
compareLogic = new CompareLogic(comparisonConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A delegate for events.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public delegate void EventHandler<T>(object sender, T e) where T : EventArgs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true when deserialization succeeds.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="json"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <param name="result"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool TryDeserialize<T>(string json, JsonSerializerOptions options, out T result)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = JsonSerializer.Deserialize<T>(json, options);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
result = default;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true when deserialization succeeds.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="reader"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <param name="result"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOptions options, out T result)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = JsonSerializer.Deserialize<T>(ref reader, options);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
result = default;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
/// 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="format">The DateTime serialization format.</param>
|
||||||
|
/// <returns>Formatted string.</returns>
|
||||||
|
public static string ParameterToString(object obj, string format = ISO8601_DATETIME_FORMAT)
|
||||||
|
{
|
||||||
|
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(format);
|
||||||
|
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(format);
|
||||||
|
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));
|
||||||
|
return string.Join(",", entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Convert.ToString(obj, System.Globalization.CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// URL encode a string
|
||||||
|
/// Credit/Ref: https://github.com/restsharp/RestSharp/blob/master/RestSharp/Extensions/StringExtensions.cs#L50
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">string to be URL encoded</param>
|
||||||
|
/// <returns>Byte array</returns>
|
||||||
|
public static string UrlEncode(string input)
|
||||||
|
{
|
||||||
|
const int maxLength = 32766;
|
||||||
|
|
||||||
|
if (input == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("input");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.Length <= maxLength)
|
||||||
|
{
|
||||||
|
return Uri.EscapeDataString(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder(input.Length * 2);
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
while (index < input.Length)
|
||||||
|
{
|
||||||
|
int length = Math.Min(input.Length - index, maxLength);
|
||||||
|
string subString = input.Substring(index, length);
|
||||||
|
|
||||||
|
sb.Append(Uri.EscapeDataString(subString));
|
||||||
|
index += subString.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
/// Get the discriminator
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="utf8JsonReader"></param>
|
||||||
|
/// <param name="discriminator"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="JsonException"></exception>
|
||||||
|
public static string GetDiscriminator(Utf8JsonReader utf8JsonReader, string discriminator)
|
||||||
|
{
|
||||||
|
int currentDepth = utf8JsonReader.CurrentDepth;
|
||||||
|
|
||||||
|
if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray)
|
||||||
|
throw new JsonException();
|
||||||
|
|
||||||
|
JsonTokenType startingTokenType = utf8JsonReader.TokenType;
|
||||||
|
|
||||||
|
while (utf8JsonReader.Read())
|
||||||
|
{
|
||||||
|
if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1)
|
||||||
|
{
|
||||||
|
string localVarJsonPropertyName = utf8JsonReader.GetString();
|
||||||
|
utf8JsonReader.Read();
|
||||||
|
|
||||||
|
if (localVarJsonPropertyName != null && localVarJsonPropertyName.Equals(discriminator))
|
||||||
|
return utf8JsonReader.GetString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new JsonException("The specified discriminator was not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The base path of the API
|
||||||
|
/// </summary>
|
||||||
|
public const string BASE_ADDRESS = "http://api.example.xyz/v1";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The scheme of the API
|
||||||
|
/// </summary>
|
||||||
|
public const string SCHEME = "http";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The context path of the API
|
||||||
|
/// </summary>
|
||||||
|
public const string CONTEXT_PATH = "/v1";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The host of the API
|
||||||
|
/// </summary>
|
||||||
|
public const string HOST = "api.example.xyz";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The format to use for DateTime serialization
|
||||||
|
/// </summary>
|
||||||
|
public const string ISO8601_DATETIME_FORMAT = "o";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A class containing a CookieContainer
|
||||||
|
/// </summary>
|
||||||
|
public sealed class CookieContainer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The collection of tokens
|
||||||
|
/// </summary>
|
||||||
|
public System.Net.CookieContainer Value { get; } = new System.Net.CookieContainer();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Formatter for 'date' and 'date-time' 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 DateTimeJsonConverter : JsonConverter<DateTime>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The formats used to deserialize the date
|
||||||
|
/// </summary>
|
||||||
|
public static string[] Formats { get; } = {
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ssK",
|
||||||
|
"yyyy'-'MM'-'dd",
|
||||||
|
"yyyyMMddTHHmmss.fffffffK",
|
||||||
|
"yyyyMMddTHHmmss.ffffffK",
|
||||||
|
"yyyyMMddTHHmmss.fffffK",
|
||||||
|
"yyyyMMddTHHmmss.ffffK",
|
||||||
|
"yyyyMMddTHHmmss.fffK",
|
||||||
|
"yyyyMMddTHHmmss.ffK",
|
||||||
|
"yyyyMMddTHHmmss.fK",
|
||||||
|
"yyyyMMddTHHmmssK",
|
||||||
|
"yyyyMMdd"
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a DateTime from the Json object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reader"></param>
|
||||||
|
/// <param name="typeToConvert"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
|
||||||
|
if (reader.TokenType == JsonTokenType.Null)
|
||||||
|
throw new NotSupportedException();
|
||||||
|
|
||||||
|
string value = reader.GetString();
|
||||||
|
|
||||||
|
foreach(string format in Formats)
|
||||||
|
if (DateTime.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime result))
|
||||||
|
return result;
|
||||||
|
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the DateTime to the json writer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"></param>
|
||||||
|
/// <param name="dateTimeValue"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
public override void Write(Utf8JsonWriter writer, DateTime dateTimeValue, JsonSerializerOptions options) =>
|
||||||
|
writer.WriteStringValue(dateTimeValue.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK", CultureInfo.InvariantCulture));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Formatter for 'date' and 'date-time' 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 DateTimeNullableJsonConverter : JsonConverter<DateTime?>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The formats used to deserialize the date
|
||||||
|
/// </summary>
|
||||||
|
public static string[] Formats { get; } = {
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ssK",
|
||||||
|
"yyyy'-'MM'-'dd",
|
||||||
|
"yyyyMMddTHHmmss.fffffffK",
|
||||||
|
"yyyyMMddTHHmmss.ffffffK",
|
||||||
|
"yyyyMMddTHHmmss.fffffK",
|
||||||
|
"yyyyMMddTHHmmss.ffffK",
|
||||||
|
"yyyyMMddTHHmmss.fffK",
|
||||||
|
"yyyyMMddTHHmmss.ffK",
|
||||||
|
"yyyyMMddTHHmmss.fK",
|
||||||
|
"yyyyMMddTHHmmssK",
|
||||||
|
"yyyyMMdd"
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a DateTime from the Json object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reader"></param>
|
||||||
|
/// <param name="typeToConvert"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
|
||||||
|
if (reader.TokenType == JsonTokenType.Null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
string value = reader.GetString();
|
||||||
|
|
||||||
|
foreach(string format in Formats)
|
||||||
|
if (DateTime.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime result))
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the DateTime to the json writer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"></param>
|
||||||
|
/// <param name="dateTimeValue"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
public override void Write(Utf8JsonWriter writer, DateTime? dateTimeValue, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
if (dateTimeValue == null)
|
||||||
|
writer.WriteNullValue();
|
||||||
|
else
|
||||||
|
writer.WriteStringValue(dateTimeValue.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK", CultureInfo.InvariantCulture));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Useful for tracking server health
|
||||||
|
/// </summary>
|
||||||
|
public class ExceptionEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The ApiResponse
|
||||||
|
/// </summary>
|
||||||
|
public Exception Exception { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ExcepetionEventArgs
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exception"></param>
|
||||||
|
public ExceptionEventArgs(Exception exception)
|
||||||
|
{
|
||||||
|
Exception = exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* 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.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Org.OpenAPITools.Api;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides hosting configuration for Org.OpenAPITools
|
||||||
|
/// </summary>
|
||||||
|
public class HostConfiguration
|
||||||
|
{
|
||||||
|
private readonly IServiceCollection _services;
|
||||||
|
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions();
|
||||||
|
|
||||||
|
internal bool HttpClientsAdded { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates the class
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services"></param>
|
||||||
|
public HostConfiguration(IServiceCollection services)
|
||||||
|
{
|
||||||
|
_services = services;
|
||||||
|
_jsonOptions.Converters.Add(new JsonStringEnumConverter());
|
||||||
|
_jsonOptions.Converters.Add(new DateTimeJsonConverter());
|
||||||
|
_jsonOptions.Converters.Add(new DateTimeNullableJsonConverter());
|
||||||
|
_jsonOptions.Converters.Add(new AdultJsonConverter());
|
||||||
|
_jsonOptions.Converters.Add(new ChildJsonConverter());
|
||||||
|
_jsonOptions.Converters.Add(new PersonJsonConverter());
|
||||||
|
JsonSerializerOptionsProvider jsonSerializerOptionsProvider = new JsonSerializerOptionsProvider(_jsonOptions);
|
||||||
|
_services.AddSingleton(jsonSerializerOptionsProvider);
|
||||||
|
_services.AddSingleton<IApiFactory, ApiFactory>();
|
||||||
|
_services.AddSingleton<DefaultApiEvents>();
|
||||||
|
_services.AddTransient<IDefaultApi, DefaultApi>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures the HttpClients.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="builder"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public HostConfiguration AddApiHttpClients
|
||||||
|
(
|
||||||
|
Action<HttpClient> client = null, Action<IHttpClientBuilder> builder = null)
|
||||||
|
{
|
||||||
|
if (client == null)
|
||||||
|
client = c => c.BaseAddress = new Uri(ClientUtils.BASE_ADDRESS);
|
||||||
|
|
||||||
|
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||||
|
|
||||||
|
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||||
|
|
||||||
|
if (builder != null)
|
||||||
|
foreach (IHttpClientBuilder instance in builders)
|
||||||
|
builder(instance);
|
||||||
|
|
||||||
|
HttpClientsAdded = true;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures the JsonSerializerSettings
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public HostConfiguration ConfigureJsonOptions(Action<JsonSerializerOptions> options)
|
||||||
|
{
|
||||||
|
options(_jsonOptions);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds tokens to your IServiceCollection
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TTokenBase"></typeparam>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public HostConfiguration AddTokens<TTokenBase>(TTokenBase token) where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
return AddTokens(new TTokenBase[]{ token });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds tokens to your IServiceCollection
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TTokenBase"></typeparam>
|
||||||
|
/// <param name="tokens"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public HostConfiguration AddTokens<TTokenBase>(IEnumerable<TTokenBase> tokens) where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
TokenContainer<TTokenBase> container = new TokenContainer<TTokenBase>(tokens);
|
||||||
|
_services.AddSingleton(services => container);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a token provider to your IServiceCollection
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TTokenProvider"></typeparam>
|
||||||
|
/// <typeparam name="TTokenBase"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public HostConfiguration UseProvider<TTokenProvider, TTokenBase>()
|
||||||
|
where TTokenProvider : TokenProvider<TTokenBase>
|
||||||
|
where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
_services.AddSingleton<TTokenProvider>();
|
||||||
|
_services.AddSingleton<TokenProvider<TTokenBase>>(services => services.GetRequiredService<TTokenProvider>());
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides the JsonSerializerOptions
|
||||||
|
/// </summary>
|
||||||
|
public class JsonSerializerOptionsProvider
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// the JsonSerializerOptions
|
||||||
|
/// </summary>
|
||||||
|
public JsonSerializerOptions Options { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a JsonSerializerOptionsProvider
|
||||||
|
/// </summary>
|
||||||
|
public JsonSerializerOptionsProvider(JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
Options = options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A wrapper for operation parameters which are not required
|
||||||
|
/// </summary>
|
||||||
|
public struct Option<TType>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The value to send to the server
|
||||||
|
/// </summary>
|
||||||
|
public TType Value { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When true the value will be sent to the server
|
||||||
|
/// </summary>
|
||||||
|
internal bool IsSet { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A wrapper for operation parameters which are not required
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public Option(TType value)
|
||||||
|
{
|
||||||
|
IsSet = true;
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Implicitly converts this option to the contained type
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="option"></param>
|
||||||
|
public static implicit operator TType(Option<TType> option) => option.Value;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Implicitly converts the provided value to an Option
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public static implicit operator Option<TType>(TType value) => new Option<TType>(value);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* 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.Linq;
|
||||||
|
using System.Threading.Channels;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a token to the api clients. Tokens will be rate limited based on the provided TimeSpan.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TTokenBase"></typeparam>
|
||||||
|
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
internal Dictionary<string, Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, Channel<TTokenBase>>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="container"></param>
|
||||||
|
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||||
|
{
|
||||||
|
foreach(TTokenBase token in _tokens)
|
||||||
|
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||||
|
|
||||||
|
BoundedChannelOptions options = new BoundedChannelOptions(_tokens.Length)
|
||||||
|
{
|
||||||
|
FullMode = BoundedChannelFullMode.DropWrite
|
||||||
|
};
|
||||||
|
|
||||||
|
AvailableTokens.Add(string.Empty, Channel.CreateBounded<TTokenBase>(options));
|
||||||
|
|
||||||
|
foreach(Channel<TTokenBase> tokens in AvailableTokens.Values)
|
||||||
|
for (int i = 0; i < _tokens.Length; i++)
|
||||||
|
_tokens[i].TokenBecameAvailable += ((sender) => tokens.Writer.TryWrite((TTokenBase) sender));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||||
|
{
|
||||||
|
if (!AvailableTokens.TryGetValue(header, out Channel<TTokenBase> tokens))
|
||||||
|
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||||
|
|
||||||
|
return await tokens.Reader.ReadAsync(cancellation).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The base for all tokens.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class TokenBase
|
||||||
|
{
|
||||||
|
private DateTime _nextAvailable = DateTime.UtcNow;
|
||||||
|
private object _nextAvailableLock = new object();
|
||||||
|
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||||
|
|
||||||
|
|
||||||
|
internal TimeSpan? Timeout { get; set; }
|
||||||
|
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||||
|
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize a TokenBase object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timeout"></param>
|
||||||
|
internal TokenBase(TimeSpan? timeout = null)
|
||||||
|
{
|
||||||
|
Timeout = timeout;
|
||||||
|
|
||||||
|
if (Timeout != null)
|
||||||
|
StartTimer(Timeout.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts the token's timer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timeout"></param>
|
||||||
|
internal void StartTimer(TimeSpan timeout)
|
||||||
|
{
|
||||||
|
Timeout = timeout;
|
||||||
|
_timer.Interval = Timeout.Value.TotalMilliseconds;
|
||||||
|
_timer.Elapsed += OnTimer;
|
||||||
|
_timer.AutoReset = true;
|
||||||
|
_timer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true while the token is rate limited.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsRateLimited => _nextAvailable > DateTime.UtcNow;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Triggered when the server returns status code TooManyRequests
|
||||||
|
/// Once triggered the local timeout will be extended an arbitrary length of time.
|
||||||
|
/// </summary>
|
||||||
|
public void BeginRateLimit()
|
||||||
|
{
|
||||||
|
lock(_nextAvailableLock)
|
||||||
|
_nextAvailable = DateTime.UtcNow.AddSeconds(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTimer(object sender, System.Timers.ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
if (TokenBecameAvailable != null && !IsRateLimited)
|
||||||
|
TokenBecameAvailable.Invoke(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A container for a collection of tokens.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TTokenBase"></typeparam>
|
||||||
|
public sealed class TokenContainer<TTokenBase> where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The collection of tokens
|
||||||
|
/// </summary>
|
||||||
|
public List<TTokenBase> Tokens { get; } = new List<TTokenBase>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a TokenContainer
|
||||||
|
/// </summary>
|
||||||
|
public TokenContainer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a TokenContainer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tokens"></param>
|
||||||
|
public TokenContainer(System.Collections.Generic.IEnumerable<TTokenBase> tokens)
|
||||||
|
{
|
||||||
|
Tokens = tokens.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A class which will provide tokens.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The array of tokens.
|
||||||
|
/// </summary>
|
||||||
|
protected TTokenBase[] _tokens;
|
||||||
|
|
||||||
|
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a TokenProvider.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tokens"></param>
|
||||||
|
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||||
|
{
|
||||||
|
_tokens = tokens.ToArray();
|
||||||
|
|
||||||
|
if (_tokens.Length == 0)
|
||||||
|
throw new ArgumentException("You did not provide any tokens.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Extensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for IHostBuilder
|
||||||
|
/// </summary>
|
||||||
|
public static class IHostBuilderExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Add the api to your host builder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder"></param>
|
||||||
|
public static IHostBuilder ConfigureApi(this IHostBuilder builder)
|
||||||
|
{
|
||||||
|
builder.ConfigureServices((context, services) =>
|
||||||
|
{
|
||||||
|
HostConfiguration config = new HostConfiguration(services);
|
||||||
|
|
||||||
|
IServiceCollectionExtensions.AddApi(services, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add the api to your host builder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
public static IHostBuilder ConfigureApi(this IHostBuilder builder, Action<HostBuilderContext, IServiceCollection, HostConfiguration> options)
|
||||||
|
{
|
||||||
|
builder.ConfigureServices((context, services) =>
|
||||||
|
{
|
||||||
|
HostConfiguration config = new HostConfiguration(services);
|
||||||
|
|
||||||
|
options(context, services, config);
|
||||||
|
|
||||||
|
IServiceCollectionExtensions.AddApi(services, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Polly.Timeout;
|
||||||
|
using Polly.Extensions.Http;
|
||||||
|
using Polly;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Extensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for IHttpClientBuilder
|
||||||
|
/// </summary>
|
||||||
|
public static class IHttpClientBuilderExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a Polly retry policy to your clients.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="retries"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IHttpClientBuilder AddRetryPolicy(this IHttpClientBuilder client, int retries)
|
||||||
|
{
|
||||||
|
client.AddPolicyHandler(RetryPolicy(retries));
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a Polly timeout policy to your clients.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="timeout"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IHttpClientBuilder AddTimeoutPolicy(this IHttpClientBuilder client, TimeSpan timeout)
|
||||||
|
{
|
||||||
|
client.AddPolicyHandler(TimeoutPolicy(timeout));
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a Polly circuit breaker to your clients.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="handledEventsAllowedBeforeBreaking"></param>
|
||||||
|
/// <param name="durationOfBreak"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IHttpClientBuilder AddCircuitBreakerPolicy(this IHttpClientBuilder client, int handledEventsAllowedBeforeBreaking, TimeSpan durationOfBreak)
|
||||||
|
{
|
||||||
|
client.AddTransientHttpErrorPolicy(builder => CircuitBreakerPolicy(builder, handledEventsAllowedBeforeBreaking, durationOfBreak));
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Polly.Retry.AsyncRetryPolicy<HttpResponseMessage> RetryPolicy(int retries)
|
||||||
|
=> HttpPolicyExtensions
|
||||||
|
.HandleTransientHttpError()
|
||||||
|
.Or<TimeoutRejectedException>()
|
||||||
|
.RetryAsync(retries);
|
||||||
|
|
||||||
|
private static AsyncTimeoutPolicy<HttpResponseMessage> TimeoutPolicy(TimeSpan timeout)
|
||||||
|
=> Policy.TimeoutAsync<HttpResponseMessage>(timeout);
|
||||||
|
|
||||||
|
private static Polly.CircuitBreaker.AsyncCircuitBreakerPolicy<HttpResponseMessage> CircuitBreakerPolicy(
|
||||||
|
PolicyBuilder<HttpResponseMessage> builder, int handledEventsAllowedBeforeBreaking, TimeSpan durationOfBreak)
|
||||||
|
=> builder.CircuitBreakerAsync(handledEventsAllowedBeforeBreaking, durationOfBreak);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Extensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for IServiceCollection
|
||||||
|
/// </summary>
|
||||||
|
public static class IServiceCollectionExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Add the api to your host builder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services"></param>
|
||||||
|
public static void AddApi(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
HostConfiguration config = new HostConfiguration(services);
|
||||||
|
AddApi(services, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add the api to your host builder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
public static void AddApi(this IServiceCollection services, Action<HostConfiguration> options)
|
||||||
|
{
|
||||||
|
HostConfiguration config = new HostConfiguration(services);
|
||||||
|
options(config);
|
||||||
|
AddApi(services, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void AddApi(IServiceCollection services, HostConfiguration host)
|
||||||
|
{
|
||||||
|
if (!host.HttpClientsAdded)
|
||||||
|
host.AddApiHttpClients();
|
||||||
|
|
||||||
|
services.AddSingleton<CookieContainer>();
|
||||||
|
|
||||||
|
// ensure that a token provider was provided for this token type
|
||||||
|
// if not, default to RateLimitProvider
|
||||||
|
var containerServices = services.Where(s => s.ServiceType.IsGenericType &&
|
||||||
|
s.ServiceType.GetGenericTypeDefinition().IsAssignableFrom(typeof(TokenContainer<>))).ToArray();
|
||||||
|
|
||||||
|
foreach(var containerService in containerServices)
|
||||||
|
{
|
||||||
|
var tokenType = containerService.ServiceType.GenericTypeArguments[0];
|
||||||
|
|
||||||
|
var provider = services.FirstOrDefault(s => s.ServiceType.IsAssignableFrom(typeof(TokenProvider<>).MakeGenericType(tokenType)));
|
||||||
|
|
||||||
|
if (provider == null)
|
||||||
|
{
|
||||||
|
services.AddSingleton(typeof(RateLimitProvider<>).MakeGenericType(tokenType));
|
||||||
|
services.AddSingleton(typeof(TokenProvider<>).MakeGenericType(tokenType),
|
||||||
|
s => s.GetRequiredService(typeof(RateLimitProvider<>).MakeGenericType(tokenType)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,205 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Model
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A representation of an adult
|
||||||
|
/// </summary>
|
||||||
|
public partial class Adult : Person, IValidatableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Adult" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="children">children</param>
|
||||||
|
/// <param name="firstName">firstName</param>
|
||||||
|
/// <param name="lastName">lastName</param>
|
||||||
|
[JsonConstructor]
|
||||||
|
public Adult(Option<List<Child>> children = default, Option<string> firstName = default, Option<string> lastName = default) : base(firstName, lastName)
|
||||||
|
{
|
||||||
|
ChildrenOption = children;
|
||||||
|
OnCreated();
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnCreated();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to track the state of Children
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||||
|
public Option<List<Child>> ChildrenOption { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets Children
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("children")]
|
||||||
|
public List<Child> Children { get { return this.ChildrenOption; } set { this.ChildrenOption = new Option<List<Child>>(value); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The discriminator
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||||
|
public new string Type { get; } = "Adult";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String presentation of the object</returns>
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append("class Adult {\n");
|
||||||
|
sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n");
|
||||||
|
sb.Append(" Children: ").Append(Children).Append("\n");
|
||||||
|
sb.Append("}\n");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A Json converter for type <see cref="Adult" />
|
||||||
|
/// </summary>
|
||||||
|
public class AdultJsonConverter : JsonConverter<Adult>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes json to <see cref="Adult" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="utf8JsonReader"></param>
|
||||||
|
/// <param name="typeToConvert"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="JsonException"></exception>
|
||||||
|
public override Adult Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
int currentDepth = utf8JsonReader.CurrentDepth;
|
||||||
|
|
||||||
|
if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray)
|
||||||
|
throw new JsonException();
|
||||||
|
|
||||||
|
JsonTokenType startingTokenType = utf8JsonReader.TokenType;
|
||||||
|
|
||||||
|
Option<List<Child>> children = default;
|
||||||
|
Option<string> firstName = default;
|
||||||
|
Option<string> lastName = default;
|
||||||
|
Option<string> type = default;
|
||||||
|
|
||||||
|
while (utf8JsonReader.Read())
|
||||||
|
{
|
||||||
|
if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1)
|
||||||
|
{
|
||||||
|
string localVarJsonPropertyName = utf8JsonReader.GetString();
|
||||||
|
utf8JsonReader.Read();
|
||||||
|
|
||||||
|
switch (localVarJsonPropertyName)
|
||||||
|
{
|
||||||
|
case "children":
|
||||||
|
if (utf8JsonReader.TokenType != JsonTokenType.Null)
|
||||||
|
children = new Option<List<Child>>(JsonSerializer.Deserialize<List<Child>>(ref utf8JsonReader, jsonSerializerOptions));
|
||||||
|
break;
|
||||||
|
case "firstName":
|
||||||
|
firstName = new Option<string>(utf8JsonReader.GetString());
|
||||||
|
break;
|
||||||
|
case "lastName":
|
||||||
|
lastName = new Option<string>(utf8JsonReader.GetString());
|
||||||
|
break;
|
||||||
|
case "$_type":
|
||||||
|
type = new Option<string>(utf8JsonReader.GetString());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (children.IsSet && children.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(children), "Property is not nullable for class Adult.");
|
||||||
|
|
||||||
|
if (firstName.IsSet && firstName.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(firstName), "Property is not nullable for class Adult.");
|
||||||
|
|
||||||
|
if (lastName.IsSet && lastName.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(lastName), "Property is not nullable for class Adult.");
|
||||||
|
|
||||||
|
if (type.IsSet && type.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(type), "Property is not nullable for class Adult.");
|
||||||
|
|
||||||
|
return new Adult(children, firstName, lastName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializes a <see cref="Adult" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"></param>
|
||||||
|
/// <param name="adult"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public override void Write(Utf8JsonWriter writer, Adult adult, JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
writer.WriteStartObject();
|
||||||
|
|
||||||
|
WriteProperties(writer, adult, jsonSerializerOptions);
|
||||||
|
writer.WriteEndObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializes the properties of <see cref="Adult" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"></param>
|
||||||
|
/// <param name="adult"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public void WriteProperties(Utf8JsonWriter writer, Adult adult, JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
if (adult.ChildrenOption.IsSet && adult.Children == null)
|
||||||
|
throw new ArgumentNullException(nameof(adult.Children), "Property is required for class Adult.");
|
||||||
|
|
||||||
|
if (adult.FirstNameOption.IsSet && adult.FirstName == null)
|
||||||
|
throw new ArgumentNullException(nameof(adult.FirstName), "Property is required for class Adult.");
|
||||||
|
|
||||||
|
if (adult.LastNameOption.IsSet && adult.LastName == null)
|
||||||
|
throw new ArgumentNullException(nameof(adult.LastName), "Property is required for class Adult.");
|
||||||
|
|
||||||
|
if (adult.ChildrenOption.IsSet)
|
||||||
|
{
|
||||||
|
writer.WritePropertyName("children");
|
||||||
|
JsonSerializer.Serialize(writer, adult.Children, jsonSerializerOptions);
|
||||||
|
}
|
||||||
|
if (adult.FirstNameOption.IsSet)
|
||||||
|
writer.WriteString("firstName", adult.FirstName);
|
||||||
|
|
||||||
|
if (adult.LastNameOption.IsSet)
|
||||||
|
writer.WriteString("lastName", adult.LastName);
|
||||||
|
|
||||||
|
writer.WriteString("$_type", adult.Type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,227 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Model
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A representation of a child
|
||||||
|
/// </summary>
|
||||||
|
public partial class Child : Person, IValidatableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Child" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="age">age</param>
|
||||||
|
/// <param name="firstName">firstName</param>
|
||||||
|
/// <param name="lastName">lastName</param>
|
||||||
|
/// <param name="boosterSeat">boosterSeat</param>
|
||||||
|
[JsonConstructor]
|
||||||
|
public Child(Option<int?> age = default, Option<string> firstName = default, Option<string> lastName = default, Option<bool?> boosterSeat = default) : base(firstName, lastName)
|
||||||
|
{
|
||||||
|
AgeOption = age;
|
||||||
|
BoosterSeatOption = boosterSeat;
|
||||||
|
OnCreated();
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnCreated();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to track the state of Age
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||||
|
public Option<int?> AgeOption { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets Age
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("age")]
|
||||||
|
public int? Age { get { return this.AgeOption; } set { this.AgeOption = new Option<int?>(value); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The discriminator
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||||
|
public new string Type { get; } = "Child";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to track the state of BoosterSeat
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||||
|
public Option<bool?> BoosterSeatOption { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets BoosterSeat
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("boosterSeat")]
|
||||||
|
public bool? BoosterSeat { get { return this.BoosterSeatOption; } set { this.BoosterSeatOption = new Option<bool?>(value); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String presentation of the object</returns>
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append("class Child {\n");
|
||||||
|
sb.Append(" ").Append(base.ToString()?.Replace("\n", "\n ")).Append("\n");
|
||||||
|
sb.Append(" Age: ").Append(Age).Append("\n");
|
||||||
|
sb.Append(" BoosterSeat: ").Append(BoosterSeat).Append("\n");
|
||||||
|
sb.Append("}\n");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A Json converter for type <see cref="Child" />
|
||||||
|
/// </summary>
|
||||||
|
public class ChildJsonConverter : JsonConverter<Child>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes json to <see cref="Child" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="utf8JsonReader"></param>
|
||||||
|
/// <param name="typeToConvert"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="JsonException"></exception>
|
||||||
|
public override Child Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
int currentDepth = utf8JsonReader.CurrentDepth;
|
||||||
|
|
||||||
|
if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray)
|
||||||
|
throw new JsonException();
|
||||||
|
|
||||||
|
JsonTokenType startingTokenType = utf8JsonReader.TokenType;
|
||||||
|
|
||||||
|
Option<int?> age = default;
|
||||||
|
Option<string> firstName = default;
|
||||||
|
Option<string> lastName = default;
|
||||||
|
Option<string> type = default;
|
||||||
|
Option<bool?> boosterSeat = default;
|
||||||
|
|
||||||
|
while (utf8JsonReader.Read())
|
||||||
|
{
|
||||||
|
if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1)
|
||||||
|
{
|
||||||
|
string localVarJsonPropertyName = utf8JsonReader.GetString();
|
||||||
|
utf8JsonReader.Read();
|
||||||
|
|
||||||
|
switch (localVarJsonPropertyName)
|
||||||
|
{
|
||||||
|
case "age":
|
||||||
|
if (utf8JsonReader.TokenType != JsonTokenType.Null)
|
||||||
|
age = new Option<int?>(utf8JsonReader.GetInt32());
|
||||||
|
break;
|
||||||
|
case "firstName":
|
||||||
|
firstName = new Option<string>(utf8JsonReader.GetString());
|
||||||
|
break;
|
||||||
|
case "lastName":
|
||||||
|
lastName = new Option<string>(utf8JsonReader.GetString());
|
||||||
|
break;
|
||||||
|
case "$_type":
|
||||||
|
type = new Option<string>(utf8JsonReader.GetString());
|
||||||
|
break;
|
||||||
|
case "boosterSeat":
|
||||||
|
if (utf8JsonReader.TokenType != JsonTokenType.Null)
|
||||||
|
boosterSeat = new Option<bool?>(utf8JsonReader.GetBoolean());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (age.IsSet && age.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(age), "Property is not nullable for class Child.");
|
||||||
|
|
||||||
|
if (firstName.IsSet && firstName.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(firstName), "Property is not nullable for class Child.");
|
||||||
|
|
||||||
|
if (lastName.IsSet && lastName.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(lastName), "Property is not nullable for class Child.");
|
||||||
|
|
||||||
|
if (type.IsSet && type.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(type), "Property is not nullable for class Child.");
|
||||||
|
|
||||||
|
if (boosterSeat.IsSet && boosterSeat.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(boosterSeat), "Property is not nullable for class Child.");
|
||||||
|
|
||||||
|
return new Child(age, firstName, lastName, boosterSeat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializes a <see cref="Child" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"></param>
|
||||||
|
/// <param name="child"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public override void Write(Utf8JsonWriter writer, Child child, JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
writer.WriteStartObject();
|
||||||
|
|
||||||
|
WriteProperties(writer, child, jsonSerializerOptions);
|
||||||
|
writer.WriteEndObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializes the properties of <see cref="Child" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"></param>
|
||||||
|
/// <param name="child"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public void WriteProperties(Utf8JsonWriter writer, Child child, JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
if (child.FirstNameOption.IsSet && child.FirstName == null)
|
||||||
|
throw new ArgumentNullException(nameof(child.FirstName), "Property is required for class Child.");
|
||||||
|
|
||||||
|
if (child.LastNameOption.IsSet && child.LastName == null)
|
||||||
|
throw new ArgumentNullException(nameof(child.LastName), "Property is required for class Child.");
|
||||||
|
|
||||||
|
if (child.AgeOption.IsSet)
|
||||||
|
writer.WriteNumber("age", child.AgeOption.Value.Value);
|
||||||
|
|
||||||
|
if (child.FirstNameOption.IsSet)
|
||||||
|
writer.WriteString("firstName", child.FirstName);
|
||||||
|
|
||||||
|
if (child.LastNameOption.IsSet)
|
||||||
|
writer.WriteString("lastName", child.LastName);
|
||||||
|
|
||||||
|
writer.WriteString("$_type", child.Type);
|
||||||
|
|
||||||
|
if (child.BoosterSeatOption.IsSet)
|
||||||
|
writer.WriteBoolean("boosterSeat", child.BoosterSeatOption.Value.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,247 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* Example
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using OpenAPIClientUtils = Org.OpenAPITools.Client.ClientUtils;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Model
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Person
|
||||||
|
/// </summary>
|
||||||
|
public partial class Person : IValidatableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="Person" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="firstName">firstName</param>
|
||||||
|
/// <param name="lastName">lastName</param>
|
||||||
|
[JsonConstructor]
|
||||||
|
public Person(Option<string> firstName = default, Option<string> lastName = default)
|
||||||
|
{
|
||||||
|
FirstNameOption = firstName;
|
||||||
|
LastNameOption = lastName;
|
||||||
|
OnCreated();
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnCreated();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to track the state of FirstName
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||||
|
public Option<string> FirstNameOption { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets FirstName
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("firstName")]
|
||||||
|
public string FirstName { get { return this.FirstNameOption; } set { this.FirstNameOption = new Option<string>(value); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to track the state of LastName
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||||
|
public Option<string> LastNameOption { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets LastName
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("lastName")]
|
||||||
|
public string LastName { get { return this.LastNameOption; } set { this.LastNameOption = new Option<string>(value); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The discriminator
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||||
|
public string Type { get; } = "Person";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or Sets additional properties
|
||||||
|
/// </summary>
|
||||||
|
[JsonExtensionData]
|
||||||
|
public Dictionary<string, JsonElement> AdditionalProperties { get; } = new Dictionary<string, JsonElement>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String presentation of the object</returns>
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append("class Person {\n");
|
||||||
|
sb.Append(" FirstName: ").Append(FirstName).Append("\n");
|
||||||
|
sb.Append(" LastName: ").Append(LastName).Append("\n");
|
||||||
|
sb.Append(" AdditionalProperties: ").Append(AdditionalProperties).Append("\n");
|
||||||
|
sb.Append("}\n");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To validate all properties of the instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext">Validation context</param>
|
||||||
|
/// <returns>Validation Result</returns>
|
||||||
|
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
return this.BaseValidate(validationContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To validate all properties of the instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext">Validation context</param>
|
||||||
|
/// <returns>Validation Result</returns>
|
||||||
|
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A Json converter for type <see cref="Person" />
|
||||||
|
/// </summary>
|
||||||
|
public class PersonJsonConverter : JsonConverter<Person>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes json to <see cref="Person" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="utf8JsonReader"></param>
|
||||||
|
/// <param name="typeToConvert"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="JsonException"></exception>
|
||||||
|
public override Person Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
int currentDepth = utf8JsonReader.CurrentDepth;
|
||||||
|
|
||||||
|
if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray)
|
||||||
|
throw new JsonException();
|
||||||
|
|
||||||
|
JsonTokenType startingTokenType = utf8JsonReader.TokenType;
|
||||||
|
|
||||||
|
Option<string> firstName = default;
|
||||||
|
Option<string> lastName = default;
|
||||||
|
Option<string> type = default;
|
||||||
|
|
||||||
|
string discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "$_type");
|
||||||
|
|
||||||
|
if (discriminator != null && discriminator.Equals("Adult"))
|
||||||
|
return JsonSerializer.Deserialize<Adult>(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value.");
|
||||||
|
|
||||||
|
if (discriminator != null && discriminator.Equals("Child"))
|
||||||
|
return JsonSerializer.Deserialize<Child>(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value.");
|
||||||
|
|
||||||
|
while (utf8JsonReader.Read())
|
||||||
|
{
|
||||||
|
if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1)
|
||||||
|
{
|
||||||
|
string localVarJsonPropertyName = utf8JsonReader.GetString();
|
||||||
|
utf8JsonReader.Read();
|
||||||
|
|
||||||
|
switch (localVarJsonPropertyName)
|
||||||
|
{
|
||||||
|
case "firstName":
|
||||||
|
firstName = new Option<string>(utf8JsonReader.GetString());
|
||||||
|
break;
|
||||||
|
case "lastName":
|
||||||
|
lastName = new Option<string>(utf8JsonReader.GetString());
|
||||||
|
break;
|
||||||
|
case "$_type":
|
||||||
|
type = new Option<string>(utf8JsonReader.GetString());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firstName.IsSet && firstName.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(firstName), "Property is not nullable for class Person.");
|
||||||
|
|
||||||
|
if (lastName.IsSet && lastName.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(lastName), "Property is not nullable for class Person.");
|
||||||
|
|
||||||
|
if (type.IsSet && type.Value == null)
|
||||||
|
throw new ArgumentNullException(nameof(type), "Property is not nullable for class Person.");
|
||||||
|
|
||||||
|
return new Person(firstName, lastName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializes a <see cref="Person" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"></param>
|
||||||
|
/// <param name="person"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public override void Write(Utf8JsonWriter writer, Person person, JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
if (person is Adult adult){
|
||||||
|
JsonSerializer.Serialize<Adult>(writer, adult, jsonSerializerOptions);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (person is Child child){
|
||||||
|
JsonSerializer.Serialize<Child>(writer, child, jsonSerializerOptions);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.WriteStartObject();
|
||||||
|
|
||||||
|
WriteProperties(writer, person, jsonSerializerOptions);
|
||||||
|
writer.WriteEndObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Serializes the properties of <see cref="Person" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"></param>
|
||||||
|
/// <param name="person"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public void WriteProperties(Utf8JsonWriter writer, Person person, JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
if (person.FirstNameOption.IsSet && person.FirstName == null)
|
||||||
|
throw new ArgumentNullException(nameof(person.FirstName), "Property is required for class Person.");
|
||||||
|
|
||||||
|
if (person.LastNameOption.IsSet && person.LastName == null)
|
||||||
|
throw new ArgumentNullException(nameof(person.LastName), "Property is required for class Person.");
|
||||||
|
|
||||||
|
if (person.FirstNameOption.IsSet)
|
||||||
|
writer.WriteString("firstName", person.FirstName);
|
||||||
|
|
||||||
|
if (person.LastNameOption.IsSet)
|
||||||
|
writer.WriteString("lastName", person.LastName);
|
||||||
|
|
||||||
|
writer.WriteString("$_type", person.Type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> <!-- setting GenerateAssemblyInfo to false causes this bug https://github.com/dotnet/project-system/issues/3934 -->
|
||||||
|
<TargetFramework>net48</TargetFramework>
|
||||||
|
<AssemblyName>Org.OpenAPITools</AssemblyName>
|
||||||
|
<PackageId>Org.OpenAPITools</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>Org.OpenAPITools</RootNamespace>
|
||||||
|
<Version>1.0.0</Version>
|
||||||
|
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\Org.OpenAPITools.xml</DocumentationFile>
|
||||||
|
<RepositoryUrl>https://github.com/GIT_USER_ID/GIT_REPO_ID.git</RepositoryUrl>
|
||||||
|
<RepositoryType>git</RepositoryType>
|
||||||
|
<PackageReleaseNotes>Minor update</PackageReleaseNotes>
|
||||||
|
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CompareNETObjects" Version="4.83.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.0" />
|
||||||
|
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />
|
||||||
|
<Reference Include="System.Web" />
|
||||||
|
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,177 @@
|
|||||||
|
# Created with Openapi Generator
|
||||||
|
|
||||||
|
<a id="cli"></a>
|
||||||
|
## Run the following powershell command to generate the library
|
||||||
|
|
||||||
|
```ps1
|
||||||
|
$properties = @(
|
||||||
|
'apiName=Api',
|
||||||
|
'targetFramework=net48',
|
||||||
|
'validatable=true',
|
||||||
|
'nullableReferenceTypes=false',
|
||||||
|
'hideGenerationTimestamp=true',
|
||||||
|
'packageVersion=1.0.0',
|
||||||
|
'packageAuthors=OpenAPI',
|
||||||
|
'packageCompany=OpenAPI',
|
||||||
|
'packageCopyright=No Copyright',
|
||||||
|
'packageDescription=A library generated from a OpenAPI doc',
|
||||||
|
'packageName=Org.OpenAPITools',
|
||||||
|
'packageTags=',
|
||||||
|
'packageTitle=OpenAPI Library'
|
||||||
|
) -join ","
|
||||||
|
|
||||||
|
$global = @(
|
||||||
|
'apiDocs=true',
|
||||||
|
'modelDocs=true',
|
||||||
|
'apiTests=true',
|
||||||
|
'modelTests=true'
|
||||||
|
) -join ","
|
||||||
|
|
||||||
|
java -jar "<path>/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar" generate `
|
||||||
|
-g csharp-netcore `
|
||||||
|
-i <your-swagger-file>.yaml `
|
||||||
|
-o <your-output-folder> `
|
||||||
|
--library generichost `
|
||||||
|
--additional-properties $properties `
|
||||||
|
--global-property $global `
|
||||||
|
--git-host "github.com" `
|
||||||
|
--git-repo-id "GIT_REPO_ID" `
|
||||||
|
--git-user-id "GIT_USER_ID" `
|
||||||
|
--release-note "Minor update"
|
||||||
|
# -t templates
|
||||||
|
```
|
||||||
|
|
||||||
|
<a id="usage"></a>
|
||||||
|
## Using the library in your project
|
||||||
|
|
||||||
|
```cs
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Org.OpenAPITools.Api;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
|
||||||
|
namespace YourProject
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static async Task Main(string[] args)
|
||||||
|
{
|
||||||
|
var host = CreateHostBuilder(args).Build();
|
||||||
|
var api = host.Services.GetRequiredService<IDefaultApi>();
|
||||||
|
ListApiResponse apiResponse = await api.ListAsync("todo");
|
||||||
|
Person model = apiResponse.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
|
||||||
|
.ConfigureApi((context, options) =>
|
||||||
|
{
|
||||||
|
options.ConfigureJsonOptions((jsonOptions) =>
|
||||||
|
{
|
||||||
|
// your custom converters if any
|
||||||
|
});
|
||||||
|
|
||||||
|
options.AddApiHttpClients(builder: builder => builder
|
||||||
|
.AddRetryPolicy(2)
|
||||||
|
.AddTimeoutPolicy(TimeSpan.FromSeconds(5))
|
||||||
|
.AddCircuitBreakerPolicy(10, TimeSpan.FromSeconds(30))
|
||||||
|
// add whatever middleware you prefer
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
<a id="questions"></a>
|
||||||
|
## Questions
|
||||||
|
|
||||||
|
- What about HttpRequest failures and retries?
|
||||||
|
If supportsRetry is enabled, you can configure Polly in the ConfigureClients method.
|
||||||
|
- How are tokens used?
|
||||||
|
Tokens are provided by a TokenProvider class. The default is RateLimitProvider which will perform client side rate limiting.
|
||||||
|
Other providers can be used with the UseProvider method.
|
||||||
|
- Does an HttpRequest throw an error when the server response is not Ok?
|
||||||
|
It depends how you made the request. If the return type is ApiResponse<T> no error will be thrown, though the Content property will be null.
|
||||||
|
StatusCode and ReasonPhrase will contain information about the error.
|
||||||
|
If the return type is T, then it will throw. If the return type is TOrDefault, it will return null.
|
||||||
|
- How do I validate requests and process responses?
|
||||||
|
Use the provided On and After methods in the Api class from the namespace Org.OpenAPITools.Rest.DefaultApi.
|
||||||
|
Or provide your own class by using the generic ConfigureApi method.
|
||||||
|
|
||||||
|
<a id="dependencies"></a>
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
- [Microsoft.Extensions.Hosting](https://www.nuget.org/packages/Microsoft.Extensions.Hosting/) - 5.0.0 or later
|
||||||
|
- [Microsoft.Extensions.Http](https://www.nuget.org/packages/Microsoft.Extensions.Http/) - 5.0.0 or later
|
||||||
|
- [Microsoft.Extensions.Http.Polly](https://www.nuget.org/packages/Microsoft.Extensions.Http.Polly/) - 5.0.1 or later
|
||||||
|
- [CompareNETObjects](https://www.nuget.org/packages/CompareNETObjects) - 4.61.0 or later
|
||||||
|
- [System.ComponentModel.Annotations](https://www.nuget.org/packages/System.ComponentModel.Annotations) - 4.7.0 or later
|
||||||
|
|
||||||
|
<a id="documentation-for-authorization"></a>
|
||||||
|
## Documentation for Authorization
|
||||||
|
|
||||||
|
Endpoints do not require authorization.
|
||||||
|
|
||||||
|
|
||||||
|
## Build
|
||||||
|
- SDK version: 1.0.0
|
||||||
|
- Generator version: 7.7.0-SNAPSHOT
|
||||||
|
- Build package: org.openapitools.codegen.languages.CSharpClientCodegen
|
||||||
|
|
||||||
|
## Api Information
|
||||||
|
- appName: Example
|
||||||
|
- appVersion: 1.0.0
|
||||||
|
- appDescription: No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
|
||||||
|
## [OpenApi Global properties](https://openapi-generator.tech/docs/globals)
|
||||||
|
- generateAliasAsModel:
|
||||||
|
- supportingFiles:
|
||||||
|
- models: omitted for brevity
|
||||||
|
- apis: omitted for brevity
|
||||||
|
- apiDocs: true
|
||||||
|
- modelDocs: true
|
||||||
|
- apiTests: true
|
||||||
|
- modelTests: true
|
||||||
|
|
||||||
|
## [OpenApi Generator Parameters](https://openapi-generator.tech/docs/generators/csharp-netcore)
|
||||||
|
- allowUnicodeIdentifiers:
|
||||||
|
- apiName: Api
|
||||||
|
- caseInsensitiveResponseHeaders:
|
||||||
|
- conditionalSerialization: false
|
||||||
|
- disallowAdditionalPropertiesIfNotPresent: false
|
||||||
|
- gitHost: github.com
|
||||||
|
- gitRepoId: GIT_REPO_ID
|
||||||
|
- gitUserId: GIT_USER_ID
|
||||||
|
- hideGenerationTimestamp: true
|
||||||
|
- interfacePrefix: I
|
||||||
|
- library: generichost
|
||||||
|
- licenseId:
|
||||||
|
- modelPropertyNaming:
|
||||||
|
- netCoreProjectFile: false
|
||||||
|
- nonPublicApi: false
|
||||||
|
- nullableReferenceTypes: false
|
||||||
|
- optionalAssemblyInfo:
|
||||||
|
- optionalEmitDefaultValues: false
|
||||||
|
- optionalMethodArgument: true
|
||||||
|
- optionalProjectFile:
|
||||||
|
- packageAuthors: OpenAPI
|
||||||
|
- packageCompany: OpenAPI
|
||||||
|
- packageCopyright: No Copyright
|
||||||
|
- packageDescription: A library generated from a OpenAPI doc
|
||||||
|
- packageGuid: {321C8C3F-0156-40C1-AE42-D59761FB9B6C}
|
||||||
|
- packageName: Org.OpenAPITools
|
||||||
|
- packageTags:
|
||||||
|
- packageTitle: OpenAPI Library
|
||||||
|
- packageVersion: 1.0.0
|
||||||
|
- releaseNote: Minor update
|
||||||
|
- returnICollection: false
|
||||||
|
- sortParamsByRequiredFlag:
|
||||||
|
- sourceFolder: src
|
||||||
|
- targetFramework: net48
|
||||||
|
- useCollection: false
|
||||||
|
- useDateTimeOffset: false
|
||||||
|
- useOneOfDiscriminatorLookup: false
|
||||||
|
- validatable: true
|
||||||
|
|
||||||
|
This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
|
362
samples/client/petstore/csharp/generichost/net4.8/AnyOf/.gitignore
vendored
Normal file
362
samples/client/petstore/csharp/generichost/net4.8/AnyOf/.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,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,40 @@
|
|||||||
|
.gitignore
|
||||||
|
Org.OpenAPITools.sln
|
||||||
|
README.md
|
||||||
|
api/openapi.yaml
|
||||||
|
appveyor.yml
|
||||||
|
docs/apis/DefaultApi.md
|
||||||
|
docs/models/Apple.md
|
||||||
|
docs/models/Banana.md
|
||||||
|
docs/models/Fruit.md
|
||||||
|
docs/scripts/git_push.ps1
|
||||||
|
docs/scripts/git_push.sh
|
||||||
|
src/Org.OpenAPITools.Test/Api/DependencyInjectionTests.cs
|
||||||
|
src/Org.OpenAPITools.Test/Org.OpenAPITools.Test.csproj
|
||||||
|
src/Org.OpenAPITools.Test/README.md
|
||||||
|
src/Org.OpenAPITools/Api/DefaultApi.cs
|
||||||
|
src/Org.OpenAPITools/Api/IApi.cs
|
||||||
|
src/Org.OpenAPITools/Client/ApiException.cs
|
||||||
|
src/Org.OpenAPITools/Client/ApiFactory.cs
|
||||||
|
src/Org.OpenAPITools/Client/ApiResponseEventArgs.cs
|
||||||
|
src/Org.OpenAPITools/Client/ApiResponse`1.cs
|
||||||
|
src/Org.OpenAPITools/Client/ClientUtils.cs
|
||||||
|
src/Org.OpenAPITools/Client/CookieContainer.cs
|
||||||
|
src/Org.OpenAPITools/Client/DateTimeJsonConverter.cs
|
||||||
|
src/Org.OpenAPITools/Client/DateTimeNullableJsonConverter.cs
|
||||||
|
src/Org.OpenAPITools/Client/ExceptionEventArgs.cs
|
||||||
|
src/Org.OpenAPITools/Client/HostConfiguration.cs
|
||||||
|
src/Org.OpenAPITools/Client/JsonSerializerOptionsProvider.cs
|
||||||
|
src/Org.OpenAPITools/Client/Option.cs
|
||||||
|
src/Org.OpenAPITools/Client/RateLimitProvider`1.cs
|
||||||
|
src/Org.OpenAPITools/Client/TokenBase.cs
|
||||||
|
src/Org.OpenAPITools/Client/TokenContainer`1.cs
|
||||||
|
src/Org.OpenAPITools/Client/TokenProvider`1.cs
|
||||||
|
src/Org.OpenAPITools/Extensions/IHostBuilderExtensions.cs
|
||||||
|
src/Org.OpenAPITools/Extensions/IHttpClientBuilderExtensions.cs
|
||||||
|
src/Org.OpenAPITools/Extensions/IServiceCollectionExtensions.cs
|
||||||
|
src/Org.OpenAPITools/Model/Apple.cs
|
||||||
|
src/Org.OpenAPITools/Model/Banana.cs
|
||||||
|
src/Org.OpenAPITools/Model/Fruit.cs
|
||||||
|
src/Org.OpenAPITools/Org.OpenAPITools.csproj
|
||||||
|
src/Org.OpenAPITools/README.md
|
@ -0,0 +1 @@
|
|||||||
|
7.7.0-SNAPSHOT
|
@ -0,0 +1,27 @@
|
|||||||
|
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}") = "Org.OpenAPITools", "src\Org.OpenAPITools\Org.OpenAPITools.csproj", "{321C8C3F-0156-40C1-AE42-D59761FB9B6C}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Org.OpenAPITools.Test", "src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{321C8C3F-0156-40C1-AE42-D59761FB9B6C}.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 @@
|
|||||||
|
# Created with Openapi Generator
|
@ -0,0 +1,42 @@
|
|||||||
|
openapi: 3.0.1
|
||||||
|
info:
|
||||||
|
title: fruity
|
||||||
|
version: 0.0.1
|
||||||
|
servers:
|
||||||
|
- url: /
|
||||||
|
paths:
|
||||||
|
/:
|
||||||
|
get:
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/fruit'
|
||||||
|
description: desc
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
fruit:
|
||||||
|
anyOf:
|
||||||
|
- $ref: '#/components/schemas/apple'
|
||||||
|
- $ref: '#/components/schemas/banana'
|
||||||
|
example:
|
||||||
|
color: color
|
||||||
|
properties:
|
||||||
|
color:
|
||||||
|
type: string
|
||||||
|
title: fruit
|
||||||
|
type: object
|
||||||
|
apple:
|
||||||
|
properties:
|
||||||
|
kind:
|
||||||
|
type: string
|
||||||
|
title: apple
|
||||||
|
type: object
|
||||||
|
banana:
|
||||||
|
properties:
|
||||||
|
count:
|
||||||
|
type: number
|
||||||
|
title: banana
|
||||||
|
type: object
|
||||||
|
|
@ -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\Org.OpenAPITools\Org.OpenAPITools.csproj -o ../../output -c Release --no-build
|
@ -0,0 +1,90 @@
|
|||||||
|
# Org.OpenAPITools.Api.DefaultApi
|
||||||
|
|
||||||
|
All URIs are relative to *http://localhost*
|
||||||
|
|
||||||
|
| Method | HTTP request | Description |
|
||||||
|
|--------|--------------|-------------|
|
||||||
|
| [**RootGet**](DefaultApi.md#rootget) | **GET** / | |
|
||||||
|
|
||||||
|
<a id="rootget"></a>
|
||||||
|
# **RootGet**
|
||||||
|
> Fruit RootGet ()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Example
|
||||||
|
```csharp
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Org.OpenAPITools.Api;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
|
||||||
|
namespace Example
|
||||||
|
{
|
||||||
|
public class RootGetExample
|
||||||
|
{
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
Configuration config = new Configuration();
|
||||||
|
config.BasePath = "http://localhost";
|
||||||
|
var apiInstance = new DefaultApi(config);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Fruit result = apiInstance.RootGet();
|
||||||
|
Debug.WriteLine(result);
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
Debug.Print("Exception when calling DefaultApi.RootGet: " + e.Message);
|
||||||
|
Debug.Print("Status Code: " + e.ErrorCode);
|
||||||
|
Debug.Print(e.StackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Using the RootGetWithHttpInfo variant
|
||||||
|
This returns an ApiResponse object which contains the response data, status code and headers.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ApiResponse<Fruit> response = apiInstance.RootGetWithHttpInfo();
|
||||||
|
Debug.Write("Status Code: " + response.StatusCode);
|
||||||
|
Debug.Write("Response Headers: " + response.Headers);
|
||||||
|
Debug.Write("Response Body: " + response.Data);
|
||||||
|
}
|
||||||
|
catch (ApiException e)
|
||||||
|
{
|
||||||
|
Debug.Print("Exception when calling DefaultApi.RootGetWithHttpInfo: " + e.Message);
|
||||||
|
Debug.Print("Status Code: " + e.ErrorCode);
|
||||||
|
Debug.Print(e.StackTrace);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
This endpoint does not need any parameter.
|
||||||
|
### Return type
|
||||||
|
|
||||||
|
[**Fruit**](Fruit.md)
|
||||||
|
|
||||||
|
### Authorization
|
||||||
|
|
||||||
|
No authorization required
|
||||||
|
|
||||||
|
### HTTP request headers
|
||||||
|
|
||||||
|
- **Content-Type**: Not defined
|
||||||
|
- **Accept**: application/json
|
||||||
|
|
||||||
|
|
||||||
|
### HTTP response details
|
||||||
|
| Status code | Description | Response headers |
|
||||||
|
|-------------|-------------|------------------|
|
||||||
|
| **200** | desc | - |
|
||||||
|
|
||||||
|
[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md)
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
# Org.OpenAPITools.Model.Apple
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**Kind** | **string** | | [optional]
|
||||||
|
|
||||||
|
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
# Org.OpenAPITools.Model.Banana
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**Count** | **decimal** | | [optional]
|
||||||
|
|
||||||
|
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
# Org.OpenAPITools.Model.Fruit
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**Color** | **string** | | [optional]
|
||||||
|
|
||||||
|
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
|
||||||
|
|
@ -0,0 +1,75 @@
|
|||||||
|
param(
|
||||||
|
[Parameter()][Alias("g")][String]$GitHost = "github.com",
|
||||||
|
[Parameter()][Alias("u")][String]$GitUserId = "GIT_USER_ID",
|
||||||
|
[Parameter()][Alias("r")][String]$GitRepoId = "GIT_REPO_ID",
|
||||||
|
[Parameter()][Alias("m")][string]$Message = "Minor update",
|
||||||
|
[Parameter()][Alias("h")][switch]$Help
|
||||||
|
)
|
||||||
|
|
||||||
|
function Publish-ToGitHost{
|
||||||
|
if ([string]::IsNullOrWhiteSpace($Message) -or $Message -eq "Minor update"){
|
||||||
|
# it seems unlikely that we would want our git commit message to be the default, so lets prompt the user
|
||||||
|
$Message = Read-Host -Prompt "Please provide a commit message or press enter"
|
||||||
|
$Message = if([string]::IsNullOrWhiteSpace($Message)) { "no message provided" } else { $Message }
|
||||||
|
}
|
||||||
|
|
||||||
|
git init
|
||||||
|
git add .
|
||||||
|
git commit -am "${Message}"
|
||||||
|
$branchName=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
$gitRemote=$(git remote)
|
||||||
|
|
||||||
|
if([string]::IsNullOrWhiteSpace($gitRemote)){
|
||||||
|
git remote add origin https://${GitHost}/${GitUserId}/${GitRepoId}.git
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "Pulling from https://${GitHost}/${GitUserId}/${GitRepoId}.git"
|
||||||
|
git pull origin $branchName --ff-only
|
||||||
|
|
||||||
|
if ($LastExitCode -ne 0){
|
||||||
|
if (${GitHost} -eq "github.com"){
|
||||||
|
Write-Output "The ${GitRepoId} repository may not exist yet. Creating it now with the GitHub CLI."
|
||||||
|
gh auth login --hostname github.com --web
|
||||||
|
gh repo create $GitRepoId --private
|
||||||
|
# sleep 2 seconds to ensure git finishes creation of the repo
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw "There was an issue pulling the origin branch. The remote repository may not exist yet."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "Pushing to https://${GitHost}/${GitUserId}/${GitRepoId}.git"
|
||||||
|
git push origin $branchName
|
||||||
|
}
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
Set-StrictMode -Version 3.0
|
||||||
|
|
||||||
|
if ($Help){
|
||||||
|
Write-Output "
|
||||||
|
This script will initialize a git repository, then add and commit all files.
|
||||||
|
The local repository will then be pushed to your preferred git provider.
|
||||||
|
If the remote repository does not exist yet and you are using GitHub,
|
||||||
|
the repository will be created for you provided you have the GitHub CLI installed.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
-g | -GitHost -> ex: github.com
|
||||||
|
-m | -Message -> the git commit message
|
||||||
|
-r | -GitRepoId -> the name of the repository
|
||||||
|
-u | -GitUserId -> your user id
|
||||||
|
"
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$rootPath=Resolve-Path -Path $PSScriptRoot/../..
|
||||||
|
|
||||||
|
Push-Location $rootPath
|
||||||
|
|
||||||
|
try {
|
||||||
|
Publish-ToGitHost $GitHost $GitUserId $GitRepoId $Message
|
||||||
|
}
|
||||||
|
finally{
|
||||||
|
Pop-Location
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
#!/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_USER_ID}
|
||||||
|
git_repo_id=${2:-GIT_REPO_ID}
|
||||||
|
release_note=${3:-Minor update}
|
||||||
|
git_host=${4:-github.com}
|
||||||
|
|
||||||
|
starting_directory=$(pwd)
|
||||||
|
script_root="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||||
|
cd $script_root
|
||||||
|
cd ../..
|
||||||
|
|
||||||
|
if [ "$release_note" = "" ] || [ "$release_note" = "Minor update" ]; then
|
||||||
|
# it seems unlikely that we would want our git commit message to be the default, so lets prompt the user
|
||||||
|
echo "Please provide a commit message or press enter"
|
||||||
|
read user_input
|
||||||
|
release_note=$user_input
|
||||||
|
if [ "$release_note" = "" ]; then
|
||||||
|
release_note="no message provided"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
git init
|
||||||
|
git add .
|
||||||
|
git commit -am "$release_note"
|
||||||
|
branch_name=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
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
|
||||||
|
|
||||||
|
echo "[INFO] Pulling from https://${git_host}/${git_user_id}/${git_repo_id}.git"
|
||||||
|
git pull origin $branch_name --ff-only
|
||||||
|
|
||||||
|
echo "[INFO] Pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
|
||||||
|
git push origin $branch_name
|
||||||
|
|
||||||
|
cd $starting_directory
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using Org.OpenAPITools.Extensions;
|
||||||
|
|
||||||
|
|
||||||
|
/* *********************************************************************************
|
||||||
|
* Follow these manual steps to construct tests.
|
||||||
|
* This file will not be overwritten.
|
||||||
|
* *********************************************************************************
|
||||||
|
* 1. Navigate to ApiTests.Base.cs and ensure any tokens are being created correctly.
|
||||||
|
* Take care not to commit credentials to any repository.
|
||||||
|
*
|
||||||
|
* 2. Mocking is coordinated by ApiTestsBase#AddApiHttpClients.
|
||||||
|
* To mock the client, use the generic AddApiHttpClients.
|
||||||
|
* To mock the server, change the client's BaseAddress.
|
||||||
|
*
|
||||||
|
* 3. Locate the test you want below
|
||||||
|
* - remove the skip property from the Fact attribute
|
||||||
|
* - set the value of any variables if necessary
|
||||||
|
*
|
||||||
|
* 4. Run the tests and ensure they work.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for API tests
|
||||||
|
/// </summary>
|
||||||
|
public class ApiTestsBase
|
||||||
|
{
|
||||||
|
protected readonly IHost _host;
|
||||||
|
|
||||||
|
public ApiTestsBase(string[] args)
|
||||||
|
{
|
||||||
|
_host = CreateHostBuilder(args).Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
|
||||||
|
.ConfigureApi((context, services, options) =>
|
||||||
|
{
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xunit;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Org.OpenAPITools.Api;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
|
||||||
|
|
||||||
|
/* *********************************************************************************
|
||||||
|
* Follow these manual steps to construct tests.
|
||||||
|
* This file will not be overwritten.
|
||||||
|
* *********************************************************************************
|
||||||
|
* 1. Navigate to ApiTests.Base.cs and ensure any tokens are being created correctly.
|
||||||
|
* Take care not to commit credentials to any repository.
|
||||||
|
*
|
||||||
|
* 2. Mocking is coordinated by ApiTestsBase#AddApiHttpClients.
|
||||||
|
* To mock the client, use the generic AddApiHttpClients.
|
||||||
|
* To mock the server, change the client's BaseAddress.
|
||||||
|
*
|
||||||
|
* 3. Locate the test you want below
|
||||||
|
* - remove the skip property from the Fact attribute
|
||||||
|
* - set the value of any variables if necessary
|
||||||
|
*
|
||||||
|
* 4. Run the tests and ensure they work.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class for testing DefaultApi
|
||||||
|
/// </summary>
|
||||||
|
public sealed class DefaultApiTests : ApiTestsBase
|
||||||
|
{
|
||||||
|
private readonly IDefaultApi _instance;
|
||||||
|
|
||||||
|
public DefaultApiTests(): base(Array.Empty<string>())
|
||||||
|
{
|
||||||
|
_instance = _host.Services.GetRequiredService<IDefaultApi>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test RootGet
|
||||||
|
/// </summary>
|
||||||
|
[Fact (Skip = "not implemented")]
|
||||||
|
public async Task RootGetAsyncTest()
|
||||||
|
{
|
||||||
|
var response = await _instance.RootGetAsync();
|
||||||
|
var model = response.Ok();
|
||||||
|
Assert.IsType<Fruit>(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using Org.OpenAPITools.Api;
|
||||||
|
using Org.OpenAPITools.Extensions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the dependency injection.
|
||||||
|
/// </summary>
|
||||||
|
public class DependencyInjectionTest
|
||||||
|
{
|
||||||
|
private readonly IHost _hostUsingConfigureWithoutAClient =
|
||||||
|
Host.CreateDefaultBuilder(Array.Empty<string>()).ConfigureApi((context, services, options) =>
|
||||||
|
{
|
||||||
|
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
private readonly IHost _hostUsingConfigureWithAClient =
|
||||||
|
Host.CreateDefaultBuilder(Array.Empty<string>()).ConfigureApi((context, services, options) =>
|
||||||
|
{
|
||||||
|
|
||||||
|
options.AddApiHttpClients(client => client.BaseAddress = new Uri(ClientUtils.BASE_ADDRESS));
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
private readonly IHost _hostUsingAddWithoutAClient =
|
||||||
|
Host.CreateDefaultBuilder(Array.Empty<string>()).ConfigureServices((host, services) =>
|
||||||
|
{
|
||||||
|
services.AddApi(options =>
|
||||||
|
{
|
||||||
|
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
private readonly IHost _hostUsingAddWithAClient =
|
||||||
|
Host.CreateDefaultBuilder(Array.Empty<string>()).ConfigureServices((host, services) =>
|
||||||
|
{
|
||||||
|
services.AddApi(options =>
|
||||||
|
{
|
||||||
|
|
||||||
|
options.AddApiHttpClients(client => client.BaseAddress = new Uri(ClientUtils.BASE_ADDRESS));
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test dependency injection when using the configure method
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void ConfigureApiWithAClientTest()
|
||||||
|
{
|
||||||
|
var defaultApi = _hostUsingConfigureWithAClient.Services.GetRequiredService<IDefaultApi>();
|
||||||
|
Assert.True(defaultApi.HttpClient.BaseAddress != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test dependency injection when using the configure method
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void ConfigureApiWithoutAClientTest()
|
||||||
|
{
|
||||||
|
var defaultApi = _hostUsingConfigureWithoutAClient.Services.GetRequiredService<IDefaultApi>();
|
||||||
|
Assert.True(defaultApi.HttpClient.BaseAddress != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test dependency injection when using the add method
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void AddApiWithAClientTest()
|
||||||
|
{
|
||||||
|
var defaultApi = _hostUsingAddWithAClient.Services.GetRequiredService<IDefaultApi>();
|
||||||
|
Assert.True(defaultApi.HttpClient.BaseAddress != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test dependency injection when using the add method
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void AddApiWithoutAClientTest()
|
||||||
|
{
|
||||||
|
var defaultApi = _hostUsingAddWithoutAClient.Services.GetRequiredService<IDefaultApi>();
|
||||||
|
Assert.True(defaultApi.HttpClient.BaseAddress != null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Model
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class for testing Apple
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
/// Please update the test case below to test the model.
|
||||||
|
/// </remarks>
|
||||||
|
public class AppleTests : IDisposable
|
||||||
|
{
|
||||||
|
// TODO uncomment below to declare an instance variable for Apple
|
||||||
|
//private Apple instance;
|
||||||
|
|
||||||
|
public AppleTests()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to create an instance of Apple
|
||||||
|
//instance = new Apple();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
// Cleanup when everything is done.
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test an instance of Apple
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void AppleInstanceTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test "IsType" Apple
|
||||||
|
//Assert.IsType<Apple>(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the property 'Kind'
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void KindTest()
|
||||||
|
{
|
||||||
|
// TODO unit test for the property 'Kind'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Model
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class for testing Banana
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
/// Please update the test case below to test the model.
|
||||||
|
/// </remarks>
|
||||||
|
public class BananaTests : IDisposable
|
||||||
|
{
|
||||||
|
// TODO uncomment below to declare an instance variable for Banana
|
||||||
|
//private Banana instance;
|
||||||
|
|
||||||
|
public BananaTests()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to create an instance of Banana
|
||||||
|
//instance = new Banana();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
// Cleanup when everything is done.
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test an instance of Banana
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void BananaInstanceTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test "IsType" Banana
|
||||||
|
//Assert.IsType<Banana>(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the property 'Count'
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void CountTest()
|
||||||
|
{
|
||||||
|
// TODO unit test for the property 'Count'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Test.Model
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class for testing Fruit
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
/// Please update the test case below to test the model.
|
||||||
|
/// </remarks>
|
||||||
|
public class FruitTests : IDisposable
|
||||||
|
{
|
||||||
|
// TODO uncomment below to declare an instance variable for Fruit
|
||||||
|
//private Fruit instance;
|
||||||
|
|
||||||
|
public FruitTests()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to create an instance of Fruit
|
||||||
|
//instance = new Fruit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
// Cleanup when everything is done.
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test an instance of Fruit
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void FruitInstanceTest()
|
||||||
|
{
|
||||||
|
// TODO uncomment below to test "IsType" Fruit
|
||||||
|
//Assert.IsType<Fruit>(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the property 'Color'
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void ColorTest()
|
||||||
|
{
|
||||||
|
// TODO unit test for the property 'Color'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<AssemblyName>Org.OpenAPITools.Test</AssemblyName>
|
||||||
|
<RootNamespace>Org.OpenAPITools.Test</RootNamespace>
|
||||||
|
<TargetFramework>net48</TargetFramework>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.7.0" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Org.OpenAPITools\Org.OpenAPITools.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
@ -0,0 +1,329 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
|
/// This class is registered as transient.
|
||||||
|
/// </summary>
|
||||||
|
public interface IDefaultApi : IApi
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The class containing the events
|
||||||
|
/// </summary>
|
||||||
|
DefaultApiEvents Events { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns><see cref="Task"/><<see cref="IRootGetApiResponse"/>></returns>
|
||||||
|
Task<IRootGetApiResponse> RootGetAsync(System.Threading.CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns><see cref="Task"/><<see cref="IRootGetApiResponse"/>></returns>
|
||||||
|
Task<IRootGetApiResponse> RootGetOrDefaultAsync(System.Threading.CancellationToken cancellationToken = default);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="IRootGetApiResponse"/>
|
||||||
|
/// </summary>
|
||||||
|
public interface IRootGetApiResponse : Org.OpenAPITools.Client.IApiResponse, IOk<Org.OpenAPITools.Model.Fruit>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the response is 200 Ok
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool IsOk { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
|
/// </summary>
|
||||||
|
public class DefaultApiEvents
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The event raised after the server response
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<ApiResponseEventArgs> OnRootGet;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The event raised after an error querying the server
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<ExceptionEventArgs> OnErrorRootGet;
|
||||||
|
|
||||||
|
internal void ExecuteOnRootGet(DefaultApi.RootGetApiResponse apiResponse)
|
||||||
|
{
|
||||||
|
OnRootGet?.Invoke(this, new ApiResponseEventArgs(apiResponse));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void ExecuteOnErrorRootGet(Exception exception)
|
||||||
|
{
|
||||||
|
OnErrorRootGet?.Invoke(this, new ExceptionEventArgs(exception));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a collection of functions to interact with the API endpoints
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class DefaultApi : IDefaultApi
|
||||||
|
{
|
||||||
|
private JsonSerializerOptions _jsonSerializerOptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The logger factory
|
||||||
|
/// </summary>
|
||||||
|
public ILoggerFactory LoggerFactory { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The logger
|
||||||
|
/// </summary>
|
||||||
|
public ILogger<DefaultApi> Logger { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The HttpClient
|
||||||
|
/// </summary>
|
||||||
|
public HttpClient HttpClient { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The class containing the events
|
||||||
|
/// </summary>
|
||||||
|
public DefaultApiEvents Events { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="DefaultApi"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public DefaultApi(ILogger<DefaultApi> logger, ILoggerFactory loggerFactory, HttpClient httpClient, JsonSerializerOptionsProvider jsonSerializerOptionsProvider, DefaultApiEvents defaultApiEvents)
|
||||||
|
{
|
||||||
|
_jsonSerializerOptions = jsonSerializerOptionsProvider.Options;
|
||||||
|
LoggerFactory = loggerFactory;
|
||||||
|
Logger = LoggerFactory.CreateLogger<DefaultApi>();
|
||||||
|
HttpClient = httpClient;
|
||||||
|
Events = defaultApiEvents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Processes the server response
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiResponseLocalVar"></param>
|
||||||
|
private void AfterRootGetDefaultImplementation(IRootGetApiResponse apiResponseLocalVar)
|
||||||
|
{
|
||||||
|
bool suppressDefaultLog = false;
|
||||||
|
AfterRootGet(ref suppressDefaultLog, apiResponseLocalVar);
|
||||||
|
if (!suppressDefaultLog)
|
||||||
|
Logger.LogInformation("{0,-9} | {1} | {3}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Processes the server response
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="suppressDefaultLog"></param>
|
||||||
|
/// <param name="apiResponseLocalVar"></param>
|
||||||
|
partial void AfterRootGet(ref bool suppressDefaultLog, IRootGetApiResponse apiResponseLocalVar);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logs exceptions that occur while retrieving the server response
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exception"></param>
|
||||||
|
/// <param name="pathFormat"></param>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
private void OnErrorRootGetDefaultImplementation(Exception exception, string pathFormat, string path)
|
||||||
|
{
|
||||||
|
bool suppressDefaultLog = false;
|
||||||
|
OnErrorRootGet(ref suppressDefaultLog, exception, pathFormat, path);
|
||||||
|
if (!suppressDefaultLog)
|
||||||
|
Logger.LogError(exception, "An error occurred while sending the request to the server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A partial method that gives developers a way to provide customized exception handling
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="suppressDefaultLog"></param>
|
||||||
|
/// <param name="exception"></param>
|
||||||
|
/// <param name="pathFormat"></param>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
partial void OnErrorRootGet(ref bool suppressDefaultLog, Exception exception, string pathFormat, string path);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns><see cref="Task"/><<see cref="IRootGetApiResponse"/>></returns>
|
||||||
|
public async Task<IRootGetApiResponse> RootGetOrDefaultAsync(System.Threading.CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await RootGetAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
|
||||||
|
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
|
||||||
|
/// <returns><see cref="Task"/><<see cref="IRootGetApiResponse"/>></returns>
|
||||||
|
public async Task<IRootGetApiResponse> RootGetAsync(System.Threading.CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
UriBuilder uriBuilderLocalVar = new UriBuilder();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage())
|
||||||
|
{
|
||||||
|
uriBuilderLocalVar.Host = HttpClient.BaseAddress.Host;
|
||||||
|
uriBuilderLocalVar.Port = HttpClient.BaseAddress.Port;
|
||||||
|
uriBuilderLocalVar.Scheme = HttpClient.BaseAddress.Scheme;
|
||||||
|
uriBuilderLocalVar.Path = ClientUtils.CONTEXT_PATH + "/";
|
||||||
|
|
||||||
|
httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;
|
||||||
|
|
||||||
|
string[] acceptLocalVars = new string[] {
|
||||||
|
"application/json"
|
||||||
|
};
|
||||||
|
|
||||||
|
string acceptLocalVar = ClientUtils.SelectHeaderAccept(acceptLocalVars);
|
||||||
|
|
||||||
|
if (acceptLocalVar != null)
|
||||||
|
httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptLocalVar));
|
||||||
|
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
|
||||||
|
|
||||||
|
DateTime requestedAtLocalVar = DateTime.UtcNow;
|
||||||
|
|
||||||
|
using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
|
ILogger<RootGetApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<RootGetApiResponse>();
|
||||||
|
|
||||||
|
RootGetApiResponse apiResponseLocalVar = new RootGetApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/", requestedAtLocalVar, _jsonSerializerOptions);
|
||||||
|
|
||||||
|
AfterRootGetDefaultImplementation(apiResponseLocalVar);
|
||||||
|
|
||||||
|
Events.ExecuteOnRootGet(apiResponseLocalVar);
|
||||||
|
|
||||||
|
return apiResponseLocalVar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
OnErrorRootGetDefaultImplementation(e, "/", uriBuilderLocalVar.Path);
|
||||||
|
Events.ExecuteOnErrorRootGet(e);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="RootGetApiResponse"/>
|
||||||
|
/// </summary>
|
||||||
|
public partial class RootGetApiResponse : Org.OpenAPITools.Client.ApiResponse, IRootGetApiResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The logger
|
||||||
|
/// </summary>
|
||||||
|
public ILogger<RootGetApiResponse> Logger { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="RootGetApiResponse"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logger"></param>
|
||||||
|
/// <param name="httpRequestMessage"></param>
|
||||||
|
/// <param name="httpResponseMessage"></param>
|
||||||
|
/// <param name="rawContent"></param>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <param name="requestedAt"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
public RootGetApiResponse(ILogger<RootGetApiResponse> logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
Logger = logger;
|
||||||
|
OnCreated(httpRequestMessage, httpResponseMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnCreated(System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the response is 200 Ok
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool IsOk => 200 == (int)StatusCode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the response if the response is 200 Ok
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Org.OpenAPITools.Model.Fruit Ok()
|
||||||
|
{
|
||||||
|
// This logic may be modified with the AsModel.mustache template
|
||||||
|
return IsOk
|
||||||
|
? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.Fruit>(RawContent, _jsonSerializerOptions)
|
||||||
|
: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the response is 200 Ok and the deserialized response is not null
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="result"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool TryOk(out Org.OpenAPITools.Model.Fruit result)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = Ok();
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
OnDeserializationErrorDefaultImplementation(e, (HttpStatusCode)200);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode)
|
||||||
|
{
|
||||||
|
bool suppressDefaultLog = false;
|
||||||
|
OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode);
|
||||||
|
if (!suppressDefaultLog)
|
||||||
|
Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using System.Net.Http;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Any Api client
|
||||||
|
/// </summary>
|
||||||
|
public interface IApi
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The HttpClient
|
||||||
|
/// </summary>
|
||||||
|
HttpClient HttpClient { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// API Exception
|
||||||
|
/// </summary>
|
||||||
|
public class ApiException : Exception
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The reason the api request failed
|
||||||
|
/// </summary>
|
||||||
|
public string ReasonPhrase { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The HttpStatusCode
|
||||||
|
/// </summary>
|
||||||
|
public System.Net.HttpStatusCode StatusCode { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The raw data returned by the api
|
||||||
|
/// </summary>
|
||||||
|
public string RawContent { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Construct the ApiException from parts of the response
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reasonPhrase"></param>
|
||||||
|
/// <param name="statusCode"></param>
|
||||||
|
/// <param name="rawContent"></param>
|
||||||
|
public ApiException(string reasonPhrase, System.Net.HttpStatusCode statusCode, string rawContent) : base(reasonPhrase ?? rawContent)
|
||||||
|
{
|
||||||
|
ReasonPhrase = reasonPhrase;
|
||||||
|
|
||||||
|
StatusCode = statusCode;
|
||||||
|
|
||||||
|
RawContent = rawContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Org.OpenAPITools.Api;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An IApiFactory interface
|
||||||
|
/// </summary>
|
||||||
|
public interface IApiFactory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A method to create an IApi of type IResult
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="IResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
IResult Create<IResult>() where IResult : IApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An ApiFactory
|
||||||
|
/// </summary>
|
||||||
|
public class ApiFactory : IApiFactory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The service provider
|
||||||
|
/// </summary>
|
||||||
|
public IServiceProvider Services { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ApiFactory"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services"></param>
|
||||||
|
public ApiFactory(IServiceProvider services)
|
||||||
|
{
|
||||||
|
Services = services;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A method to create an IApi of type IResult
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="IResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IResult Create<IResult>() where IResult : IApi
|
||||||
|
{
|
||||||
|
return Services.GetRequiredService<IResult>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Useful for tracking server health
|
||||||
|
/// </summary>
|
||||||
|
public class ApiResponseEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The ApiResponse
|
||||||
|
/// </summary>
|
||||||
|
public ApiResponse ApiResponse { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ApiResponseEventArgs
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiResponse"></param>
|
||||||
|
public ApiResponseEventArgs(ApiResponse apiResponse)
|
||||||
|
{
|
||||||
|
ApiResponse = apiResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,170 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a non-generic contract for the ApiResponse wrapper.
|
||||||
|
/// </summary>
|
||||||
|
public partial interface IApiResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The IsSuccessStatusCode from the api response
|
||||||
|
/// </summary>
|
||||||
|
bool IsSuccessStatusCode { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the status code (HTTP status code)
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The status code.</value>
|
||||||
|
HttpStatusCode StatusCode { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The raw content of this response.
|
||||||
|
/// </summary>
|
||||||
|
string RawContent { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The DateTime when the request was retrieved.
|
||||||
|
/// </summary>
|
||||||
|
DateTime DownloadedAt { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The headers contained in the api response
|
||||||
|
/// </summary>
|
||||||
|
System.Net.Http.Headers.HttpResponseHeaders Headers { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The path used when making the request.
|
||||||
|
/// </summary>
|
||||||
|
string Path { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The reason phrase contained in the api response
|
||||||
|
/// </summary>
|
||||||
|
string ReasonPhrase { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The DateTime when the request was sent.
|
||||||
|
/// </summary>
|
||||||
|
DateTime RequestedAt { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Uri used when making the request.
|
||||||
|
/// </summary>
|
||||||
|
Uri RequestUri { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// API Response
|
||||||
|
/// </summary>
|
||||||
|
public partial class ApiResponse : IApiResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the status code (HTTP status code)
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The status code.</value>
|
||||||
|
public HttpStatusCode StatusCode { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The raw data
|
||||||
|
/// </summary>
|
||||||
|
public string RawContent { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The IsSuccessStatusCode from the api response
|
||||||
|
/// </summary>
|
||||||
|
public bool IsSuccessStatusCode { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The reason phrase contained in the api response
|
||||||
|
/// </summary>
|
||||||
|
public string ReasonPhrase { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The headers contained in the api response
|
||||||
|
/// </summary>
|
||||||
|
public System.Net.Http.Headers.HttpResponseHeaders Headers { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The DateTime when the request was retrieved.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime DownloadedAt { get; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The DateTime when the request was sent.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime RequestedAt { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The path used when making the request.
|
||||||
|
/// </summary>
|
||||||
|
public string Path { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Uri used when making the request.
|
||||||
|
/// </summary>
|
||||||
|
public Uri RequestUri { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="System.Text.Json.JsonSerializerOptions"/>
|
||||||
|
/// </summary>
|
||||||
|
protected System.Text.Json.JsonSerializerOptions _jsonSerializerOptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Construct the response using an HttpResponseMessage
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="httpRequestMessage"></param>
|
||||||
|
/// <param name="httpResponseMessage"></param>
|
||||||
|
/// <param name="rawContent"></param>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <param name="requestedAt"></param>
|
||||||
|
/// <param name="jsonSerializerOptions"></param>
|
||||||
|
public ApiResponse(System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions)
|
||||||
|
{
|
||||||
|
StatusCode = httpResponseMessage.StatusCode;
|
||||||
|
Headers = httpResponseMessage.Headers;
|
||||||
|
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
|
||||||
|
ReasonPhrase = httpResponseMessage.ReasonPhrase;
|
||||||
|
RawContent = rawContent;
|
||||||
|
Path = path;
|
||||||
|
RequestUri = httpRequestMessage.RequestUri;
|
||||||
|
RequestedAt = requestedAt;
|
||||||
|
_jsonSerializerOptions = jsonSerializerOptions;
|
||||||
|
OnCreated(httpRequestMessage, httpResponseMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnCreated(System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An interface for responses of type
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TType"></typeparam>
|
||||||
|
public interface IOk<TType> : IApiResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Deserializes the response if the response is Ok
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
TType Ok();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the response is Ok and the deserialized response is not null
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="result"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool TryOk(out TType result);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,329 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using KellermanSoftware.CompareNetObjects;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
[assembly: InternalsVisibleTo("Org.OpenAPITools.Test")]
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Utility functions providing some benefit to API client consumers.
|
||||||
|
/// </summary>
|
||||||
|
public static class ClientUtils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An instance of CompareLogic.
|
||||||
|
/// </summary>
|
||||||
|
public static CompareLogic compareLogic;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Static constructor to initialise compareLogic.
|
||||||
|
/// </summary>
|
||||||
|
static ClientUtils()
|
||||||
|
{
|
||||||
|
ComparisonConfig comparisonConfig = new ComparisonConfig();
|
||||||
|
comparisonConfig.UseHashCodeIdentifier = true;
|
||||||
|
compareLogic = new CompareLogic(comparisonConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A delegate for events.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public delegate void EventHandler<T>(object sender, T e) where T : EventArgs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true when deserialization succeeds.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="json"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <param name="result"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool TryDeserialize<T>(string json, JsonSerializerOptions options, out T result)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = JsonSerializer.Deserialize<T>(json, options);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
result = default;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true when deserialization succeeds.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="reader"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <param name="result"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOptions options, out T result)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = JsonSerializer.Deserialize<T>(ref reader, options);
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
result = default;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
/// 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="format">The DateTime serialization format.</param>
|
||||||
|
/// <returns>Formatted string.</returns>
|
||||||
|
public static string ParameterToString(object obj, string format = ISO8601_DATETIME_FORMAT)
|
||||||
|
{
|
||||||
|
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(format);
|
||||||
|
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(format);
|
||||||
|
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));
|
||||||
|
return string.Join(",", entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Convert.ToString(obj, System.Globalization.CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// URL encode a string
|
||||||
|
/// Credit/Ref: https://github.com/restsharp/RestSharp/blob/master/RestSharp/Extensions/StringExtensions.cs#L50
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">string to be URL encoded</param>
|
||||||
|
/// <returns>Byte array</returns>
|
||||||
|
public static string UrlEncode(string input)
|
||||||
|
{
|
||||||
|
const int maxLength = 32766;
|
||||||
|
|
||||||
|
if (input == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("input");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.Length <= maxLength)
|
||||||
|
{
|
||||||
|
return Uri.EscapeDataString(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder(input.Length * 2);
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
while (index < input.Length)
|
||||||
|
{
|
||||||
|
int length = Math.Min(input.Length - index, maxLength);
|
||||||
|
string subString = input.Substring(index, length);
|
||||||
|
|
||||||
|
sb.Append(Uri.EscapeDataString(subString));
|
||||||
|
index += subString.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
/// Get the discriminator
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="utf8JsonReader"></param>
|
||||||
|
/// <param name="discriminator"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="JsonException"></exception>
|
||||||
|
public static string GetDiscriminator(Utf8JsonReader utf8JsonReader, string discriminator)
|
||||||
|
{
|
||||||
|
int currentDepth = utf8JsonReader.CurrentDepth;
|
||||||
|
|
||||||
|
if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray)
|
||||||
|
throw new JsonException();
|
||||||
|
|
||||||
|
JsonTokenType startingTokenType = utf8JsonReader.TokenType;
|
||||||
|
|
||||||
|
while (utf8JsonReader.Read())
|
||||||
|
{
|
||||||
|
if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1)
|
||||||
|
{
|
||||||
|
string localVarJsonPropertyName = utf8JsonReader.GetString();
|
||||||
|
utf8JsonReader.Read();
|
||||||
|
|
||||||
|
if (localVarJsonPropertyName != null && localVarJsonPropertyName.Equals(discriminator))
|
||||||
|
return utf8JsonReader.GetString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new JsonException("The specified discriminator was not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The base path of the API
|
||||||
|
/// </summary>
|
||||||
|
public const string BASE_ADDRESS = "http://localhost";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The scheme of the API
|
||||||
|
/// </summary>
|
||||||
|
public const string SCHEME = "http";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The context path of the API
|
||||||
|
/// </summary>
|
||||||
|
public const string CONTEXT_PATH = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The host of the API
|
||||||
|
/// </summary>
|
||||||
|
public const string HOST = "localhost";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The format to use for DateTime serialization
|
||||||
|
/// </summary>
|
||||||
|
public const string ISO8601_DATETIME_FORMAT = "o";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A class containing a CookieContainer
|
||||||
|
/// </summary>
|
||||||
|
public sealed class CookieContainer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The collection of tokens
|
||||||
|
/// </summary>
|
||||||
|
public System.Net.CookieContainer Value { get; } = new System.Net.CookieContainer();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Formatter for 'date' and 'date-time' 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 DateTimeJsonConverter : JsonConverter<DateTime>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The formats used to deserialize the date
|
||||||
|
/// </summary>
|
||||||
|
public static string[] Formats { get; } = {
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ssK",
|
||||||
|
"yyyy'-'MM'-'dd",
|
||||||
|
"yyyyMMddTHHmmss.fffffffK",
|
||||||
|
"yyyyMMddTHHmmss.ffffffK",
|
||||||
|
"yyyyMMddTHHmmss.fffffK",
|
||||||
|
"yyyyMMddTHHmmss.ffffK",
|
||||||
|
"yyyyMMddTHHmmss.fffK",
|
||||||
|
"yyyyMMddTHHmmss.ffK",
|
||||||
|
"yyyyMMddTHHmmss.fK",
|
||||||
|
"yyyyMMddTHHmmssK",
|
||||||
|
"yyyyMMdd"
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a DateTime from the Json object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reader"></param>
|
||||||
|
/// <param name="typeToConvert"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
|
||||||
|
if (reader.TokenType == JsonTokenType.Null)
|
||||||
|
throw new NotSupportedException();
|
||||||
|
|
||||||
|
string value = reader.GetString();
|
||||||
|
|
||||||
|
foreach(string format in Formats)
|
||||||
|
if (DateTime.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime result))
|
||||||
|
return result;
|
||||||
|
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the DateTime to the json writer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"></param>
|
||||||
|
/// <param name="dateTimeValue"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
public override void Write(Utf8JsonWriter writer, DateTime dateTimeValue, JsonSerializerOptions options) =>
|
||||||
|
writer.WriteStringValue(dateTimeValue.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK", CultureInfo.InvariantCulture));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Formatter for 'date' and 'date-time' 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 DateTimeNullableJsonConverter : JsonConverter<DateTime?>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The formats used to deserialize the date
|
||||||
|
/// </summary>
|
||||||
|
public static string[] Formats { get; } = {
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fK",
|
||||||
|
"yyyy'-'MM'-'dd'T'HH':'mm':'ssK",
|
||||||
|
"yyyy'-'MM'-'dd",
|
||||||
|
"yyyyMMddTHHmmss.fffffffK",
|
||||||
|
"yyyyMMddTHHmmss.ffffffK",
|
||||||
|
"yyyyMMddTHHmmss.fffffK",
|
||||||
|
"yyyyMMddTHHmmss.ffffK",
|
||||||
|
"yyyyMMddTHHmmss.fffK",
|
||||||
|
"yyyyMMddTHHmmss.ffK",
|
||||||
|
"yyyyMMddTHHmmss.fK",
|
||||||
|
"yyyyMMddTHHmmssK",
|
||||||
|
"yyyyMMdd"
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a DateTime from the Json object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reader"></param>
|
||||||
|
/// <param name="typeToConvert"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
|
||||||
|
if (reader.TokenType == JsonTokenType.Null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
string value = reader.GetString();
|
||||||
|
|
||||||
|
foreach(string format in Formats)
|
||||||
|
if (DateTime.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime result))
|
||||||
|
return result;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the DateTime to the json writer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="writer"></param>
|
||||||
|
/// <param name="dateTimeValue"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
public override void Write(Utf8JsonWriter writer, DateTime? dateTimeValue, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
if (dateTimeValue == null)
|
||||||
|
writer.WriteNullValue();
|
||||||
|
else
|
||||||
|
writer.WriteStringValue(dateTimeValue.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK", CultureInfo.InvariantCulture));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Useful for tracking server health
|
||||||
|
/// </summary>
|
||||||
|
public class ExceptionEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The ApiResponse
|
||||||
|
/// </summary>
|
||||||
|
public Exception Exception { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ExcepetionEventArgs
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exception"></param>
|
||||||
|
public ExceptionEventArgs(Exception exception)
|
||||||
|
{
|
||||||
|
Exception = exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Org.OpenAPITools.Api;
|
||||||
|
using Org.OpenAPITools.Model;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides hosting configuration for Org.OpenAPITools
|
||||||
|
/// </summary>
|
||||||
|
public class HostConfiguration
|
||||||
|
{
|
||||||
|
private readonly IServiceCollection _services;
|
||||||
|
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions();
|
||||||
|
|
||||||
|
internal bool HttpClientsAdded { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates the class
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services"></param>
|
||||||
|
public HostConfiguration(IServiceCollection services)
|
||||||
|
{
|
||||||
|
_services = services;
|
||||||
|
_jsonOptions.Converters.Add(new JsonStringEnumConverter());
|
||||||
|
_jsonOptions.Converters.Add(new DateTimeJsonConverter());
|
||||||
|
_jsonOptions.Converters.Add(new DateTimeNullableJsonConverter());
|
||||||
|
_jsonOptions.Converters.Add(new AppleJsonConverter());
|
||||||
|
_jsonOptions.Converters.Add(new BananaJsonConverter());
|
||||||
|
_jsonOptions.Converters.Add(new FruitJsonConverter());
|
||||||
|
JsonSerializerOptionsProvider jsonSerializerOptionsProvider = new JsonSerializerOptionsProvider(_jsonOptions);
|
||||||
|
_services.AddSingleton(jsonSerializerOptionsProvider);
|
||||||
|
_services.AddSingleton<IApiFactory, ApiFactory>();
|
||||||
|
_services.AddSingleton<DefaultApiEvents>();
|
||||||
|
_services.AddTransient<IDefaultApi, DefaultApi>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures the HttpClients.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="builder"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public HostConfiguration AddApiHttpClients
|
||||||
|
(
|
||||||
|
Action<HttpClient> client = null, Action<IHttpClientBuilder> builder = null)
|
||||||
|
{
|
||||||
|
if (client == null)
|
||||||
|
client = c => c.BaseAddress = new Uri(ClientUtils.BASE_ADDRESS);
|
||||||
|
|
||||||
|
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||||
|
|
||||||
|
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||||
|
|
||||||
|
if (builder != null)
|
||||||
|
foreach (IHttpClientBuilder instance in builders)
|
||||||
|
builder(instance);
|
||||||
|
|
||||||
|
HttpClientsAdded = true;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures the JsonSerializerSettings
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public HostConfiguration ConfigureJsonOptions(Action<JsonSerializerOptions> options)
|
||||||
|
{
|
||||||
|
options(_jsonOptions);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds tokens to your IServiceCollection
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TTokenBase"></typeparam>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public HostConfiguration AddTokens<TTokenBase>(TTokenBase token) where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
return AddTokens(new TTokenBase[]{ token });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds tokens to your IServiceCollection
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TTokenBase"></typeparam>
|
||||||
|
/// <param name="tokens"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public HostConfiguration AddTokens<TTokenBase>(IEnumerable<TTokenBase> tokens) where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
TokenContainer<TTokenBase> container = new TokenContainer<TTokenBase>(tokens);
|
||||||
|
_services.AddSingleton(services => container);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a token provider to your IServiceCollection
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TTokenProvider"></typeparam>
|
||||||
|
/// <typeparam name="TTokenBase"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public HostConfiguration UseProvider<TTokenProvider, TTokenBase>()
|
||||||
|
where TTokenProvider : TokenProvider<TTokenBase>
|
||||||
|
where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
_services.AddSingleton<TTokenProvider>();
|
||||||
|
_services.AddSingleton<TokenProvider<TTokenBase>>(services => services.GetRequiredService<TTokenProvider>());
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides the JsonSerializerOptions
|
||||||
|
/// </summary>
|
||||||
|
public class JsonSerializerOptionsProvider
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// the JsonSerializerOptions
|
||||||
|
/// </summary>
|
||||||
|
public JsonSerializerOptions Options { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a JsonSerializerOptionsProvider
|
||||||
|
/// </summary>
|
||||||
|
public JsonSerializerOptionsProvider(JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
Options = options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A wrapper for operation parameters which are not required
|
||||||
|
/// </summary>
|
||||||
|
public struct Option<TType>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The value to send to the server
|
||||||
|
/// </summary>
|
||||||
|
public TType Value { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When true the value will be sent to the server
|
||||||
|
/// </summary>
|
||||||
|
internal bool IsSet { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A wrapper for operation parameters which are not required
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public Option(TType value)
|
||||||
|
{
|
||||||
|
IsSet = true;
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Implicitly converts this option to the contained type
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="option"></param>
|
||||||
|
public static implicit operator TType(Option<TType> option) => option.Value;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Implicitly converts the provided value to an Option
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public static implicit operator Option<TType>(TType value) => new Option<TType>(value);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Channels;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a token to the api clients. Tokens will be rate limited based on the provided TimeSpan.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TTokenBase"></typeparam>
|
||||||
|
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
internal Dictionary<string, Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, Channel<TTokenBase>>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="container"></param>
|
||||||
|
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||||
|
{
|
||||||
|
foreach(TTokenBase token in _tokens)
|
||||||
|
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||||
|
|
||||||
|
BoundedChannelOptions options = new BoundedChannelOptions(_tokens.Length)
|
||||||
|
{
|
||||||
|
FullMode = BoundedChannelFullMode.DropWrite
|
||||||
|
};
|
||||||
|
|
||||||
|
AvailableTokens.Add(string.Empty, Channel.CreateBounded<TTokenBase>(options));
|
||||||
|
|
||||||
|
foreach(Channel<TTokenBase> tokens in AvailableTokens.Values)
|
||||||
|
for (int i = 0; i < _tokens.Length; i++)
|
||||||
|
_tokens[i].TokenBecameAvailable += ((sender) => tokens.Writer.TryWrite((TTokenBase) sender));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||||
|
{
|
||||||
|
if (!AvailableTokens.TryGetValue(header, out Channel<TTokenBase> tokens))
|
||||||
|
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||||
|
|
||||||
|
return await tokens.Reader.ReadAsync(cancellation).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The base for all tokens.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class TokenBase
|
||||||
|
{
|
||||||
|
private DateTime _nextAvailable = DateTime.UtcNow;
|
||||||
|
private object _nextAvailableLock = new object();
|
||||||
|
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||||
|
|
||||||
|
|
||||||
|
internal TimeSpan? Timeout { get; set; }
|
||||||
|
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||||
|
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize a TokenBase object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timeout"></param>
|
||||||
|
internal TokenBase(TimeSpan? timeout = null)
|
||||||
|
{
|
||||||
|
Timeout = timeout;
|
||||||
|
|
||||||
|
if (Timeout != null)
|
||||||
|
StartTimer(Timeout.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts the token's timer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timeout"></param>
|
||||||
|
internal void StartTimer(TimeSpan timeout)
|
||||||
|
{
|
||||||
|
Timeout = timeout;
|
||||||
|
_timer.Interval = Timeout.Value.TotalMilliseconds;
|
||||||
|
_timer.Elapsed += OnTimer;
|
||||||
|
_timer.AutoReset = true;
|
||||||
|
_timer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true while the token is rate limited.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsRateLimited => _nextAvailable > DateTime.UtcNow;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Triggered when the server returns status code TooManyRequests
|
||||||
|
/// Once triggered the local timeout will be extended an arbitrary length of time.
|
||||||
|
/// </summary>
|
||||||
|
public void BeginRateLimit()
|
||||||
|
{
|
||||||
|
lock(_nextAvailableLock)
|
||||||
|
_nextAvailable = DateTime.UtcNow.AddSeconds(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTimer(object sender, System.Timers.ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
if (TokenBecameAvailable != null && !IsRateLimited)
|
||||||
|
TokenBecameAvailable.Invoke(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A container for a collection of tokens.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TTokenBase"></typeparam>
|
||||||
|
public sealed class TokenContainer<TTokenBase> where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The collection of tokens
|
||||||
|
/// </summary>
|
||||||
|
public List<TTokenBase> Tokens { get; } = new List<TTokenBase>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a TokenContainer
|
||||||
|
/// </summary>
|
||||||
|
public TokenContainer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a TokenContainer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tokens"></param>
|
||||||
|
public TokenContainer(System.Collections.Generic.IEnumerable<TTokenBase> tokens)
|
||||||
|
{
|
||||||
|
Tokens = tokens.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
// <auto-generated>
|
||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A class which will provide tokens.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The array of tokens.
|
||||||
|
/// </summary>
|
||||||
|
protected TTokenBase[] _tokens;
|
||||||
|
|
||||||
|
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a TokenProvider.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tokens"></param>
|
||||||
|
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||||
|
{
|
||||||
|
_tokens = tokens.ToArray();
|
||||||
|
|
||||||
|
if (_tokens.Length == 0)
|
||||||
|
throw new ArgumentException("You did not provide any tokens.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Org.OpenAPITools.Client;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Extensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for IHostBuilder
|
||||||
|
/// </summary>
|
||||||
|
public static class IHostBuilderExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Add the api to your host builder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder"></param>
|
||||||
|
public static IHostBuilder ConfigureApi(this IHostBuilder builder)
|
||||||
|
{
|
||||||
|
builder.ConfigureServices((context, services) =>
|
||||||
|
{
|
||||||
|
HostConfiguration config = new HostConfiguration(services);
|
||||||
|
|
||||||
|
IServiceCollectionExtensions.AddApi(services, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add the api to your host builder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
public static IHostBuilder ConfigureApi(this IHostBuilder builder, Action<HostBuilderContext, IServiceCollection, HostConfiguration> options)
|
||||||
|
{
|
||||||
|
builder.ConfigureServices((context, services) =>
|
||||||
|
{
|
||||||
|
HostConfiguration config = new HostConfiguration(services);
|
||||||
|
|
||||||
|
options(context, services, config);
|
||||||
|
|
||||||
|
IServiceCollectionExtensions.AddApi(services, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* fruity
|
||||||
|
*
|
||||||
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 0.0.1
|
||||||
|
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Polly.Timeout;
|
||||||
|
using Polly.Extensions.Http;
|
||||||
|
using Polly;
|
||||||
|
|
||||||
|
namespace Org.OpenAPITools.Extensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for IHttpClientBuilder
|
||||||
|
/// </summary>
|
||||||
|
public static class IHttpClientBuilderExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a Polly retry policy to your clients.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="retries"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IHttpClientBuilder AddRetryPolicy(this IHttpClientBuilder client, int retries)
|
||||||
|
{
|
||||||
|
client.AddPolicyHandler(RetryPolicy(retries));
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a Polly timeout policy to your clients.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="timeout"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IHttpClientBuilder AddTimeoutPolicy(this IHttpClientBuilder client, TimeSpan timeout)
|
||||||
|
{
|
||||||
|
client.AddPolicyHandler(TimeoutPolicy(timeout));
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a Polly circuit breaker to your clients.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="handledEventsAllowedBeforeBreaking"></param>
|
||||||
|
/// <param name="durationOfBreak"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IHttpClientBuilder AddCircuitBreakerPolicy(this IHttpClientBuilder client, int handledEventsAllowedBeforeBreaking, TimeSpan durationOfBreak)
|
||||||
|
{
|
||||||
|
client.AddTransientHttpErrorPolicy(builder => CircuitBreakerPolicy(builder, handledEventsAllowedBeforeBreaking, durationOfBreak));
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Polly.Retry.AsyncRetryPolicy<HttpResponseMessage> RetryPolicy(int retries)
|
||||||
|
=> HttpPolicyExtensions
|
||||||
|
.HandleTransientHttpError()
|
||||||
|
.Or<TimeoutRejectedException>()
|
||||||
|
.RetryAsync(retries);
|
||||||
|
|
||||||
|
private static AsyncTimeoutPolicy<HttpResponseMessage> TimeoutPolicy(TimeSpan timeout)
|
||||||
|
=> Policy.TimeoutAsync<HttpResponseMessage>(timeout);
|
||||||
|
|
||||||
|
private static Polly.CircuitBreaker.AsyncCircuitBreakerPolicy<HttpResponseMessage> CircuitBreakerPolicy(
|
||||||
|
PolicyBuilder<HttpResponseMessage> builder, int handledEventsAllowedBeforeBreaking, TimeSpan durationOfBreak)
|
||||||
|
=> builder.CircuitBreakerAsync(handledEventsAllowedBeforeBreaking, durationOfBreak);
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user