11# Created with Openapi Generator
22
33<a id =" cli" ></a >
4- ## Run the following powershell command to generate the library
5-
6- ```ps1
7- $properties = @(
8- 'apiName={ {apiName} }',
9- 'targetFramework={ {targetFramework} }',
10- 'validatable={ {validatable} }',
11- 'nullableReferenceTypes={ {nullableReferenceTypes} }',
12- 'hideGenerationTimestamp={ {hideGenerationTimestamp} }',
13- 'packageVersion={ {packageVersion} }',
14- 'packageAuthors={ {packageAuthors} }',
15- 'packageCompany={ {packageCompany} }',
16- 'packageCopyright={ {packageCopyright} }',
17- 'packageDescription={ {packageDescription} }',{ {#licenseId} }
18- 'licenseId={ {.} }',{ {/licenseId} }
19- 'packageName={ {packageName} }',
20- 'packageTags={ {packageTags} }',
21- 'packageTitle={ {packageTitle} }'
22- ) -join ","
23-
24- $global = @(
25- 'apiDocs={ {generateApiDocs} }',
26- 'modelDocs={ {generateModelDocs} }',
27- 'apiTests={ {generateApiTests} }',
28- 'modelTests={ {generateModelTests} }'
29- ) -join ","
30-
31- java -jar "<path >/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar" generate `
32- -g csharp-netcore `
33- -i <your-swagger-file >.yaml `
34- -o <your-output-folder > `
35- --library generichost `
36- --additional-properties $properties `
37- --global-property $global `
38- --git-host "{ {gitHost} }" `
39- --git-repo-id "{ {gitRepoId} }" `
40- --git-user-id "{ {gitUserId} }" `
41- --release-note "{ {releaseNote} }"
42- # -t templates
4+ ## Creating the library
5+ Create a config.yaml file similar to what is below, then run the following powershell command to generate the library `java -jar "<path >/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar" generate -c config.yaml`
6+
7+ ```yaml
8+ generatorName: csharp
9+ inputSpec: { {inputSpec} }
10+ outputDir: { {outputFolder} }
11+
12+ # https://openapi-generator.tech/docs/generators/csharp
13+ additionalProperties:
14+ packageGuid: '{ {packageGuid} }'
15+
16+ # https://openapi-generator.tech/docs/integrations/#github-integration
17+ # gitHost:
18+ # gitUserId:
19+ # gitRepoId:
20+
21+ # https://openapi-generator.tech/docs/globals
22+ # globalProperties:
23+
24+ # https://openapi-generator.tech/docs/customization/#inline-schema-naming
25+ # inlineSchemaOptions:
26+
27+ # https://openapi-generator.tech/docs/customization/#name-mapping
28+ # modelNameMappings:
29+ # nameMappings:
30+
31+ # https://openapi-generator.tech/docs/customization/#openapi-normalizer
32+ # openapiNormalizer:
33+
34+ # templateDir: https://openapi-generator.tech/docs/templating/#modifying-templates
35+
36+ # releaseNote:
4337```
4438
4539<a id =" usage" ></a >
4640## Using the library in your project
4741
4842```cs
49- using System;
50- using System.Threading.Tasks;
5143using Microsoft.Extensions.Hosting;
5244using Microsoft.Extensions.DependencyInjection;
5345using { {packageName} }.Api;
5446using { {packageName} }.Client;
5547using { {packageName} }.Model;
48+ using Org.OpenAPITools.Extensions;
5649
5750namespace YourProject
5851{
@@ -66,8 +59,8 @@ namespace YourProject
6659 { {#-first} }
6760 { {#operation} }
6861 { {#-first} }
69- { {operationId} }ApiResponse apiResponse = await api.{ {operationId} }Async("todo");
70- { {#returnType} }{ {{.} }}{ {/returnType} }{ {^returnType} }object{ {/returnType} } model = apiResponse.Ok();
62+ { {interfacePrefix } } { { operationId} }ApiResponse apiResponse = await api.{ {operationId} }Async("todo");
63+ { {#returnType} }{ {{.} }}{ {/returnType} }{ {^returnType} }object{ {/returnType} }{ {nrt? } } model = apiResponse.Ok();
7164 { {/-first} }
7265 { {/operation} }
7366 { {/-first} }
@@ -78,16 +71,17 @@ namespace YourProject
7871 }
7972
8073 public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
81- .Configure{ {apiName} }((context, options) =>
74+ .Configure{ {apiName} }((context, services, options) =>
8275 {
8376 {{#authMethods} }
8477 { {#-first} }
85- // the type of token here depends on the api security specifications
86- ApiKeyToken token = new("<your token >", ClientUtils.ApiKeyHeader.Authorization);
78+ // The type of token here depends on the api security specifications
79+ // Available token types are ApiKeyToken, BasicToken, BearerToken, HttpSigningToken, and OAuthToken.
80+ BearerToken token = new("<your token >");
8781 options.AddTokens(token);
8882
8983 // optionally choose the method the tokens will be provided with, default is RateLimitProvider
90- options.UseProvider<RateLimitProvider <ApiKeyToken >, ApiKeyToken >();
84+ options.UseProvider<RateLimitProvider <BearerToken >, BearerToken >();
9185
9286 { {/-first} }
9387 { {/authMethods} }
@@ -96,11 +90,17 @@ namespace YourProject
9690 // your custom converters if any
9791 } );
9892
99- options.Add{ {apiName} }HttpClients(builder: builder => builder
100- .AddRetryPolicy(2)
101- .AddTimeoutPolicy(TimeSpan.FromSeconds(5))
102- .AddCircuitBreakerPolicy(10, TimeSpan.FromSeconds(30))
103- // add whatever middleware you prefer
93+ options.Add{ {apiName} }HttpClients(client =>
94+ {
95+ // client configuration
96+ } , builder =>
97+ {
98+ builder
99+ .AddRetryPolicy(2)
100+ .AddTimeoutPolicy(TimeSpan.FromSeconds(5))
101+ .AddCircuitBreakerPolicy(10, TimeSpan.FromSeconds(30));
102+ // add whatever middleware you prefer
103+ }
104104 );
105105 });
106106 }
@@ -110,136 +110,28 @@ namespace YourProject
110110## Questions
111111
112112- What about HttpRequest failures and retries?
113- If supportsRetry is enabled, you can configure Polly in the ConfigureClients method.
113+ Configure Polly in the IHttpClientBuilder
114114- How are tokens used?
115115 Tokens are provided by a TokenProvider class. The default is RateLimitProvider which will perform client side rate limiting.
116116 Other providers can be used with the UseProvider method.
117117- Does an HttpRequest throw an error when the server response is not Ok?
118- 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.
118+ 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.
119119 StatusCode and ReasonPhrase will contain information about the error.
120120 If the return type is T, then it will throw. If the return type is TOrDefault, it will return null.
121121- How do I validate requests and process responses?
122- Use the provided On and After methods in the Api class from the namespace { {packageName} }.Rest.DefaultApi.
123- Or provide your own class by using the generic Configure{ {apiName} } method.
124-
125- <a id =" dependencies" ></a >
126- ## Dependencies
127-
128- - [Microsoft.Extensions.Hosting](https://www.nuget.org/packages/Microsoft.Extensions.Hosting/) - 5.0.0 or later
129- - [Microsoft.Extensions.Http](https://www.nuget.org/packages/Microsoft.Extensions.Http/) - 5.0.0 or later{ {#supportsRetry} }
130- - [Microsoft.Extensions.Http.Polly](https://www.nuget.org/packages/Microsoft.Extensions.Http.Polly/) - 5.0.1 or later{ {/supportsRetry} }{ {#useCompareNetObjects} }
131- - [CompareNETObjects](https://www.nuget.org/packages/CompareNETObjects) - 4.61.0 or later{ {/useCompareNetObjects} }{ {#validatable} }
132- - [System.ComponentModel.Annotations](https://www.nuget.org/packages/System.ComponentModel.Annotations) - 4.7.0 or later{ {/validatable} }{ {#apiDocs} }
133-
134- <a id =" documentation-for-api-endpoints" ></a >
135- ## Documentation for API Endpoints
136-
137- All URIs are relative to *{ {{basePath} }}*
138-
139- Class | Method | HTTP request | Description
140- ------------ | ------------- | ------------- | -------------{ {#apiInfo} }{ {#apis} }{ {#operations} }{ {#operation} }
141- *{ {classname} }* | [**{ {operationId} }**]({ {apiDocPath} }{ {classname} }.md#{ {operationIdLowerCase} }) | **{ {httpMethod} }** { {path} } | { {#summary} }{ {{summary} }}{ {/summary} }{ {/operation} }{ {/operations} }{ {/apis} }{ {/apiInfo} }{ {/apiDocs} }{ {#modelDocs} }
142-
143- <a id =" documentation-for-models" ></a >
144- ## Documentation for Models
145-
146- { {#modelPackage} }{ {#models} }{ {#model} } - [{ {{modelPackage} }}.{ {{classname} }}]({ {modelDocPath} }{ {{classname} }}.md){ {/model} }{ {/models} }{ {/modelPackage} }
147- { {^modelPackage} }No model defined in this package{ {/modelPackage} }{ {/modelDocs} }
148-
149- <a id =" documentation-for-authorization" ></a >
150- ## Documentation for Authorization
151-
152- { {^authMethods} }Endpoints do not require authorization.{ {/authMethods} }
153- { {#hasAuthMethods} }Authentication schemes defined for the API:{ {/hasAuthMethods} }
154- { {#authMethods} }
155- <a id =" { { name} } " ></a >
156- ### { {name} }
157-
158- { {#isApiKey} }- **Type**: API key
159- - **API key parameter name**: { {keyParamName} }
160- - **Location**: { {#isKeyInQuery} }URL query string{ {/isKeyInQuery} }{ {#isKeyInHeader} }HTTP header{ {/isKeyInHeader} }
161- { {/isApiKey} }
162- { {#isBasicBasic} }
163- - **Type**: HTTP basic authentication
164- { {/isBasicBasic} }
165- { {#isBasicBearer} }
166- - **Type**: Bearer Authentication
167- { {/isBasicBearer} }
168- { {#isHttpSignature} }
169- - **Type**: HTTP signature authentication
170- { {/isHttpSignature} }
171- { {#isOAuth} }
172- - **Type**: OAuth
173- - **Flow**: { {flow} }
174- - **Authorization URL**: { {authorizationUrl} }
175- - **Scopes**: { {^scopes} }N/A{ {/scopes} }{ {#scopes} }
176- - { {scope} }: { {description} }{ {/scopes} }
177- { {/isOAuth} }
178-
179- { {/authMethods} }
122+ Use the provided On and After partial methods in the api classes.
123+
124+ ## Api Information
125+ - appName: { {appName} }
126+ - appVersion: { {appVersion} }
127+ - appDescription: { {appDescription} }
180128
181129## Build
130+ This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
131+
182132- SDK version: { {packageVersion} }
183133{ {^hideGenerationTimestamp} }
184134- Build date: { {generatedDate} }
185135{ {/hideGenerationTimestamp} }
186136- Generator version: { {generatorVersion} }
187137- Build package: { {generatorClass} }
188-
189- ## Api Information
190- - appName: { {appName} }
191- - appVersion: { {appVersion} }
192- - appDescription: { {appDescription} }
193-
194- ## [OpenApi Global properties](https://openapi-generator.tech/docs/globals)
195- - generateAliasAsModel: { {generateAliasAsModel} }
196- - supportingFiles: { {supportingFiles} }
197- - models: omitted for brevity
198- - apis: omitted for brevity
199- - apiDocs: { {generateApiDocs} }
200- - modelDocs: { {generateModelDocs} }
201- - apiTests: { {generateApiTests} }
202- - modelTests: { {generateModelTests} }
203-
204- ## [OpenApi Generator Parameters](https://openapi-generator.tech/docs/generators/csharp-netcore)
205- - allowUnicodeIdentifiers: { {allowUnicodeIdentifiers} }
206- - apiName: { {apiName} }
207- - caseInsensitiveResponseHeaders: { {caseInsensitiveResponseHeaders} }
208- - conditionalSerialization: { {conditionalSerialization} }
209- - disallowAdditionalPropertiesIfNotPresent: { {disallowAdditionalPropertiesIfNotPresent} }
210- - gitHost: { {gitHost} }
211- - gitRepoId: { {gitRepoId} }
212- - gitUserId: { {gitUserId} }
213- - hideGenerationTimestamp: { {hideGenerationTimestamp} }
214- - interfacePrefix: { {interfacePrefix} }
215- - library: { {library} }
216- - licenseId: { {licenseId} }
217- - modelPropertyNaming: { {modelPropertyNaming} }
218- - netCoreProjectFile: { {netCoreProjectFile} }
219- - nonPublicApi: { {nonPublicApi} }
220- - nullableReferenceTypes: { {nullableReferenceTypes} }
221- - optionalAssemblyInfo: { {optionalAssemblyInfo} }
222- - optionalEmitDefaultValues: { {optionalEmitDefaultValues} }
223- - optionalMethodArgument: { {optionalMethodArgument} }
224- - optionalProjectFile: { {optionalProjectFile} }
225- - packageAuthors: { {packageAuthors} }
226- - packageCompany: { {packageCompany} }
227- - packageCopyright: { {packageCopyright} }
228- - packageDescription: { {packageDescription} }
229- - packageGuid: { {packageGuid} }
230- - packageName: { {packageName} }
231- - packageTags: { {packageTags} }
232- - packageTitle: { {packageTitle} }
233- - packageVersion: { {packageVersion} }
234- - releaseNote: { {releaseNote} }
235- - returnICollection: { {returnICollection} }
236- - sortParamsByRequiredFlag: { {sortParamsByRequiredFlag} }
237- - sourceFolder: { {sourceFolder} }
238- - targetFramework: { {targetFramework} }
239- - useCollection: { {useCollection} }
240- - useDateTimeOffset: { {useDateTimeOffset} }
241- - useOneOfDiscriminatorLookup: { {useOneOfDiscriminatorLookup} }
242- - validatable: { {validatable} }{ {#infoUrl} }
243- For more information, please visit [{ {{.} }}]({ {{.} }}){ {/infoUrl} }
244-
245- This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
0 commit comments