diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/AfterOperationDefaultImplementation.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/AfterOperationDefaultImplementation.mustache
new file mode 100644
index 00000000000..5db1afeab5e
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/AfterOperationDefaultImplementation.mustache
@@ -0,0 +1 @@
+ Logger.LogInformation("{0,-9} | {1} | {3}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path);
\ No newline at end of file
diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/ApiResponse`1.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/ApiResponse`1.mustache
index 03b9256153c..20823fd8fc1 100644
--- a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/ApiResponse`1.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/ApiResponse`1.mustache
@@ -28,7 +28,7 @@ namespace {{packageName}}.{{clientPackage}}
HttpStatusCode StatusCode { get; }
///
- /// The raw content of this response
+ /// The raw content of this response.
///
string RawContent { get; }
@@ -36,6 +36,16 @@ namespace {{packageName}}.{{clientPackage}}
/// The DateTime when the request was retrieved.
///
DateTime DownloadedAt { get; }
+
+ ///
+ /// The path used when making the request.
+ ///
+ string Path { get; }
+
+ ///
+ /// The Uri used when making the request.
+ ///
+ Uri{{nrt?}} RequestUri { get; }
}
///
@@ -82,6 +92,21 @@ namespace {{packageName}}.{{clientPackage}}
///
public DateTime DownloadedAt { get; } = DateTime.UtcNow;
+ ///
+ /// The DateTime when the request was sent.
+ ///
+ public DateTime RequestedAt { get; }
+
+ ///
+ /// The path used when making the request.
+ ///
+ public string Path { get; }
+
+ ///
+ /// The Uri used when making the request.
+ ///
+ public Uri{{nrt?}} RequestUri { get; }
+
///
/// The JsonSerialzierOptions
///
@@ -93,14 +118,19 @@ namespace {{packageName}}.{{clientPackage}}
///
///
///
+ ///
+ ///
///
- public ApiResponse(System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, System.Text.Json.JsonSerializerOptions jsonSerializerOptions)
+ public ApiResponse(System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions)
{
StatusCode = httpResponseMessage.StatusCode;
Headers = httpResponseMessage.Headers;
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
ReasonPhrase = httpResponseMessage.ReasonPhrase;
RawContent = rawContent;
+ Path = path;
+ RequestUri = httpRequestMessage.RequestUri;
+ RequestedAt = requestedAt;
_jsonSerializerOptions = jsonSerializerOptions;
OnCreated(httpRequestMessage, httpResponseMessage);
}
diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/OnErrorDefaultImplementation.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/OnErrorDefaultImplementation.mustache
new file mode 100644
index 00000000000..bdefb67c6e4
--- /dev/null
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/OnErrorDefaultImplementation.mustache
@@ -0,0 +1 @@
+ Logger.LogError(exception, "An error occurred while sending the request to the server.");
\ No newline at end of file
diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/api.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/api.mustache
index bdafdaa9470..a3d24e5b7ca 100644
--- a/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/api.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/api.mustache
@@ -124,15 +124,6 @@ namespace {{packageName}}.{{apiPackage}}
HttpSignatureTokenProvider = httpSignatureTokenProvider;{{/hasHttpSignatureMethods}}{{#hasOAuthMethods}}
OauthTokenProvider = oauthTokenProvider;{{/hasOAuthMethods}}
}
-
- ///
- /// Logs the api response
- ///
- ///
- protected virtual void OnApiResponded(ApiResponseEventArgs args)
- {
- Logger.LogInformation("{0,-9} | {1} | {3}", (args.ReceivedAt - args.RequestedAt).TotalSeconds, args.HttpStatus, args.Path);
- }
{{#operation}}
{{#allParams}}
@@ -186,24 +177,47 @@ namespace {{packageName}}.{{apiPackage}}
{{#allParams}}
///
{{/allParams}}
- protected virtual void After{{operationId}}({{#lambda.joinWithComma}}ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}object{{/returnType}}> apiResponseLocalVar {{#allParams}}{{#requiredAndNotNullable}}{{#lambda.required}}{{{dataType}}}{{/lambda.required}} {{paramName}} {{/requiredAndNotNullable}}{{^requiredAndNotNullable}}{{#lambda.optional}}{{{dataType}}}{{/lambda.optional}} {{paramName}} {{/requiredAndNotNullable}}{{/allParams}}{{/lambda.joinWithComma}})
+ private void After{{operationId}}DefaultImplementation({{#lambda.joinWithComma}}ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}object{{/returnType}}> apiResponseLocalVar {{#allParams}}{{#requiredAndNotNullable}}{{#lambda.required}}{{{dataType}}}{{/lambda.required}} {{paramName}} {{/requiredAndNotNullable}}{{^requiredAndNotNullable}}{{#lambda.optional}}{{{dataType}}}{{/lambda.optional}} {{paramName}} {{/requiredAndNotNullable}}{{/allParams}}{{/lambda.joinWithComma}})
{
+{{>AfterOperationDefaultImplementation}}
+ After{{operationId}}({{#lambda.joinWithComma}}apiResponseLocalVar {{#allParams}}{{paramName}} {{/allParams}}{{/lambda.joinWithComma}});
}
///
/// Processes the server response
///
+ ///
+ {{#allParams}}
+ ///
+ {{/allParams}}
+ partial void After{{operationId}}({{#lambda.joinWithComma}}ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}object{{/returnType}}> apiResponseLocalVar {{#allParams}}{{#requiredAndNotNullable}}{{#lambda.required}}{{{dataType}}}{{/lambda.required}} {{paramName}} {{/requiredAndNotNullable}}{{^requiredAndNotNullable}}{{#lambda.optional}}{{{dataType}}}{{/lambda.optional}} {{paramName}} {{/requiredAndNotNullable}}{{/allParams}}{{/lambda.joinWithComma}});
+
+ ///
+ /// Logs exceptions that occur while retrieving the server response
+ ///
///
///
///
{{#allParams}}
///
{{/allParams}}
- protected virtual void OnError{{operationId}}({{#lambda.joinWithComma}}Exception exception string pathFormat string path {{#allParams}}{{#requiredAndNotNullable}}{{#lambda.required}}{{{dataType}}}{{/lambda.required}} {{paramName}} {{/requiredAndNotNullable}}{{^requiredAndNotNullable}}{{#lambda.optional}}{{{dataType}}}{{/lambda.optional}} {{paramName}} {{/requiredAndNotNullable}}{{/allParams}}{{/lambda.joinWithComma}})
+ private void OnError{{operationId}}DefaultImplementation({{#lambda.joinWithComma}}Exception exception string pathFormat string path {{#allParams}}{{#requiredAndNotNullable}}{{#lambda.required}}{{{dataType}}}{{/lambda.required}} {{paramName}} {{/requiredAndNotNullable}}{{^requiredAndNotNullable}}{{#lambda.optional}}{{{dataType}}}{{/lambda.optional}} {{paramName}} {{/requiredAndNotNullable}}{{/allParams}}{{/lambda.joinWithComma}})
{
- Logger.LogError(exception, "An error occurred while sending the request to the server.");
+{{>OnErrorDefaultImplementation}}
+ OnError{{operationId}}({{#lambda.joinWithComma}}exception pathFormat path {{#allParams}}{{paramName}} {{/allParams}}{{/lambda.joinWithComma}});
}
+ ///
+ /// A partial method that gives developers a way to provide customized exception handling
+ ///
+ ///
+ ///
+ ///
+ {{#allParams}}
+ ///
+ {{/allParams}}
+ partial void OnError{{operationId}}({{#lambda.joinWithComma}}Exception exception string pathFormat string path {{#allParams}}{{#requiredAndNotNullable}}{{#lambda.required}}{{{dataType}}}{{/lambda.required}} {{paramName}} {{/requiredAndNotNullable}}{{^requiredAndNotNullable}}{{#lambda.optional}}{{{dataType}}}{{/lambda.optional}} {{paramName}} {{/requiredAndNotNullable}}{{/allParams}}{{/lambda.joinWithComma}});
+
///
/// {{summary}} {{notes}}
///
@@ -477,13 +491,11 @@ namespace {{packageName}}.{{apiPackage}}
using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
{
- OnApiResponded(new ApiResponseEventArgs(requestedAtLocalVar, DateTime.UtcNow, httpResponseMessageLocalVar.StatusCode, "{{path}}", uriBuilderLocalVar.Path));
-
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync({{#net60OrLater}}cancellationToken{{/net60OrLater}}).ConfigureAwait(false);
- ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}object{{/returnType}}> apiResponseLocalVar = new ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}object{{/returnType}}>(httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, _jsonSerializerOptions);
+ ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}object{{/returnType}}> apiResponseLocalVar = new ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}object{{/returnType}}>(httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "{{path}}", requestedAtLocalVar, _jsonSerializerOptions);
- After{{operationId}}({{#lambda.joinWithComma}}apiResponseLocalVar {{#allParams}}{{paramName}} {{/allParams}}{{/lambda.joinWithComma}});
+ After{{operationId}}DefaultImplementation({{#lambda.joinWithComma}}apiResponseLocalVar {{#allParams}}{{paramName}} {{/allParams}}{{/lambda.joinWithComma}});
{{#authMethods}}
if (apiResponseLocalVar.StatusCode == (HttpStatusCode) 429)
@@ -497,7 +509,7 @@ namespace {{packageName}}.{{apiPackage}}
}
catch(Exception e)
{
- OnError{{operationId}}({{#lambda.joinWithComma}}e "{{path}}" uriBuilderLocalVar.Path {{#allParams}}{{paramName}} {{/allParams}}{{/lambda.joinWithComma}});
+ OnError{{operationId}}DefaultImplementation({{#lambda.joinWithComma}}e "{{path}}" uriBuilderLocalVar.Path {{#allParams}}{{paramName}} {{/allParams}}{{/lambda.joinWithComma}});
throw;
}
{{/lambda.trimLineBreaks}}
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/AnotherFakeApi.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/AnotherFakeApi.cs
index 3f531b66344..3480bac3400 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/AnotherFakeApi.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/AnotherFakeApi.cs
@@ -119,15 +119,6 @@ namespace Org.OpenAPITools.Api
OauthTokenProvider = oauthTokenProvider;
}
- ///
- /// Logs the api response
- ///
- ///
- protected virtual void OnApiResponded(ApiResponseEventArgs args)
- {
- Logger.LogInformation("{0,-9} | {1} | {3}", (args.ReceivedAt - args.RequestedAt).TotalSeconds, args.HttpStatus, args.Path);
- }
-
partial void FormatCall123TestSpecialTags(ModelClient modelClient);
///
@@ -152,22 +143,41 @@ namespace Org.OpenAPITools.Api
///
///
///
- protected virtual void AfterCall123TestSpecialTags(ApiResponse apiResponseLocalVar, ModelClient modelClient)
+ private void AfterCall123TestSpecialTagsDefaultImplementation(ApiResponse apiResponseLocalVar, ModelClient modelClient)
{
+ Logger.LogInformation("{0,-9} | {1} | {3}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path);
+ AfterCall123TestSpecialTags(apiResponseLocalVar, modelClient);
}
///
/// Processes the server response
///
+ ///
+ ///
+ partial void AfterCall123TestSpecialTags(ApiResponse apiResponseLocalVar, ModelClient modelClient);
+
+ ///
+ /// Logs exceptions that occur while retrieving the server response
+ ///
///
///
///
///
- protected virtual void OnErrorCall123TestSpecialTags(Exception exception, string pathFormat, string path, ModelClient modelClient)
+ private void OnErrorCall123TestSpecialTagsDefaultImplementation(Exception exception, string pathFormat, string path, ModelClient modelClient)
{
Logger.LogError(exception, "An error occurred while sending the request to the server.");
+ OnErrorCall123TestSpecialTags(exception, pathFormat, path, modelClient);
}
+ ///
+ /// A partial method that gives developers a way to provide customized exception handling
+ ///
+ ///
+ ///
+ ///
+ ///
+ partial void OnErrorCall123TestSpecialTags(Exception exception, string pathFormat, string path, ModelClient modelClient);
+
///
/// To test special tags To test special tags and operation ID starting with number
///
@@ -240,13 +250,11 @@ namespace Org.OpenAPITools.Api
using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
{
- OnApiResponded(new ApiResponseEventArgs(requestedAtLocalVar, DateTime.UtcNow, httpResponseMessageLocalVar.StatusCode, "/another-fake/dummy", uriBuilderLocalVar.Path));
-
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
- ApiResponse apiResponseLocalVar = new ApiResponse(httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, _jsonSerializerOptions);
+ ApiResponse apiResponseLocalVar = new ApiResponse(httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/another-fake/dummy", requestedAtLocalVar, _jsonSerializerOptions);
- AfterCall123TestSpecialTags(apiResponseLocalVar, modelClient);
+ AfterCall123TestSpecialTagsDefaultImplementation(apiResponseLocalVar, modelClient);
return apiResponseLocalVar;
}
@@ -254,7 +262,7 @@ namespace Org.OpenAPITools.Api
}
catch(Exception e)
{
- OnErrorCall123TestSpecialTags(e, "/another-fake/dummy", uriBuilderLocalVar.Path, modelClient);
+ OnErrorCall123TestSpecialTagsDefaultImplementation(e, "/another-fake/dummy", uriBuilderLocalVar.Path, modelClient);
throw;
}
}
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/DefaultApi.cs
index 4fd131b66e8..0883057e578 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/DefaultApi.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/DefaultApi.cs
@@ -162,33 +162,41 @@ namespace Org.OpenAPITools.Api
}
///
- /// Logs the api response
+ /// Processes the server response
///
- ///
- protected virtual void OnApiResponded(ApiResponseEventArgs args)
+ ///
+ private void AfterFooGetDefaultImplementation(ApiResponse apiResponseLocalVar)
{
- Logger.LogInformation("{0,-9} | {1} | {3}", (args.ReceivedAt - args.RequestedAt).TotalSeconds, args.HttpStatus, args.Path);
+ Logger.LogInformation("{0,-9} | {1} | {3}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path);
+ AfterFooGet(apiResponseLocalVar);
}
///
/// Processes the server response
///
///
- protected virtual void AfterFooGet(ApiResponse apiResponseLocalVar)
- {
- }
+ partial void AfterFooGet(ApiResponse apiResponseLocalVar);
///
- /// Processes the server response
+ /// Logs exceptions that occur while retrieving the server response
///
///
///
///
- protected virtual void OnErrorFooGet(Exception exception, string pathFormat, string path)
+ private void OnErrorFooGetDefaultImplementation(Exception exception, string pathFormat, string path)
{
Logger.LogError(exception, "An error occurred while sending the request to the server.");
+ OnErrorFooGet(exception, pathFormat, path);
}
+ ///
+ /// A partial method that gives developers a way to provide customized exception handling
+ ///
+ ///
+ ///
+ ///
+ partial void OnErrorFooGet(Exception exception, string pathFormat, string path);
+
///
///
///
@@ -242,13 +250,11 @@ namespace Org.OpenAPITools.Api
using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
{
- OnApiResponded(new ApiResponseEventArgs(requestedAtLocalVar, DateTime.UtcNow, httpResponseMessageLocalVar.StatusCode, "/foo", uriBuilderLocalVar.Path));
-
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
- ApiResponse apiResponseLocalVar = new ApiResponse(httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, _jsonSerializerOptions);
+ ApiResponse apiResponseLocalVar = new ApiResponse(httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/foo", requestedAtLocalVar, _jsonSerializerOptions);
- AfterFooGet(apiResponseLocalVar);
+ AfterFooGetDefaultImplementation(apiResponseLocalVar);
return apiResponseLocalVar;
}
@@ -256,7 +262,7 @@ namespace Org.OpenAPITools.Api
}
catch(Exception e)
{
- OnErrorFooGet(e, "/foo", uriBuilderLocalVar.Path);
+ OnErrorFooGetDefaultImplementation(e, "/foo", uriBuilderLocalVar.Path);
throw;
}
}
@@ -285,22 +291,41 @@ namespace Org.OpenAPITools.Api
///
///
///
- protected virtual void AfterGetCountry(ApiResponse