Skip to content

Commit 3b9ccd4

Browse files
committed
Added template src logging; MethodRequestBuilder.cs.tt - method type changed to Action or Function;
I/MethodRequest.cs.tt supports multiple HTTP verbs, setting verb in the method;
1 parent 6a45df1 commit 3b9ccd4

File tree

2 files changed

+70
-6
lines changed

2 files changed

+70
-6
lines changed

Templates/CSharp/Requests/IMethodRequest.cs.tt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,27 @@
55

66
var method = host.CurrentType.AsOdcmMethod();
77
var entityName = method.Class.Name.ToCheckedCase();
8-
var httpMethod = (method.IsAction()) ? "POST" : "GET";
8+
9+
var isFunction = method.IsFunction;
10+
var isAction = !isFunction;
11+
var isComposable = method.IsComposable;
12+
var httpMethods = new System.Collections.Generic.List<string>();
13+
14+
// Set the supported verbs based on whether this is function, composable function, or an action.
15+
if (isFunction)
16+
{
17+
httpMethods.Add("GET");
18+
if (isComposable)
19+
{
20+
httpMethods.Add("PATCH");
21+
httpMethods.Add("PUT");
22+
}
23+
}
24+
else
25+
{
26+
httpMethods.Add("POST");
27+
}
28+
929
var methodName = method.Name.Substring(method.Name.IndexOf('.') + 1).ToCheckedCase();
1030
var requestType = entityName + methodName + "Request";
1131

@@ -47,7 +67,7 @@ namespace <#=method.Namespace.GetNamespaceName()#>
4767
public partial interface I<#=requestType#> : IBaseRequest
4868
{
4969
<#
50-
if (hasParameters && method.IsAction())
70+
if (hasParameters && (isAction || isComposable))
5171
{
5272
#>
5373

@@ -73,6 +93,8 @@ namespace <#=method.Namespace.GetNamespaceName()#>
7393
sendOverloadParameters = "CancellationToken cancellationToken";
7494
}
7595

96+
foreach (string httpMethod in httpMethods)
97+
{
7698
#>
7799

78100
/// <summary>
@@ -86,6 +108,12 @@ namespace <#=method.Namespace.GetNamespaceName()#>
86108
/// <#=sendParameterHeadersForOverload#>
87109
/// <returns><#=methodReturnTag#></returns>
88110
<#=methodReturnType#> <#=httpMethod.ToLower().ToCheckedCase()#>Async(<#=sendOverloadParameters#>);
111+
112+
<#
113+
} // end foreach
114+
#>
115+
116+
89117
<#
90118
if (!returnsStream)
91119
{

Templates/CSharp/Requests/MethodRequest.cs.tt

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,33 @@
55

66
var method = host.CurrentType.AsOdcmMethod();
77
var entityName = method.Class.Name.ToCheckedCase();
8-
var isAction = method.IsAction();
9-
var httpMethod = isAction ? "POST" : "GET";
8+
//var isAction = method.IsAction();// TODO: We don't need the IsAction extension for this. We should use odcmmethod.IsFunction()
9+
10+
var overloadCount = method.Overloads.Count;
11+
var isFunction = method.IsFunction;
12+
var isAction = !isFunction;
13+
var isComposable = method.IsComposable;
14+
var httpMethods = new System.Collections.Generic.List<string>();
15+
16+
// Set the supported verbs based on whether this is function, composable function, or an action.
17+
if (isFunction)
18+
{
19+
httpMethods.Add("GET");
20+
if (isComposable)
21+
{
22+
httpMethods.Add("PATCH");
23+
httpMethods.Add("PUT");
24+
}
25+
}
26+
else
27+
{
28+
httpMethods.Add("POST");
29+
}
30+
31+
32+
33+
34+
//var httpMethod = isAction ? "POST" : "GET";
1035
var methodName = method.Name.Substring(method.Name.IndexOf('.') + 1).ToCheckedCase();
1136
var requestType = entityName + methodName + "Request";
1237

@@ -60,7 +85,6 @@ namespace <#=method.Namespace.GetNamespaceName()#>
6085
IEnumerable<Option> options)
6186
: base(requestUrl, client, options)
6287
{
63-
this.Method = "<#=httpMethod#>";
6488
<#
6589
if (includeRequestBody)
6690
{
@@ -83,7 +107,10 @@ namespace <#=method.Namespace.GetNamespaceName()#>
83107
<#
84108
}
85109
#>
86-
110+
<#
111+
foreach (string httpMethod in httpMethods) // We need to create a method for each HTTP verb.
112+
{
113+
#>
87114
/// <summary>
88115
/// Issues the <#=httpMethod#> request.
89116
/// </summary>
@@ -122,6 +149,7 @@ namespace <#=method.Namespace.GetNamespaceName()#>
122149
}
123150
#>
124151
{
152+
this.Method = "<#=httpMethod#>";
125153
<#
126154
var methodParameter = includeRequestBody ? "this.RequestBody" : "null";
127155

@@ -175,6 +203,14 @@ namespace <#=method.Namespace.GetNamespaceName()#>
175203
#>
176204
}
177205

206+
207+
208+
<#
209+
} // end the foreach httpmethods
210+
#>
211+
212+
213+
178214
<#
179215
if (!returnsStream)
180216
{

0 commit comments

Comments
 (0)