Skip to content

Commit

Permalink
chore: updating templates for csharp sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
valmoz authored and fattureincloud-bot committed Sep 1, 2024
1 parent 0e9cfd0 commit 229df97
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 174 deletions.
247 changes: 125 additions & 122 deletions templates/openapi-generator/csharp/ApiClient.mustache

Large diffs are not rendered by default.

51 changes: 46 additions & 5 deletions templates/openapi-generator/csharp/Configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ using System.Text;
using System.Net.Http;
using System.Net.Security;
{{#useRestSharp}}
{{#hasOAuthMethods}}using {{packageName}}.Client.Auth;
{{/hasOAuthMethods}}
{{/useRestSharp}}

namespace {{packageName}}.Client
Expand Down Expand Up @@ -120,11 +122,11 @@ namespace {{packageName}}.Client
/// <summary>
/// Initializes a new instance of the <see cref="Configuration" /> class
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
[global::System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
public Configuration()
{
Proxy = null;
UserAgent = "{{httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{packageVersion}}/csharp{{/httpUserAgent}}";
UserAgent = WebUtility.UrlEncode("{{httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{packageVersion}}/csharp{{/httpUserAgent}}");
BasePath = "{{{basePath}}}";
DefaultHeaders = new {{^net35}}Concurrent{{/net35}}Dictionary<string, string>();
ApiKey = new {{^net35}}Concurrent{{/net35}}Dictionary<string, string>();
Expand Down Expand Up @@ -206,7 +208,7 @@ namespace {{packageName}}.Client
/// <summary>
/// Initializes a new instance of the <see cref="Configuration" /> class
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
[global::System.Diagnostics.CodeAnalysis.SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")]
public Configuration(
IDictionary<string, string> defaultHeaders,
IDictionary<string, string> apiKey,
Expand Down Expand Up @@ -247,7 +249,7 @@ namespace {{packageName}}.Client
/// <summary>
/// Gets or sets the base path for API access.
/// </summary>
public virtual string BasePath
public virtual string BasePath
{
get { return _basePath; }
set { _basePath = value; }
Expand Down Expand Up @@ -345,6 +347,38 @@ namespace {{packageName}}.Client
public virtual string AccessToken { get; set; }

{{#useRestSharp}}
{{#hasOAuthMethods}}
/// <summary>
/// Gets or sets the token URL for OAuth2 authentication.
/// </summary>
/// <value>The OAuth Token URL.</value>
public virtual string OAuthTokenUrl { get; set; }

/// <summary>
/// Gets or sets the client ID for OAuth2 authentication.
/// </summary>
/// <value>The OAuth Client ID.</value>
public virtual string OAuthClientId { get; set; }

/// <summary>
/// Gets or sets the client secret for OAuth2 authentication.
/// </summary>
/// <value>The OAuth Client Secret.</value>
public virtual string OAuthClientSecret { get; set; }

/// <summary>
/// Gets or sets the client scope for OAuth2 authentication.
/// </summary>
/// <value>The OAuth Client Scope.</value>
public virtual string{{nrt?}} OAuthScope { get; set; }

/// <summary>
/// Gets or sets the flow for OAuth2 authentication.
/// </summary>
/// <value>The OAuth Flow.</value>
public virtual OAuthFlow? OAuthFlow { get; set; }

{{/hasOAuthMethods}}
{{/useRestSharp}}
/// <summary>
/// Gets or sets the temporary folder path to store the files downloaded from the server.
Expand Down Expand Up @@ -600,7 +634,7 @@ namespace {{packageName}}.Client
set { _HttpSigningConfiguration = value; }
}
{{/hasHttpSignatureMethods}}

/// <summary>
/// Gets and Sets the RemoteCertificateValidationCallback
/// </summary>
Expand Down Expand Up @@ -679,6 +713,13 @@ namespace {{packageName}}.Client
Password = second.Password ?? first.Password,
AccessToken = second.AccessToken ?? first.AccessToken,
{{#useRestSharp}}
{{#hasOAuthMethods}}
OAuthTokenUrl = second.OAuthTokenUrl ?? first.OAuthTokenUrl,
OAuthClientId = second.OAuthClientId ?? first.OAuthClientId,
OAuthClientSecret = second.OAuthClientSecret ?? first.OAuthClientSecret,
OAuthScope = second.OAuthScope ?? first.OAuthScope,
OAuthFlow = second.OAuthFlow ?? first.OAuthFlow,
{{/hasOAuthMethods}}
{{/useRestSharp}}
{{#hasHttpSignatureMethods}}
HttpSigningConfiguration = second.HttpSigningConfiguration ?? first.HttpSigningConfiguration,
Expand Down
34 changes: 34 additions & 0 deletions templates/openapi-generator/csharp/IReadableConfiguration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
{{#useRestSharp}}
{{#hasOAuthMethods}}using {{packageName}}.Client.Auth;
{{/hasOAuthMethods}}
{{/useRestSharp}}

namespace {{packageName}}.Client
Expand All @@ -22,6 +24,38 @@ namespace {{packageName}}.Client
string AccessToken { get; }

{{#useRestSharp}}
{{#hasOAuthMethods}}
/// <summary>
/// Gets the OAuth token URL.
/// </summary>
/// <value>OAuth Token URL.</value>
string OAuthTokenUrl { get; }

/// <summary>
/// Gets the OAuth client ID.
/// </summary>
/// <value>OAuth Client ID.</value>
string OAuthClientId { get; }

/// <summary>
/// Gets the OAuth client secret.
/// </summary>
/// <value>OAuth Client Secret.</value>
string OAuthClientSecret { get; }

/// <summary>
/// Gets the OAuth token scope.
/// </summary>
/// <value>OAuth Token scope.</value>
string{{nrt?}} OAuthScope { get; }

/// <summary>
/// Gets the OAuth flow.
/// </summary>
/// <value>OAuth Flow.</value>
OAuthFlow? OAuthFlow { get; }

{{/hasOAuthMethods}}
{{/useRestSharp}}
/// <summary>
/// Gets the API key.
Expand Down
41 changes: 18 additions & 23 deletions templates/openapi-generator/csharp/README.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# FattureInCloud C# SDK

[![NuGet](https://img.shields.io/nuget/v/It.FattureInCloud.Sdk?color=g)](https://www.nuget.org/packages/It.FattureInCloud.Sdk) ![unit tests](https://github.com/fattureincloud/fattureincloud-csharp-sdk/actions/workflows/validate.yaml/badge.svg)
# {{packageName}} - the C# library for the {{appName}}

{{#appDescriptionWithNewLines}}
{{{.}}}
Expand All @@ -13,11 +11,10 @@ This C# SDK is automatically generated by the [OpenAPI Generator](https://openap
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/hideGenerationTimestamp}}
- Generator version: {{generatorVersion}}
- Build package: {{generatorClass}}


{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

<a id="frameworks-supported"></a>
Expand Down Expand Up @@ -65,13 +62,16 @@ NOTE: RestSharp for .Net Core creates a new socket for each api call, which can
{{/useRestSharp}}
<a id="installation"></a>
## Installation
{{#netStandard}}
Generate the DLL using your preferred tool (e.g. `dotnet build`)
{{/netStandard}}
{{^netStandard}}
Run the following command to generate the DLL
- [Mac/Linux] `/bin/sh build.sh`
- [Windows] `build.bat`
{{/netStandard}}

To install the bindings via [Nuget](https://www.nuget.org), run the following command:
```shell
dotnet add package It.FattureInCloud.Sdk
```

Then add the following namespaces to your project:
Then include the DLL (under the `bin` folder) in the C# project, and use the namespaces:
```csharp
using {{packageName}}.{{apiPackage}};
using {{packageName}}.Client;
Expand Down Expand Up @@ -240,14 +240,8 @@ No model defined in this package
<a id="documentation-for-authorization"></a>
## Documentation for Authorization

{{^authMethods}}
All endpoints do not require authorization.
{{/authMethods}}
{{#authMethods}}
{{#last}}
Authentication schemes defined for the API:
{{/last}}
{{/authMethods}}
{{^authMethods}}Endpoints do not require authorization.{{/authMethods}}
{{#hasAuthMethods}}Authentication schemes defined for the API:{{/hasAuthMethods}}
{{#authMethods}}
<a id="{{name}}"></a>
### {{name}}
Expand All @@ -260,13 +254,14 @@ Authentication schemes defined for the API:
{{/isBasicBasic}}
{{#isBasicBearer}}- **Type**: Bearer Authentication
{{/isBasicBearer}}
{{#isHttpSignature}}- **Type**: HTTP signature authentication
{{/isHttpSignature}}
{{#isOAuth}}- **Type**: OAuth
- **Flow**: {{flow}}
- **Authorization URL**: {{authorizationUrl}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}}
- **{{{scope}}}**: {{{description}}}
{{#scopes}} - {{scope}}: {{description}}
{{/scopes}}
{{/isOAuth}}

{{/authMethods}}
{{/authMethods}}
7 changes: 7 additions & 0 deletions templates/openapi-generator/csharp/RequestOptions.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ namespace {{packageName}}.Client
/// </summary>
public Object Data { get; set; }
{{#hasOAuthMethods}}
/// <summary>
/// If request should be authenticated with OAuth.
/// </summary>
public bool OAuth { get; set; }
{{/hasOAuthMethods}}
/// <summary>
/// Constructs a new instance of <see cref="RequestOptions"/>
/// </summary>
Expand Down
38 changes: 32 additions & 6 deletions templates/openapi-generator/csharp/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using System.Linq;
using System.Net;
using System.Net.Mime;
using {{packageName}}.Client;
{{#hasOAuthMethods}}using {{packageName}}.Client.Auth;
{{/hasOAuthMethods}}
{{#hasImport}}using {{packageName}}.{{modelPackage}};
{{/hasImport}}

Expand Down Expand Up @@ -80,7 +82,7 @@ namespace {{packageName}}.{{apiPackage}}
{{#isDeprecated}}
[Obsolete]
{{/isDeprecated}}
{{#returnType}}System.Threading.Tasks.Task<{{{.}}}>{{/returnType}}{{^returnType}}System.Threading.Tasks.Task{{/returnType}} {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
{{#returnType}}System.Threading.Tasks.Task<{{{.}}}>{{/returnType}}{{^returnType}}System.Threading.Tasks.Task{{/returnType}} {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken));

/// <summary>
/// {{summary}}
Expand All @@ -98,7 +100,7 @@ namespace {{packageName}}.{{apiPackage}}
{{#isDeprecated}}
[Obsolete]
{{/isDeprecated}}
System.Threading.Tasks.Task<ApiResponse<{{{returnType}}}{{^returnType}}Object{{/returnType}}>> {{operationId}}WithHttpInfoAsync({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
System.Threading.Tasks.Task<ApiResponse<{{{returnType}}}{{^returnType}}Object{{/returnType}}>> {{operationId}}WithHttpInfoAsync({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken));
{{/operation}}
#endregion Asynchronous Operations
}
Expand Down Expand Up @@ -448,7 +450,19 @@ namespace {{packageName}}.{{apiPackage}}
// oauth required
if (!localVarRequestOptions.HeaderParameters.ContainsKey("Authorization"))
{
localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
if (!string.IsNullOrEmpty(this.Configuration.AccessToken))
{
localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
}
{{#hasOAuthMethods}}
else if (!string.IsNullOrEmpty(this.Configuration.OAuthTokenUrl) &&
!string.IsNullOrEmpty(this.Configuration.OAuthClientId) &&
!string.IsNullOrEmpty(this.Configuration.OAuthClientSecret) &&
this.Configuration.OAuthFlow != null)
{
localVarRequestOptions.OAuth = true;
}
{{/hasOAuthMethods}}
}
{{/isOAuth}}
{{#isHttpSignature}}
Expand Down Expand Up @@ -498,7 +512,7 @@ namespace {{packageName}}.{{apiPackage}}
{{#isDeprecated}}
[Obsolete]
{{/isDeprecated}}
{{#returnType}}public async System.Threading.Tasks.Task<{{{.}}}>{{/returnType}}{{^returnType}}public async System.Threading.Tasks.Task{{/returnType}} {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{{#returnType}}public async System.Threading.Tasks.Task<{{{.}}}>{{/returnType}}{{^returnType}}public async System.Threading.Tasks.Task{{/returnType}} {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken))
{
{{#returnType}}{{packageName}}.Client.ApiResponse<{{{returnType}}}> localVarResponse = await {{operationId}}WithHttpInfoAsync({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}operationIndex, cancellationToken).ConfigureAwait(false);
return localVarResponse.Data;{{/returnType}}{{^returnType}}await {{operationId}}WithHttpInfoAsync({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}operationIndex, cancellationToken).ConfigureAwait(false);{{/returnType}}
Expand All @@ -517,7 +531,7 @@ namespace {{packageName}}.{{apiPackage}}
{{#isDeprecated}}
[Obsolete]
{{/isDeprecated}}
public async System.Threading.Tasks.Task<{{packageName}}.Client.ApiResponse<{{{returnType}}}{{^returnType}}Object{{/returnType}}>> {{operationId}}WithHttpInfoAsync({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
public async System.Threading.Tasks.Task<{{packageName}}.Client.ApiResponse<{{{returnType}}}{{^returnType}}Object{{/returnType}}>> {{operationId}}WithHttpInfoAsync({{#allParams}}{{{dataType}}} {{paramName}}{{^required}}{{#optionalMethodArgument}} = default({{{dataType}}}){{/optionalMethodArgument}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken))
{
{{#allParams}}
{{#required}}
Expand Down Expand Up @@ -728,7 +742,19 @@ namespace {{packageName}}.{{apiPackage}}
// oauth required
if (!localVarRequestOptions.HeaderParameters.ContainsKey("Authorization"))
{
localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
if (!string.IsNullOrEmpty(this.Configuration.AccessToken))
{
localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
}
{{#hasOAuthMethods}}
else if (!string.IsNullOrEmpty(this.Configuration.OAuthTokenUrl) &&
!string.IsNullOrEmpty(this.Configuration.OAuthClientId) &&
!string.IsNullOrEmpty(this.Configuration.OAuthClientSecret) &&
this.Configuration.OAuthFlow != null)
{
localVarRequestOptions.OAuth = true;
}
{{/hasOAuthMethods}}
}
{{/isOAuth}}
{{#isHttpSignature}}
Expand Down
2 changes: 2 additions & 0 deletions templates/openapi-generator/csharp/modelGeneric.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@
{{^conditionalSerialization}}
[DataMember(Name = "{{baseName}}"{{#required}}, IsRequired = true{{/required}}, EmitDefaultValue = {{#vendorExtensions.x-emit-default-value}}true{{/vendorExtensions.x-emit-default-value}}{{^vendorExtensions.x-emit-default-value}}{{#required}}true{{/required}}{{^required}}{{#isBoolean}}true{{/isBoolean}}{{^isBoolean}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}}{{/isBoolean}}{{/required}}{{/vendorExtensions.x-emit-default-value}})]
{{#isDate}}
{{^supportsDateOnly}}
[JsonConverter(typeof(OpenAPIDateConverter))]
{{/supportsDateOnly}}
{{/isDate}}
{{#deprecated}}
[Obsolete]
Expand Down
Loading

0 comments on commit 229df97

Please sign in to comment.