-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy path_LowLevelDispatch.Generated.cshtml
85 lines (82 loc) · 2.73 KB
/
_LowLevelDispatch.Generated.cshtml
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
@using System.Linq
@using CodeGeneration.LowLevelClient.Domain
@using CodeGeneration.LowLevelClient
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Elasticsearch.Net;
using static Elasticsearch.Net.HttpMethod;
//Generated File Please Do Not Edit Manually
@{ RestApiSpec model = Model; }
namespace Nest
{
///<summary>This dispatches highlevel requests into the proper lowlevel client overload method</summary>
internal partial class LowLevelDispatch
{
@foreach (var kv in model.Endpoints)
{
var endpoint = kv.Value;
var endpointsException = string.Join(", ", endpoint.Url.Paths.Select(p=> "\"" + p + "\""));
var httpMethodsException = string.Join(", ", endpoint.RawDispatches.Select(p=> p.Key.ToUpper() ));
var peek = endpoint.GetCsharpMethods().FirstOrDefault();
if (peek == null)
{
<text>//NO METHOD FOR @endpoint.Url.Path</text>
continue;
}
var generate = new [] {
new { Name = endpoint.CsharpMethodName + "Dispatch<T>", Returns = "ElasticsearchResponse<T>" , Async = false},
new { Name = endpoint.CsharpMethodName + "DispatchAsync<T>", Returns = "Task<ElasticsearchResponse<T>>", Async = true },
};
foreach(var gen in generate)
{
<text>internal @Raw(gen.Returns) @(Raw(gen.Name))(IRequest<@peek.QueryStringParamName> p @if (endpoint.Body != null) {<text>, @(Raw("PostData<object>")) body</text>}) where T : class
{
switch(p.HttpMethod)
{
@foreach (var methodGroup in endpoint.RawDispatches)
{
var httpMethod = methodGroup.Key;
var dispatches = methodGroup.Value.ToList();
var totalDispatches = dispatches.Count();
var allWithIfChecks = dispatches.All(d => !string.IsNullOrEmpty(d.IfCheck));
var i = 0;
<text>case @httpMethod.ToUpper():
@foreach (var dispatch in dispatches)
{
var method = dispatch.CsharpMethod;
var name = method.FullName + ((gen.Async) ? "Async<T>" : "<T>");
var hasIfCheck = !string.IsNullOrEmpty(dispatch.IfCheck);
if (i == 0 && !hasIfCheck)
{
<text>return _lowLevel.@(Raw(name))(@Raw(string.Join(",", dispatch.MethodArguments)));</text>
}
else
{
if (hasIfCheck)
{
<text>if (@Raw(dispatch.IfCheck)) return _lowLevel.@(Raw(name))(@Raw(string.Join(",", dispatch.MethodArguments)));</text>
}
else
{
<text>return _lowLevel.@(Raw(name))(@Raw(string.Join(",", dispatch.MethodArguments)));</text>
}
}
if (i == totalDispatches - 1 && allWithIfChecks)
{
<text>break;</text>
}
i++;
}</text>
}
}
throw InvalidDispatch("@(endpoint.CsharpMethodName)", p, new [] { @(httpMethodsException) }, @Raw(endpointsException));
}
</text>
}
}
}
}