-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathOperations.cs.template
86 lines (81 loc) · 3.53 KB
/
Operations.cs.template
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
// <auto-generated>
// Code generated by https://github.com/kubernetes-client/csharp/tree/master/src/LibKubernetesGenerator
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
namespace k8s;
public partial class AbstractKubernetes : I{{name}}Operations
{
{{#apis}}
/// <inheritdoc/>
async Task<HttpOperationResponse{{GetReturnType operation "<>"}}> I{{name}}Operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetType .}} {{GetDotNetName .}},
{{/operation.parameters}}
IReadOnlyDictionary<string, IReadOnlyList<string>> customHeaders,
CancellationToken cancellationToken)
{
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
cts.CancelAfter(HttpClientTimeout);
{{#IfParamContains operation "watch"}}
if (watch == true)
{
cts.CancelAfter(Timeout.InfiniteTimeSpan);
}
{{/IfParamContains operation "watch"}}
cancellationToken = cts.Token;
{{#operation.parameters}}
{{#isRequired}}
if ({{GetDotNetName name}} == null)
{
throw new ArgumentNullException("{{GetDotNetName name}}");
}
{{/isRequired}}
{{/operation.parameters}}
// Construct URL
var url = $"{{ToInterpolationPathString path}}";
{{#IfGroupPathParamContainsGroup path}}
url = url.Replace("apis//", "api/");
{{/IfGroupPathParamContainsGroup}}
{{#IfListNotEmpty operation.parameters}}
var q = new QueryBuilder();
{{#operation.parameters}}
{{#IfKindIs . "query"}}
q.Append("{{name}}", {{GetDotNetName name}});
{{/IfKindIs . "query"}}
{{/operation.parameters}}
url += q.ToString();
{{/IfListNotEmpty operation.parameters}}
// Create HTTP transport
var httpRequest = CreateRequest(url, HttpMethods.{{Method}}, customHeaders);
{{#IfParamContains operation "body"}}
var httpResponse = await SendRequest(body, httpRequest, cancellationToken);
{{/IfParamContains operation "body"}}
{{#IfParamDoesNotContain operation "body"}}
var httpResponse = await SendRequestRaw("", httpRequest, cancellationToken);
{{/IfParamDoesNotContain operation "body"}}
// Create Result
{{#IfReturnType operation "void"}}
HttpOperationResponse result = new HttpOperationResponse() { Request = httpRequest, Response = httpResponse };
{{/IfReturnType operation "void"}}
{{#IfReturnType operation "obj"}}
var result = await CreateResultAsync{{GetReturnType operation "<>"}}(httpRequest,
httpResponse,
{{#IfParamContains operation "watch"}}
watch,
{{/IfParamContains operation "watch"}}
{{#IfParamDoesNotContain operation "watch"}}
false,
{{/IfParamDoesNotContain operation "watch"}}
cancellationToken);
{{/IfReturnType operation "obj"}}
{{#IfReturnType operation "stream"}}
var result = new HttpOperationResponse{{GetReturnType operation "<>"}}() {
Request = httpRequest,
Response = httpResponse,
Body = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false) };
{{/IfReturnType operation "stream"}}
return result;
}
{{/apis}}
}