1
1
using System;
2
2
using System.Collections.Generic;
3
+ using System.Threading.Tasks;
3
4
using RestSharp;
4
5
using { {invokerPackage} };
5
6
using { {modelPackage} };
@@ -8,10 +9,30 @@ using {{modelPackage}};
8
9
9
10
namespace { {package} } {
10
11
{{#operations} }
12
+
13
+ public interface I{ {classname} } {
14
+ {{#operation} }
15
+ /// <summary >
16
+ /// { {summary} } { {notes} }
17
+ /// </summary >
18
+ { {#allParams} }/// <param name =" { { paramName} } " >{ {description} }</param >{ {/allParams} }
19
+ /// <returns >{ {#returnType} }{ {{returnType} }}{ {/returnType} }</returns >
20
+ { {#returnType} }{ {{returnType} }}{ {/returnType} }{ {^returnType} }void{ {/returnType} } { {nickname} } ({ {#allParams} }{ {{dataType} }} { {paramName} }{ {#hasMore} }, { {/hasMore} }{ {/allParams} });
21
+
22
+ /// <summary >
23
+ /// { {summary} } { {notes} }
24
+ /// </summary >
25
+ { {#allParams} }/// <param name =" { { paramName} } " >{ {description} }</param >{ {/allParams} }
26
+ /// <returns >{ {#returnType} }{ {{returnType} }}{ {/returnType} }</returns >
27
+ { {#returnType} }Task<{ {{returnType} }}>{ {/returnType} }{ {^returnType} }Task{ {/returnType} } { {nickname} }Async ({ {#allParams} }{ {{dataType} }} { {paramName} }{ {#hasMore} }, { {/hasMore} }{ {/allParams} });
28
+ { {/operation} }
29
+ }
30
+
11
31
/// <summary >
12
32
/// Represents a collection of functions to interact with the API endpoints
13
33
/// </summary >
14
- public class { {classname} } {
34
+ public class { {classname} } : I{ {classname} } {
35
+
15
36
/// < summary>
16
37
/// Initializes a new instance of the < see cref= " {{classname}}" /> class.
17
38
/// < /summary>
@@ -61,8 +82,7 @@ namespace {{package}} {
61
82
/// <summary >
62
83
/// { {summary} } { {notes} }
63
84
/// </summary >
64
- { {#allParams} } /// <param name =" { { paramName} } " >{ {description} }</param >
65
- { {/allParams} }
85
+ { {#allParams} }/// <param name =" { { paramName} } " >{ {description} }</param >{ {/allParams} }
66
86
/// <returns >{ {#returnType} }{ {{returnType} }}{ {/returnType} }</returns >
67
87
public { {#returnType} }{ {{returnType} }}{ {/returnType} }{ {^returnType} }void{ {/returnType} } { {nickname} } ({ {#allParams} }{ {{dataType} }} { {paramName} }{ {#hasMore} }, { {/hasMore} }{ {/allParams} }) {
68
88
@@ -98,12 +118,56 @@ namespace {{package}} {
98
118
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.{ {httpMethod} }, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
99
119
100
120
if (((int)response.StatusCode) >= 400) {
101
- throw new ApiException ((int)response.StatusCode, " Error calling {{nickname}}: " + response.Content);
121
+ throw new ApiException ((int)response.StatusCode, " Error calling {{nickname}}: " + response.Content, response.Content );
102
122
}
103
123
{ {#returnType} }return ({ {{returnType} }}) apiClient.Deserialize(response.Content, typeof({ {{returnType} }}));{ {/returnType} }{ {^returnType} }
104
124
return;{ {/returnType} }
105
125
}
126
+
127
+ /// <summary >
128
+ /// { {summary} } { {notes} }
129
+ /// </summary >
130
+ { {#allParams} }/// <param name =" { { paramName} } " >{ {description} }</param >{ {/allParams} }
131
+ /// <returns >{ {#returnType} }{ {{returnType} }}{ {/returnType} }</returns >
132
+ public async { {#returnType} }Task<{ {{returnType} }}>{ {/returnType} }{ {^returnType} }Task{ {/returnType} } { {nickname} }Async ({ {#allParams} }{ {{dataType} }} { {paramName} }{ {#hasMore} }, { {/hasMore} }{ {/allParams} }) {
133
+
134
+ {{#allParams} }{ {#required} }
135
+ // verify the required parameter '{ {paramName} }' is set
136
+ if ({ {paramName} } == null) throw new ApiException(400, "Missing required parameter '{ {paramName} }' when calling { {nickname} }");
137
+ { {/required} }{ {/allParams} }
138
+
139
+ var path = "{ {path} }";
140
+ path = path.Replace("{ format} ", "json");
141
+ { {#pathParams} }path = path.Replace("{ " + " {{baseName} }" + "}", apiClient.ParameterToString({ {{paramName} }}));
142
+ { {/pathParams} }
143
+
144
+ var queryParams = new Dictionary<String , String >();
145
+ var headerParams = new Dictionary<String , String >();
146
+ var formParams = new Dictionary<String , String >();
147
+ var fileParams = new Dictionary<String , String >();
148
+ String postBody = null;
149
+
150
+ { {#queryParams} } if ({ {paramName} } != null) queryParams.Add("{ {baseName} }", apiClient.ParameterToString({ {paramName} })); // query parameter
151
+ { {/queryParams} }
152
+ { {#headerParams} } if ({ {paramName} } != null) headerParams.Add("{ {baseName} }", apiClient.ParameterToString({ {paramName} })); // header parameter
153
+ { {/headerParams} }
154
+ { {#formParams} }if ({ {paramName} } != null) { {#isFile} }fileParams.Add("{ {baseName} }", { {paramName} });{ {/isFile} }{ {^isFile} }formParams.Add("{ {baseName} }", apiClient.ParameterToString({ {paramName} })); // form parameter{ {/isFile} }
155
+ { {/formParams} }
156
+ { {#bodyParam} }postBody = apiClient.Serialize({ {paramName} }); // http body (model) parameter
157
+ { {/bodyParam} }
158
+
159
+ // authentication setting, if any
160
+ String[] authSettings = new String[] { {{#authMethods} }"{ {name} }"{ {#hasMore} }, { {/hasMore} }{ {/authMethods} } };
161
+
162
+ // make the HTTP request
163
+ IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.{ {httpMethod} }, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
164
+ if (((int)response.StatusCode) >= 400) {
165
+ throw new ApiException ((int)response.StatusCode, " Error calling {{nickname}}: " + response.Content, response.Content);
166
+ }
167
+ { {#returnType} }return ({ {{returnType} }}) ApiInvoker.Deserialize(response.Content, typeof({ {{returnType} }}));{ {/returnType} }{ {^returnType} }
168
+ return;{ {/returnType} }
169
+ }
106
170
{ {/operation} }
107
- }
171
+ }
108
172
{ {/operations} }
109
173
}
0 commit comments