@@ -19,7 +19,7 @@ public IEnumerable<string> MethodArguments
19
19
get
20
20
{
21
21
var methodArgs = CsharpMethod . Parts
22
- . Select ( p => p . Name != "body" ? "p.RouteValues." + p . Name . ToPascalCase ( ) : "body" )
22
+ . Select ( p => p . Name != "body" ? "p.RouteValues." + p . Name . ToPascalCase ( ) + ( p . Type == "enum" ? ".Value" : "" ) : "body" )
23
23
. Concat ( new [ ] { "u => p.RequestParameters" } ) ;
24
24
return methodArgs ;
25
25
}
@@ -44,6 +44,8 @@ public string IfCheck
44
44
45
45
public class ApiEndpoint
46
46
{
47
+ private List < CsharpMethod > _csharpMethods ;
48
+
47
49
public string CsharpMethodName { get ; set ; }
48
50
public string Documentation { get ; set ; }
49
51
public IEnumerable < string > Methods { get ; set ; }
@@ -100,9 +102,20 @@ public IEnumerable<CsharpMethod> CsharpMethods
100
102
{
101
103
get
102
104
{
103
- foreach ( var method in this . Methods )
105
+ if ( _csharpMethods != null )
104
106
{
107
+ foreach ( var csharpMethod in _csharpMethods )
108
+ yield return csharpMethod ;
109
+ yield break ;
110
+ }
105
111
112
+ // enumerate once and cache
113
+ _csharpMethods = new List < CsharpMethod > ( ) ;
114
+
115
+ this . PatchEndpoint ( ) ;
116
+
117
+ foreach ( var method in this . Methods )
118
+ {
106
119
var methodName = this . CsharpMethodName + this . OptionallyAppendHttpMethod ( this . Methods , method ) ;
107
120
//the distinctby here catches aliases routes i.e
108
121
// /_cluster/nodes/{node_id}/hotthreads vs /_cluster/nodes/{node_id}/hot_threads
@@ -117,25 +130,8 @@ public IEnumerable<CsharpMethod> CsharpMethods
117
130
return p . Value ;
118
131
} )
119
132
. ToList ( ) ;
120
- var args = parts . Select ( p =>
121
- {
122
- switch ( p . Type )
123
- {
124
- case "int" :
125
- case "string" :
126
- return p . Type + " " + p . Name ;
127
- case "list" :
128
- return "string " + p . Name ;
129
- case "enum" :
130
- return this . PascalCase ( p . Name ) + p . Name ;
131
- case "number" :
132
- return "string " + p . Name ;
133
- default :
134
- return p . Type + " " + p . Name ;
135
- //return "string " + p.Name;
136
133
137
- }
138
- } ) ;
134
+ var args = parts . Select ( p => p . Argument ) ;
139
135
140
136
//.NET does not allow get requests to have a body payload.
141
137
if ( method != "GET" && this . Body != null )
@@ -184,6 +180,7 @@ public IEnumerable<CsharpMethod> CsharpMethods
184
180
"Func<" + apiMethod . QueryStringParamName + ", " + apiMethod . QueryStringParamName + "> requestParameters = null"
185
181
} ) . ToList ( ) ;
186
182
apiMethod . Arguments = string . Join ( ", " , args ) ;
183
+ _csharpMethods . Add ( apiMethod ) ;
187
184
yield return apiMethod ;
188
185
189
186
args = args . Concat ( new [ ]
@@ -208,6 +205,7 @@ public IEnumerable<CsharpMethod> CsharpMethods
208
205
Url = this . Url
209
206
} ;
210
207
PatchMethod ( apiMethod ) ;
208
+ _csharpMethods . Add ( apiMethod ) ;
211
209
yield return apiMethod ;
212
210
213
211
//No need for deserialization state when returning dynamicdictionary
@@ -241,7 +239,9 @@ public IEnumerable<CsharpMethod> CsharpMethods
241
239
Url = this . Url
242
240
} ;
243
241
PatchMethod ( apiMethod ) ;
242
+ _csharpMethods . Add ( apiMethod ) ;
244
243
yield return apiMethod ;
244
+
245
245
args = args . Concat ( new [ ]
246
246
{
247
247
"CancellationToken cancellationToken = default(CancellationToken)"
@@ -265,12 +265,38 @@ public IEnumerable<CsharpMethod> CsharpMethods
265
265
Url = this . Url
266
266
} ;
267
267
PatchMethod ( apiMethod ) ;
268
+ _csharpMethods . Add ( apiMethod ) ;
268
269
yield return apiMethod ;
269
270
}
270
271
}
271
272
}
272
273
}
273
274
275
+ private void PatchEndpoint ( )
276
+ {
277
+ //rename the {metric} route param to something more specific on XpackWatcherStats
278
+ // TODO: find a better place to do this
279
+ if ( this . CsharpMethodName == "XpackWatcherStats" )
280
+ {
281
+ var metric = this . Url . Parts . First ( p => p . Key == "metric" ) ;
282
+
283
+ var apiUrlPart = metric . Value ;
284
+ apiUrlPart . Name = "watcher_stats_metric" ;
285
+
286
+ if ( this . Url . Parts . Remove ( "metric" ) )
287
+ {
288
+ this . Url . Parts . Add ( "watcher_stats_metric" , apiUrlPart ) ;
289
+ }
290
+
291
+ this . Url . Path = RenameMetricUrlPathParam ( this . Url . Path ) ;
292
+ this . Url . Paths = this . Url . Paths . Select ( RenameMetricUrlPathParam ) ;
293
+ }
294
+ }
295
+
296
+ private static string RenameMetricUrlPathParam ( string path )
297
+ {
298
+ return path . Replace ( "{metric}" , "{watcher_stats_metric}" ) ;
299
+ }
274
300
275
301
//Patches a method name for the exceptions (IndicesStats needs better unique names for all the url endpoints)
276
302
//or to get rid of double verbs in an method name i,e ClusterGetSettingsGet > ClusterGetSettings
@@ -318,7 +344,7 @@ public static void PatchMethod(CsharpMethod method)
318
344
try
319
345
{
320
346
IEnumerable < string > skipList = new List < string > ( ) ;
321
- IDictionary < string , string > renameList = new Dictionary < string , string > ( ) ;
347
+ IDictionary < string , string > queryStringParamsRenameList = new Dictionary < string , string > ( ) ;
322
348
323
349
var typeName = "ApiGenerator.Overrides.Descriptors." + method . DescriptorType + "Overrides" ;
324
350
var type = CodeConfiguration . Assembly . GetType ( typeName ) ;
@@ -328,9 +354,8 @@ public static void PatchMethod(CsharpMethod method)
328
354
if ( overrides != null )
329
355
{
330
356
skipList = overrides . SkipQueryStringParams ?? skipList ;
331
- renameList = overrides . RenameQueryStringParams ?? renameList ;
332
-
333
- overrides . PatchMethod ( method ) ;
357
+ queryStringParamsRenameList = overrides . RenameQueryStringParams ?? queryStringParamsRenameList ;
358
+ method = overrides . PatchMethod ( method ) ;
334
359
}
335
360
}
336
361
@@ -343,8 +368,8 @@ public static void PatchMethod(CsharpMethod method)
343
368
} ;
344
369
345
370
foreach ( var kv in globalQueryStringRenames )
346
- if ( ! renameList . ContainsKey ( kv . Key ) )
347
- renameList [ kv . Key ] = kv . Value ;
371
+ if ( ! queryStringParamsRenameList . ContainsKey ( kv . Key ) )
372
+ queryStringParamsRenameList [ kv . Key ] = kv . Value ;
348
373
349
374
var patchedParams = new Dictionary < string , ApiQueryParameters > ( ) ;
350
375
foreach ( var kv in method . Url . Params )
@@ -355,7 +380,7 @@ public static void PatchMethod(CsharpMethod method)
355
380
continue ;
356
381
357
382
string newName ;
358
- if ( ! renameList . TryGetValue ( kv . Key , out newName ) )
383
+ if ( ! queryStringParamsRenameList . TryGetValue ( kv . Key , out newName ) )
359
384
{
360
385
patchedParams . Add ( kv . Key , kv . Value ) ;
361
386
continue ;
0 commit comments