Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking templates for csharp SDK #883

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions templates/openapi-generator/csharp/ApiClient.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ using RestSharpMethod = RestSharp.Method;
{{#supportsRetry}}
using Polly;
{{/supportsRetry}}
{{#hasOAuthMethods}}
using {{packageName}}.Client.Auth;
{{/hasOAuthMethods}}

namespace {{packageName}}.Client
{
Expand Down Expand Up @@ -359,8 +362,7 @@ namespace {{packageName}}.Client
request.RequestFormat = DataFormat.Json;
}

request.AddParameter("application/json", JsonConvert.SerializeObject(options.Data), ParameterType.RequestBody);
request.AddHeader("User-Agent", configuration.UserAgent);
request.AddJsonBody(options.Data);
}
}

Expand Down Expand Up @@ -447,10 +449,27 @@ namespace {{packageName}}.Client
CookieContainer = cookies,
MaxTimeout = configuration.Timeout,
Proxy = configuration.Proxy,
UserAgent = configuration.UserAgent,
UseDefaultCredentials = configuration.UseDefaultCredentials,
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
};

{{#hasOAuthMethods}}
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
configuration.OAuthFlow != null)
{
clientOptions.Authenticator = new OAuthAuthenticator(
configuration.OAuthTokenUrl,
configuration.OAuthClientId,
configuration.OAuthClientSecret,
configuration.OAuthFlow,
SerializerSettings,
configuration);
}

{{/hasOAuthMethods}}
using (RestClient client = new RestClient(clientOptions,
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
{
Expand All @@ -470,6 +489,7 @@ namespace {{packageName}}.Client
{
response = client.Execute<T>(request);
}

// if the response type is oneOf/anyOf, call FromJSON to deserialize the data
if (typeof({{{packageName}}}.{{modelPackage}}.AbstractOpenAPISchema).IsAssignableFrom(typeof(T)))
{
Expand Down Expand Up @@ -543,9 +563,27 @@ namespace {{packageName}}.Client
ClientCertificates = configuration.ClientCertificates,
MaxTimeout = configuration.Timeout,
Proxy = configuration.Proxy,
UseDefaultCredentials = configuration.UseDefaultCredentials
UserAgent = configuration.UserAgent,
UseDefaultCredentials = configuration.UseDefaultCredentials,
RemoteCertificateValidationCallback = configuration.RemoteCertificateValidationCallback
};

{{#hasOAuthMethods}}
if (!string.IsNullOrEmpty(configuration.OAuthTokenUrl) &&
!string.IsNullOrEmpty(configuration.OAuthClientId) &&
!string.IsNullOrEmpty(configuration.OAuthClientSecret) &&
configuration.OAuthFlow != null)
{
clientOptions.Authenticator = new OAuthAuthenticator(
configuration.OAuthTokenUrl,
configuration.OAuthClientId,
configuration.OAuthClientSecret,
configuration.OAuthFlow,
SerializerSettings,
configuration);
}

{{/hasOAuthMethods}}
using (RestClient client = new RestClient(clientOptions,
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
{
Expand Down
40 changes: 37 additions & 3 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 @@ -124,7 +126,7 @@ namespace {{packageName}}.Client
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 @@ -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,32 @@ 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 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 +628,7 @@ namespace {{packageName}}.Client
set { _HttpSigningConfiguration = value; }
}
{{/hasHttpSignatureMethods}}

/// <summary>
/// Gets and Sets the RemoteCertificateValidationCallback
/// </summary>
Expand Down Expand Up @@ -679,6 +707,12 @@ 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,
OAuthFlow = second.OAuthFlow ?? first.OAuthFlow,
{{/hasOAuthMethods}}
{{/useRestSharp}}
{{#hasHttpSignatureMethods}}
HttpSigningConfiguration = second.HttpSigningConfiguration ?? first.HttpSigningConfiguration,
Expand Down
28 changes: 28 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,32 @@ 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 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
Loading