Files
csharp/gen/KubernetesGenerator/templates/Kubernetes.cs.template
Boshi Lian 1778d446d1 simplify http build code (#754)
* simplify request code

* re generate code

* remove unused tracing from websocket

* dotnet fmt

* fix warning

* fix warning

* make fmt and stylecop happy together
2021-12-19 09:01:26 -08:00

95 lines
4.0 KiB
Plaintext

// <auto-generated>
// Code generated by https://github.com/kubernetes-client/csharp/tree/master/gen/KubernetesGenerator
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
namespace k8s
{
using Microsoft.Rest;
using Models;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
public partial class Kubernetes : ServiceClient<Kubernetes>, IKubernetes
{
{{#.}}
/// <inheritdoc/>
public async Task<HttpOperationResponse{{GetReturnType operation "<>"}}> {{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetType .}} {{GetDotNetName . "true"}},
{{/operation.parameters}}
IDictionary<string, IList<string>> customHeaders = null,
CancellationToken cancellationToken = default(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 = new System.Uri(BaseUri, $"{{ToInterpolationPathString path}}").ToString();
{{#IfGroupPathParamContainsGroup path}}
url = url.Replace("/apis//", "/api/");
{{/IfGroupPathParamContainsGroup}}
var q = new QueryBuilder();
{{#operation.parameters}}
{{#IfKindIs . "query"}}
q.Append("{{name}}", {{GetDotNetName name}});
{{/IfKindIs . "query"}}
{{/operation.parameters}}
url += q.ToString();
// Create HTTP transport
var httpRequest = CreateRequest(url, HttpMethod.{{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;
}
{{/.}}
}
}