-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi-generator-templates.patch
More file actions
302 lines (283 loc) · 13.7 KB
/
openapi-generator-templates.patch
File metadata and controls
302 lines (283 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
diff --git a/templates/ApiClient.mustache b/templates/ApiClient.mustache
index 3e77467..a39c718 100644
--- a/templates/ApiClient.mustache
+++ b/templates/ApiClient.mustache
@@ -30,6 +30,8 @@ using Polly;
using {{packageName}}.Client.Auth;
{{/hasOAuthMethods}}
using {{packageName}}.{{modelPackage}};
+// Applied OLAP Modification (for EssSharp)
+using Type = System.Type;
namespace {{packageName}}.Client
{
@@ -187,18 +189,26 @@ namespace {{packageName}}.Client
}
};
+ // Applied OLAP Modification
/// <summary>
/// Allows for extending request processing for <see cref="ApiClient"/> generated code.
/// </summary>
/// <param name="request">The RestSharp request object</param>
- {{#useVirtualForHooks}}public virtual{{/useVirtualForHooks}}{{^useVirtualForHooks}}partial{{/useVirtualForHooks}} void InterceptRequest(RestRequest request){{#useVirtualForHooks}} { }{{/useVirtualForHooks}}{{^useVirtualForHooks}};{{/useVirtualForHooks}}
+ /// <param name="configuration">The per-client configuration.</param>
+ /// <param name="options">The per-request options.</param>
+ /// <param name="cancellationToken" />
+ {{#useVirtualForHooks}}public virtual{{/useVirtualForHooks}}{{^useVirtualForHooks}}private partial{{/useVirtualForHooks}} Task InterceptRequestAsync(RestRequest request, IReadableConfiguration configuration, RequestOptions options, CancellationToken cancellationToken = default){{#useVirtualForHooks}} { }{{/useVirtualForHooks}}{{^useVirtualForHooks}};{{/useVirtualForHooks}}
+ // Applied OLAP Modification
/// <summary>
/// Allows for extending response processing for <see cref="ApiClient"/> generated code.
/// </summary>
/// <param name="request">The RestSharp request object</param>
/// <param name="response">The RestSharp response object</param>
- {{#useVirtualForHooks}}public virtual{{/useVirtualForHooks}}{{^useVirtualForHooks}}partial{{/useVirtualForHooks}} void InterceptResponse(RestRequest request, RestResponse response){{#useVirtualForHooks}} { }{{/useVirtualForHooks}}{{^useVirtualForHooks}};{{/useVirtualForHooks}}
+ /// <param name="configuration">The per-client configuration.</param>
+ /// <param name="options">The per-request options.</param>
+ /// <param name="cancellationToken" />
+ {{#useVirtualForHooks}}public virtual{{/useVirtualForHooks}}{{^useVirtualForHooks}}private partial{{/useVirtualForHooks}} Task InterceptResponseAsync(RestRequest request, RestResponse response, IReadableConfiguration configuration, RequestOptions options, CancellationToken cancellationToken = default){{#useVirtualForHooks}} { }{{/useVirtualForHooks}}{{^useVirtualForHooks}};{{/useVirtualForHooks}}
/// <summary>
/// Initializes a new instance of the <see cref="ApiClient" />, defaulting to the global configurations' base url.
@@ -392,6 +402,15 @@ namespace {{packageName}}.Client
}
}
+ // Applied OLAP Modification
+ if (options.Cookies != null && options.Cookies.Count > 0)
+ {
+ foreach (var cookie in options.Cookies)
+ {
+ request.AddCookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain);
+ }
+ }
+
return request;
}
@@ -446,6 +465,7 @@ namespace {{packageName}}.Client
return transformed;
}
+ // Applied OLAP Modification
/// <summary>
/// Executes the HTTP request for the current service.
/// Based on functions received it can be async or sync.
@@ -456,8 +476,9 @@ namespace {{packageName}}.Client
/// <param name="options">The RestSharp options object</param>
/// <param name="configuration">A per-request configuration object.
/// It is assumed that any merge with GlobalConfiguration has been done before calling this method.</param>
+ /// <param name="cancellationToken" />
/// <returns>A new ApiResponse instance.</returns>
- private async Task<ApiResponse<T>> ExecClientAsync<T>(Func<RestClient, Task<RestResponse<T>>> getResponse, Action<RestClientOptions> setOptions, RestRequest request, RequestOptions options, IReadableConfiguration configuration)
+ private async Task<ApiResponse<T>> ExecClientAsync<T>(Func<RestClient, Task<RestResponse<T>>> getResponse, Action<RestClientOptions> setOptions, RestRequest request, RequestOptions options, IReadableConfiguration configuration, CancellationToken cancellationToken = default)
{
var baseUrl = configuration.GetOperationServerUrl(options.Operation, options.OperationIndex) ?? _baseUrl;
var clientOptions = new RestClientOptions(baseUrl)
@@ -491,7 +512,19 @@ namespace {{packageName}}.Client
using (RestClient client = new RestClient(clientOptions,
configureSerialization: serializerConfig => serializerConfig.UseSerializer(() => new CustomJsonCodec(SerializerSettings, configuration))))
{
- InterceptRequest(request);
+ // Applied OLAP Modification - START
+ try
+ {
+ // Assign any configured degree of parallelism.
+ if ( configuration is { MaxDegreeOfParallelism: { } degree } )
+ MaxDegreeOfParallelism = degree;
+
+ // Await any request semaphore.
+ await (RequestSemaphore?.WaitAsync(cancellationToken) ?? Task.CompletedTask).ConfigureAwait(false);
+
+ // Allow any custom extensions to process the request before dispatch.
+ await InterceptRequestAsync(request, configuration, options, cancellationToken).ConfigureAwait(false);
+ // Applied OLAP Modification - END
RestResponse<T> response = await getResponse(client).ConfigureAwait(false);
@@ -519,8 +552,16 @@ namespace {{packageName}}.Client
{
response.Data = (T)(object)response.Content;
}
+ // Applied OLAP Modification
+ else if (typeof(T).Name == "Object") // for raw object response
+ {
+ // if the response data was not already deserialized, return the raw bytes.
+ response.Data ??= (T)(object)response.RawBytes;
+ }
- InterceptResponse(request, response);
+ // Applied OLAP Modification
+ // Allow any custom extensions to process the response after dispatch.
+ await InterceptResponseAsync(request, response, configuration, options, cancellationToken).ConfigureAwait(false);
var result = ToApiResponse(response);
if (response.ErrorMessage != null)
@@ -555,12 +596,19 @@ namespace {{packageName}}.Client
}
}
return result;
+ // Applied OLAP Modification
+ }
+ finally
+ {
+ try { RequestSemaphore?.Release(); } catch { }
+ }
}
}
private async Task<RestResponse<T>> DeserializeRestResponseFromPolicyAsync<T>(RestClient client, RestRequest request, PolicyResult<RestResponse> policyResult, CancellationToken cancellationToken = default)
{
- if (policyResult.Outcome == OutcomeType.Successful)
+ // Applied OLAP Modification
+ if (policyResult.Outcome == OutcomeType.Successful || policyResult.Result != null)
{
return await client.Deserialize<T>(policyResult.Result, cancellationToken).ConfigureAwait(false);
}
@@ -568,7 +616,10 @@ namespace {{packageName}}.Client
{
return new RestResponse<T>(request)
{
- ErrorException = policyResult.FinalException
+ // Applied OLAP Modification
+ StatusCode = policyResult.Result?.StatusCode ?? 0,
+ ErrorMessage = policyResult.Result?.ErrorMessage,
+ ErrorException = policyResult.FinalException ?? policyResult.Result?.ErrorException ?? policyResult.FinalHandledResult?.ErrorException
};
}
}
@@ -632,7 +683,8 @@ namespace {{packageName}}.Client
{{/supportsRetry}}
};
- return ExecClientAsync(getResponse, setOptions, request, options, configuration);
+ // Applied OLAP Modification
+ return ExecClientAsync(getResponse, setOptions, request, options, configuration, cancellationToken);
}
#region IAsynchronousClient
diff --git a/templates/Configuration.mustache b/templates/Configuration.mustache
index 39dbd9c..b7ab16c 100644
--- a/templates/Configuration.mustache
+++ b/templates/Configuration.mustache
@@ -17,6 +17,8 @@ using System.Net.Security;
{{#hasOAuthMethods}}using {{packageName}}.Client.Auth;
{{/hasOAuthMethods}}
{{/useRestSharp}}
+// Applied OLAP Modification
+using Microsoft.Extensions.Logging;
namespace {{packageName}}.Client
{
@@ -246,6 +248,30 @@ namespace {{packageName}}.Client
#region Properties
+ // Applied OLAP Modification
+ /// <summary>
+ /// Gets or sets whether to apply cached session cookies.
+ /// </summary>
+ public virtual bool ApplyCookies { get; set; } = true;
+
+ // Applied OLAP Modification
+ /// <summary>
+ /// Gets or sets whether to retain cached session cookies.
+ /// </summary>
+ public virtual bool RetainCookies { get; set; } = true;
+
+ // Applied OLAP Modification
+ /// <summary>
+ /// Gets or sets the <see cref="ILogger"/> used to log information, warnings, and errors during requests.
+ /// </summary>
+ public virtual ILogger Logger { get; set; }
+
+ // Applied OLAP Modification
+ /// <summary>
+ /// Gets or sets the maximum number of concurrent requests.
+ /// </summary>
+ public virtual int MaxDegreeOfParallelism { get; set; } = 4;
+
/// <summary>
/// Gets or sets the base path for API access.
/// </summary>
@@ -702,6 +728,14 @@ namespace {{packageName}}.Client
var config = new Configuration
{
+ // Applied OLAP Modification
+ ApplyCookies = second.ApplyCookies,
+ // Applied OLAP Modification
+ RetainCookies = second.RetainCookies,
+ // Applied OLAP Modification
+ Logger = second.Logger ?? first.Logger,
+ // Applied OLAP Modification
+ MaxDegreeOfParallelism = second.MaxDegreeOfParallelism,
ApiKey = apiKey,
ApiKeyPrefix = apiKeyPrefix,
DefaultHeaders = defaultHeaders,
diff --git a/templates/IApiAccessor.mustache b/templates/IApiAccessor.mustache
index a269f56..5ea6378 100644
--- a/templates/IApiAccessor.mustache
+++ b/templates/IApiAccessor.mustache
@@ -9,6 +9,18 @@ namespace {{packageName}}.Client
/// </summary>
{{>visibility}} interface IApiAccessor
{
+ // Applied OLAP Modification
+ /// <summary>
+ /// Gets or sets the client for accessing the underlying API asynchronously.
+ /// </summary>
+ IAsynchronousClient AsynchronousClient { get; set; }
+
+ // Applied OLAP Modification
+ /// <summary>
+ /// Gets or sets the client for accessing the underlying API synchronously.
+ /// </summary>
+ ISynchronousClient Client { get; set; }
+
/// <summary>
/// Gets or sets the configuration object
/// </summary>
diff --git a/templates/IReadableConfiguration.mustache b/templates/IReadableConfiguration.mustache
index 6712aa6..60273eb 100644
--- a/templates/IReadableConfiguration.mustache
+++ b/templates/IReadableConfiguration.mustache
@@ -9,6 +9,8 @@ using System.Security.Cryptography.X509Certificates;
{{#hasOAuthMethods}}using {{packageName}}.Client.Auth;
{{/hasOAuthMethods}}
{{/useRestSharp}}
+// Applied OLAP Modification
+using Microsoft.Extensions.Logging;
namespace {{packageName}}.Client
{
@@ -17,6 +19,30 @@ namespace {{packageName}}.Client
/// </summary>
public interface IReadableConfiguration
{
+ // Applied OLAP Modification
+ /// <summary>
+ /// Gets whether to apply cached session cookies.
+ /// </summary>
+ bool ApplyCookies { get; }
+
+ // Applied OLAP Modification
+ /// <summary>
+ /// Gets whether to retain cached session cookies.
+ /// </summary>
+ bool RetainCookies { get; }
+
+ // Applied OLAP Modification
+ /// <summary>
+ /// Gets the <see cref="ILogger"/> used to log information, warnings, and errors during requests.
+ /// </summary>
+ ILogger Logger { get; }
+
+ // Applied OLAP Modification
+ /// <summary>
+ /// Gets the maximum number of concurrent requests.
+ /// </summary>
+ int MaxDegreeOfParallelism { get; }
+
/// <summary>
/// Gets the access token.
/// </summary>
diff --git a/templates/RequestOptions.mustache b/templates/RequestOptions.mustache
index cfc1469..d4b4df7 100644
--- a/templates/RequestOptions.mustache
+++ b/templates/RequestOptions.mustache
@@ -13,6 +13,12 @@ namespace {{packageName}}.Client
/// </summary>
public class RequestOptions
{
+ // Applied OLAP Modification
+ /// <summary>
+ /// Arbitrary preferences associated with the operation.
+ /// </summary>
+ public object Preferences { get; set; }
+
/// <summary>
/// Parameters to be bound to path parts of the Request's URL
/// </summary>