Skip to content

Commit a428cff

Browse files
authored
[csharp][generichost] Updated docs (#21357)
* updated docs * updated docs * updated docs
1 parent 9593260 commit a428cff

File tree

195 files changed

+2233
-40365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+2233
-40365
lines changed

docs/generators/csharp.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
4444
|packageName|C# package name (convention: Title.Case).| |Org.OpenAPITools|
4545
|packageTags|Tags to identify the package| |null|
4646
|packageVersion|C# package version.| |1.0.0|
47-
|releaseNote|Release note, default to 'Minor update'.| |Minor update|
4847
|returnICollection|Return ICollection<T> instead of the concrete type.| |false|
4948
|sourceFolder|source folder for generated code| |src|
5049
|targetFramework|The target .NET framework version. To target multiple frameworks, use `;` as the separator, e.g. `netstandard2.1;netcoreapp3.1`|<dl><dt>**netstandard1.3**</dt><dd>.NET Standard 1.3</dd><dt>**netstandard1.4**</dt><dd>.NET Standard 1.4</dd><dt>**netstandard1.5**</dt><dd>.NET Standard 1.5</dd><dt>**netstandard1.6**</dt><dd>.NET Standard 1.6</dd><dt>**netstandard2.0**</dt><dd>.NET Standard 2.0</dd><dt>**netstandard2.1**</dt><dd>.NET Standard 2.1</dd><dt>**net47**</dt><dd>.NET Framework 4.7</dd><dt>**net48**</dt><dd>.NET Framework 4.8</dd><dt>**net8.0**</dt><dd>.NET 8.0 (End of Support 10 November 2026)</dd><dt>**net9.0**</dt><dd>.NET 9.0 (End of Support 12 May 2026)</dd></dl>|net9.0|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ enum SortingMethod {
134134
private SortingMethod modelPropertySorting = SortingMethod.DEFAULT;
135135

136136
protected boolean caseInsensitiveResponseHeaders = Boolean.FALSE;
137-
protected String releaseNote = "Minor update";
138137
@Setter protected String licenseId;
139138
@Setter protected String packageTags;
140139
@Setter protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
@@ -213,10 +212,6 @@ public CSharpClientCodegen() {
213212
CodegenConstants.LICENSE_ID_DESC,
214213
this.licenseId);
215214

216-
addOption(CodegenConstants.RELEASE_NOTE,
217-
CodegenConstants.RELEASE_NOTE_DESC,
218-
this.releaseNote);
219-
220215
addOption(CodegenConstants.PACKAGE_TAGS,
221216
CodegenConstants.PACKAGE_TAGS_DESC,
222217
this.packageTags);
@@ -1293,11 +1288,6 @@ public void setCaseInsensitiveResponseHeaders(final Boolean caseInsensitiveRespo
12931288
this.caseInsensitiveResponseHeaders = caseInsensitiveResponseHeaders;
12941289
}
12951290

1296-
@Override
1297-
public void setReleaseNote(String releaseNote) {
1298-
this.releaseNote = releaseNote;
1299-
}
1300-
13011291
public boolean getUseOneOfDiscriminatorLookup() {
13021292
return this.useOneOfDiscriminatorLookup;
13031293
}

modules/openapi-generator/src/main/resources/csharp/api_doc.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ All URIs are relative to *{{{basePath}}}*
2121

2222
{{{.}}}{{/notes}}
2323

24+
{{^useGenericHost}}
2425
### Example
2526
```csharp
2627
using System.Collections.Generic;
@@ -122,6 +123,7 @@ catch (ApiException e)
122123
Debug.Print(e.StackTrace);
123124
}
124125
```
126+
{{/useGenericHost}}
125127

126128
### Parameters
127129
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
Lines changed: 66 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,69 @@
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: out
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;
5143
using Microsoft.Extensions.Hosting;
5244
using Microsoft.Extensions.DependencyInjection;
5345
using {{packageName}}.Api;
5446
using {{packageName}}.Client;
5547
using {{packageName}}.Model;
48+
using Org.OpenAPITools.Extensions;
5649

5750
namespace YourProject
5851
{
5952
public class Program
6053
{
6154
public static async Task Main(string[] args)
6255
{
63-
var host = CreateHostBuilder(args).Build();{{#apiInfo}}{{#apis}}{{#-first}}
56+
var host = CreateHostBuilder(args).Build();
57+
{{#apiInfo}}
58+
{{#apis}}
59+
{{#-first}}
6460
var api = host.Services.GetRequiredService<{{interfacePrefix}}{{classname}}>();
6561
{{#operations}}
6662
{{#-first}}
6763
{{#operation}}
6864
{{#-first}}
69-
{{operationId}}ApiResponse apiResponse = await api.{{operationId}}Async("todo");
70-
{{#returnType}}{{{.}}}{{/returnType}}{{^returnType}}object{{/returnType}} model = apiResponse.Ok();
65+
{{interfacePrefix}}{{operationId}}ApiResponse apiResponse = await api.{{operationId}}Async("todo");
66+
{{#returnType}}{{{.}}}{{/returnType}}{{^returnType}}object{{/returnType}}{{nrt?}} model = apiResponse.Ok();
7167
{{/-first}}
7268
{{/operation}}
7369
{{/-first}}
@@ -78,16 +74,17 @@ namespace YourProject
7874
}
7975

8076
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
81-
.Configure{{apiName}}((context, options) =>
77+
.Configure{{apiName}}((context, services, options) =>
8278
{
8379
{{#authMethods}}
8480
{{#-first}}
85-
// the type of token here depends on the api security specifications
86-
ApiKeyToken token = new("<your token>", ClientUtils.ApiKeyHeader.Authorization);
81+
// The type of token here depends on the api security specifications
82+
// Available token types are ApiKeyToken, BasicToken, BearerToken, HttpSigningToken, and OAuthToken.
83+
BearerToken token = new("<your token>");
8784
options.AddTokens(token);
8885

8986
// optionally choose the method the tokens will be provided with, default is RateLimitProvider
90-
options.UseProvider<RateLimitProvider<ApiKeyToken>, ApiKeyToken>();
87+
options.UseProvider<RateLimitProvider<BearerToken>, BearerToken>();
9188

9289
{{/-first}}
9390
{{/authMethods}}
@@ -96,11 +93,17 @@ namespace YourProject
9693
// your custom converters if any
9794
});
9895

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
96+
options.Add{{apiName}}HttpClients(client =>
97+
{
98+
// client configuration
99+
}, builder =>
100+
{
101+
builder
102+
.AddRetryPolicy(2)
103+
.AddTimeoutPolicy(TimeSpan.FromSeconds(5))
104+
.AddCircuitBreakerPolicy(10, TimeSpan.FromSeconds(30));
105+
// add whatever middleware you prefer
106+
}
104107
);
105108
});
106109
}
@@ -110,136 +113,28 @@ namespace YourProject
110113
## Questions
111114

112115
- What about HttpRequest failures and retries?
113-
If supportsRetry is enabled, you can configure Polly in the ConfigureClients method.
116+
Configure Polly in the IHttpClientBuilder
114117
- How are tokens used?
115118
Tokens are provided by a TokenProvider class. The default is RateLimitProvider which will perform client side rate limiting.
116119
Other providers can be used with the UseProvider method.
117120
- 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.
121+
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.
119122
StatusCode and ReasonPhrase will contain information about the error.
120123
If the return type is T, then it will throw. If the return type is TOrDefault, it will return null.
121124
- 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}}
125+
Use the provided On and After partial methods in the api classes.
126+
127+
## Api Information
128+
- appName: {{appName}}
129+
- appVersion: {{appVersion}}
130+
- appDescription: {{appDescription}}
180131

181132
## Build
133+
This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
134+
182135
- SDK version: {{packageVersion}}
183136
{{^hideGenerationTimestamp}}
184137
- Build date: {{generatedDate}}
185138
{{/hideGenerationTimestamp}}
186139
- Generator version: {{generatorVersion}}
187140
- 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.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# Created with Openapi Generator
2+
See the project's [REAMDE](src/{{packageName}}/README.md)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# Created with Openapi Generator
2+
See the project's [REAMDE](src/Org.OpenAPITools/README.md)

0 commit comments

Comments
 (0)