diff --git a/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache b/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache index 91ea70055b06f..eb4b63f578f91 100644 --- a/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache @@ -14,9 +14,9 @@ using System.Text; using System.Threading; using System.Text.RegularExpressions; using System.Threading.Tasks; -{{^net60OrLater}} +#if !NET6_0_OR_GREATER using System.Web; -{{/net60OrLater}} +#endif using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using RestSharp; diff --git a/modules/openapi-generator/src/main/resources/csharp/ApiClient.v790.mustache b/modules/openapi-generator/src/main/resources/csharp/ApiClient.v790.mustache index a63d1c2be9c18..f47705a8b7f11 100644 --- a/modules/openapi-generator/src/main/resources/csharp/ApiClient.v790.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/ApiClient.v790.mustache @@ -14,9 +14,9 @@ using System.Text; using System.Threading; using System.Text.RegularExpressions; using System.Threading.Tasks; -{{^net60OrLater}} +#if !NET6_0_OR_GREATER using System.Web; -{{/net60OrLater}} +#endif using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using RestSharp; diff --git a/modules/openapi-generator/src/main/resources/csharp/ClientUtils.mustache b/modules/openapi-generator/src/main/resources/csharp/ClientUtils.mustache index 5c42d2e4fe338..84e8177e219cc 100644 --- a/modules/openapi-generator/src/main/resources/csharp/ClientUtils.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/ClientUtils.mustache @@ -114,14 +114,14 @@ namespace {{packageName}}.Client // 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((configuration ?? GlobalConfiguration.Instance).DateTimeFormat); -{{#net60OrLater}} +#if NET6_0_OR_GREATER if (obj is DateOnly dateOnly) // 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-15 return dateOnly.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat); -{{/net60OrLater}} +#endif if (obj is bool boolean) return boolean ? "true" : "false"; if (obj is ICollection collection) { diff --git a/modules/openapi-generator/src/main/resources/csharp/HttpSigningConfiguration.mustache b/modules/openapi-generator/src/main/resources/csharp/HttpSigningConfiguration.mustache index faca675944a38..823d9849a698f 100644 --- a/modules/openapi-generator/src/main/resources/csharp/HttpSigningConfiguration.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/HttpSigningConfiguration.mustache @@ -344,7 +344,7 @@ namespace {{packageName}}.Client /// ECDSA signature private string GetECDSASignature(byte[] dataToSign) { - {{#net60OrLater}} +#if NET6_0_OR_GREATER if (!File.Exists(KeyFilePath) && string.IsNullOrEmpty(KeyString)) { throw new Exception("No API key has been provided."); @@ -382,10 +382,10 @@ namespace {{packageName}}.Client var signedString = System.Convert.ToBase64String(derBytes); return signedString; - {{/net60OrLater}} - {{^net60OrLater}} +#endif +#if !NET6_0_OR_GREATER throw new Exception("ECDSA signing is supported only on NETCOREAPP3_0 and above"); - {{/net60OrLater}} +#endif } /// diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ApiResponse`1.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ApiResponse`1.mustache index 1b12e4173931c..634af2d43e7cf 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ApiResponse`1.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ApiResponse`1.mustache @@ -164,7 +164,11 @@ namespace {{packageName}}.{{clientPackage}} /// /// /// - bool Try{{.}}({{#net60OrLater}}[NotNullWhen(true)]{{/net60OrLater}}out TType{{nrt?}} result); + bool Try{{.}}( +#if NET6_0_OR_GREATER + [NotNullWhen(true)] +#endif + out TType{{nrt?}} result); } {{/x-http-statuses-with-return}} } diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/AsModel.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/AsModel.mustache index 96bedfa464ecc..dd7ce036f3ffd 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/AsModel.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/AsModel.mustache @@ -1,4 +1,9 @@ // This logic may be modified with the AsModel.mustache template return Is{{vendorExtensions.x-http-status}} ? System.Text.Json.JsonSerializer.Deserialize<{{#isModel}}{{^containerType}}{{packageName}}.{{modelPackage}}.{{/containerType}}{{/isModel}}{{{dataType}}}>(RawContent, _jsonSerializerOptions) - : {{#net60OrLater}}null{{/net60OrLater}}{{^net60OrLater}}default{{/net60OrLater}}; + : +#if NET6_0_OR_GREATER + null +#else + default +#endif; diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ClientUtils.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ClientUtils.mustache index 03d0daf819868..a1f072de3f06c 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ClientUtils.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ClientUtils.mustache @@ -107,7 +107,15 @@ using System.Runtime.CompilerServices; /// /// /// - public static bool TryDeserialize(string json, JsonSerializerOptions options, {{#net60OrLater}}[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] {{/net60OrLater}}out T{{#nrt}}{{#net60OrLater}}?{{/net60OrLater}}{{/nrt}} result) + public static bool TryDeserialize(string json, JsonSerializerOptions options, +#if NET6_0_OR_GREATER + [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out T{{#nrt}} +#if NET6_0_OR_GREATER + ? +#endif + {{/nrt}} result) { try { @@ -129,7 +137,15 @@ using System.Runtime.CompilerServices; /// /// /// - public static bool TryDeserialize(ref Utf8JsonReader reader, JsonSerializerOptions options, {{#net60OrLater}}[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] {{/net60OrLater}}out T{{#nrt}}{{#net60OrLater}}?{{/net60OrLater}}{{/nrt}} result) + public static bool TryDeserialize(ref Utf8JsonReader reader, JsonSerializerOptions options, +#if NET6_0_OR_GREATER + [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] +#endif + out T{{#nrt}} +#if NET6_0_OR_GREATER + ? +#endif + {{/nrt}} result) { try { @@ -176,10 +192,10 @@ using System.Runtime.CompilerServices; // 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); - {{#net60OrLater}} +#if NET6_0_OR_GREATER if (obj is DateOnly dateOnly) return dateOnly.ToString(format); - {{/net60OrLater}} +#endif if (obj is bool boolean) return boolean ? "true" diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/HostConfiguration.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/HostConfiguration.mustache index 1333f0e67ea25..cd8f3ce98d31d 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/HostConfiguration.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/HostConfiguration.mustache @@ -54,7 +54,7 @@ namespace {{packageName}}.{{clientPackage}} {{/isEnum}} {{/model}} {{/models}} - JsonSerializerOptionsProvider jsonSerializerOptionsProvider = new{{^net60OrLater}} JsonSerializerOptionsProvider{{/net60OrLater}}(_jsonOptions); + JsonSerializerOptionsProvider jsonSerializerOptionsProvider = new JsonSerializerOptionsProvider(_jsonOptions); _services.AddSingleton(jsonSerializerOptionsProvider); {{#useSourceGeneration}} diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/HttpSigningConfiguration.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/HttpSigningConfiguration.mustache index 5e0f7739df06f..273b70a379be4 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/HttpSigningConfiguration.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/HttpSigningConfiguration.mustache @@ -272,7 +272,7 @@ namespace {{packageName}}.{{clientPackage}} /// private string GetECDSASignature(byte[] dataToSign) { - {{#net60OrLater}} +#if NET6_0_OR_GREATER if (!File.Exists(KeyFilePath)) throw new Exception("key file path does not exist."); @@ -310,10 +310,10 @@ namespace {{packageName}}.{{clientPackage}} var signedString = System.Convert.ToBase64String(derBytes); return signedString; - {{/net60OrLater}} - {{^net60OrLater}} +#endif +#if !NET6_0_OR_GREATER throw new Exception("ECDSA signing is supported only on NETCOREAPP3_0 and above"); - {{/net60OrLater}} +#endif } private byte[] ConvertToECDSAANS1Format(byte[] signedBytes) diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api.mustache index b33115f0a5e12..25abe72ca7376 100644 --- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api.mustache @@ -562,7 +562,11 @@ namespace {{packageName}}.{{apiPackage}} tokenBaseLocalVars.Add(httpSignatureTokenLocalVar{{-index}}); if (httpRequestMessageLocalVar.Content != null) { - string requestBodyLocalVar = await httpRequestMessageLocalVar.Content.ReadAsStringAsync({{#net60OrLater}}cancellationToken{{/net60OrLater}}).ConfigureAwait(false); + string requestBodyLocalVar = await httpRequestMessageLocalVar.Content.ReadAsStringAsync( +#if NET6_0_OR_GREATER + cancellationToken +#endif + ).ConfigureAwait(false); httpSignatureTokenLocalVar{{-index}}.UseInHeader(httpRequestMessageLocalVar, requestBodyLocalVar, cancellationToken); } @@ -607,23 +611,25 @@ namespace {{packageName}}.{{apiPackage}} httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptLocalVar)); {{/-first}} {{/produces}} - {{#net60OrLater}} - +#if NET6_0_OR_GREATER httpRequestMessageLocalVar.Method = HttpMethod.{{#lambda.titlecase}}{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}{{/lambda.titlecase}}; - {{/net60OrLater}} - {{^net60OrLater}} +#else httpRequestMessageLocalVar.Method = new HttpMethod("{{#lambda.uppercase}}{{httpMethod}}{{/lambda.uppercase}}"); - {{/net60OrLater}} +#endif DateTime requestedAtLocalVar = DateTime.UtcNow; using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false)) { - string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync({{#net60OrLater}}cancellationToken{{/net60OrLater}}).ConfigureAwait(false); + string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync( +#if NET6_0_OR_GREATER + cancellationToken +#endif + ).ConfigureAwait(false); ILogger<{{#vendorExtensions.x-duplicates}}{{.}}.{{/vendorExtensions.x-duplicates}}{{operationId}}ApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<{{#vendorExtensions.x-duplicates}}{{.}}.{{/vendorExtensions.x-duplicates}}{{operationId}}ApiResponse>(); - {{#vendorExtensions.x-duplicates}}{{.}}.{{/vendorExtensions.x-duplicates}}{{operationId}}ApiResponse apiResponseLocalVar = new{{^net60OrLater}} {{operationId}}ApiResponse{{/net60OrLater}}(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "{{{path}}}", requestedAtLocalVar, _jsonSerializerOptions); + {{#vendorExtensions.x-duplicates}}{{.}}.{{/vendorExtensions.x-duplicates}}{{operationId}}ApiResponse apiResponseLocalVar = new {{operationId}}ApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "{{{path}}}", requestedAtLocalVar, _jsonSerializerOptions); After{{operationId}}DefaultImplementation({{#lambda.joinWithComma}}apiResponseLocalVar {{#allParams}}{{paramName}} {{/allParams}}{{/lambda.joinWithComma}}); @@ -761,7 +767,11 @@ namespace {{packageName}}.{{apiPackage}} /// /// /// - public bool Try{{vendorExtensions.x-http-status}}({{#net60OrLater}}[NotNullWhen(true)]{{/net60OrLater}}out {{#isModel}}{{^containerType}}{{packageName}}.{{modelPackage}}.{{/containerType}}{{/isModel}}{{{dataType}}}{{#nrt}}?{{/nrt}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} result) + public bool Try{{vendorExtensions.x-http-status}}( +#if NET6_0_OR_GREATER + [NotNullWhen(true)] +#endif + out {{#isModel}}{{^containerType}}{{packageName}}.{{modelPackage}}.{{/containerType}}{{/isModel}}{{{dataType}}}{{#nrt}}?{{/nrt}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} result) { result = null;