@@ -49,11 +49,13 @@ namespace {{packageName}}.Client
49
49
string.Format(" Error calling {0}: {1}" , methodName, response.RawContent),
50
50
response.RawContent, response.Headers);
51
51
}
52
- { {^netStandard} }if (status == 0)
52
+ { {^netStandard} }
53
+ if (status == 0)
53
54
{
54
55
return new ApiException(status,
55
56
string.Format(" Error calling {0}: {1}" , methodName, response.ErrorText), response.ErrorText);
56
- } { {/netStandard} }
57
+ }
58
+ { {/netStandard} }
57
59
return null;
58
60
};
59
61
@@ -82,6 +84,14 @@ namespace {{packageName}}.Client
82
84
83
85
private string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
84
86
private string _tempFolderPath = Path.GetTempPath();
87
+ { {#servers.0} }
88
+
89
+ /// <summary >
90
+ /// Gets or sets the servers defined in the OpenAPI spec.
91
+ /// </summary >
92
+ /// <value >The servers</value >
93
+ private IList<IReadOnlyDictionary <string, object >> _servers;
94
+ { {/servers.0} }
85
95
86
96
/// <summary >
87
97
/// HTTPSigning configuration
@@ -102,6 +112,48 @@ namespace {{packageName}}.Client
102
112
DefaultHeaders = new {{^net35} }Concurrent{ {/net35} }Dictionary<string , string >();
103
113
ApiKey = new { {^net35} }Concurrent{ {/net35} }Dictionary<string , string >();
104
114
ApiKeyPrefix = new { {^net35} }Concurrent{ {/net35} }Dictionary<string , string >();
115
+ { {#servers} }
116
+ { {#-first} }
117
+ Servers = new List<IReadOnlyDictionary <string, object >>()
118
+ {
119
+ {{/-first} }
120
+ {
121
+ new Dictionary< string, object> {
122
+ {" url" , " {{{url}}}" } ,
123
+ { " description" , " {{{description}}}{{^description}}No description provided{{/description}}" } ,
124
+ { {#variables} }
125
+ { {#-first} }
126
+ {
127
+ " variables" , new Dictionary< string, object> {
128
+ {{/-first} }
129
+ {
130
+ " {{{name}}}" , new Dictionary< string, object> {
131
+ {" description" , " {{{description}}}{{^description}}No description provided{{/description}}" } ,
132
+ { " default_value" , " {{{defaultValue}}}" } ,
133
+ { {#enumValues} }
134
+ { {#-first} }
135
+ {
136
+ " enum_values" , new List< string> () {
137
+ {{/-first} }
138
+ "{ {{.} }}"{ {^-last} },{ {/-last} }
139
+ { {#-last} }
140
+ }
141
+ }
142
+ { {/-last} }
143
+ { {/enumValues} }
144
+ }
145
+ }{ {^-last} },{ {/-last} }
146
+ { {#-last} }
147
+ }
148
+ }
149
+ { {/-last} }
150
+ { {/variables} }
151
+ }
152
+ }{ {^-last} },{ {/-last} }
153
+ { {#-last} }
154
+ };
155
+ { {/-last} }
156
+ { {/servers} }
105
157
106
158
// Setting Timeout has side effects (forces ApiClient creation).
107
159
Timeout = 100000;
@@ -337,6 +389,84 @@ namespace {{packageName}}.Client
337
389
_apiKey = value;
338
390
}
339
391
}
392
+ { {#servers.0} }
393
+
394
+ /// <summary >
395
+ /// Gets or sets the servers.
396
+ /// </summary >
397
+ /// <value >The servers.</value >
398
+ public virtual IList<IReadOnlyDictionary <string, object >> Servers
399
+ {
400
+ get { return _servers; }
401
+ set
402
+ {
403
+ if (value == null)
404
+ {
405
+ throw new InvalidOperationException(" Servers may not be null." );
406
+ }
407
+ _servers = value;
408
+ }
409
+ }
410
+
411
+ /// <summary >
412
+ /// Returns URL based on server settings without providing values
413
+ /// for the variables
414
+ /// </summary >
415
+ /// <param name =" index" >Array index of the server settings.</param >
416
+ /// <return >The server URL.</return >
417
+ public string GetServerUrl(int index)
418
+ {
419
+ return GetServerUrl(index, null);
420
+ }
421
+
422
+ /// <summary >
423
+ /// Returns URL based on server settings.
424
+ /// </summary >
425
+ /// <param name =" index" >Array index of the server settings.</param >
426
+ /// <param name =" inputVariables" >Dictionary of the variables and the corresponding values.</param >
427
+ /// <return >The server URL.</return >
428
+ public string GetServerUrl(int index, Dictionary<string , string > inputVariables)
429
+ {
430
+ if (index < 0 || index >= Servers.Count)
431
+ {
432
+ throw new InvalidOperationException($" Invalid index {index} when selecting the server. Must be less than {Servers.Count}." );
433
+ }
434
+
435
+ if (inputVariables == null)
436
+ {
437
+ inputVariables = new Dictionary< string, string> ();
438
+ }
439
+
440
+ IReadOnlyDictionary<string , object > server = Servers[index];
441
+ string url = (string)server["url"];
442
+
443
+ // go through variable and assign a value
444
+ foreach (KeyValuePair<string , object > variable in (IReadOnlyDictionary<string , object >)server["variables"])
445
+ {
446
+
447
+ IReadOnlyDictionary< string, object> serverVariables = (IReadOnlyDictionary< string, object> )(variable.Value);
448
+
449
+ if (inputVariables.ContainsKey(variable.Key))
450
+ {
451
+ if (((List< string> )serverVariables[" enum_values" ]).Contains(inputVariables[variable.Key]))
452
+ {
453
+ url = url.Replace(" {" + variable.Key + " }" , inputVariables[variable.Key]);
454
+ }
455
+ else
456
+ {
457
+ throw new InvalidOperationException($" The variable `{variable.Key}` in the server URL has invalid value #{inputVariables[variable.Key]}. Must be {(List<string>)serverVariables[" enum_values" ]}" );
458
+ }
459
+ }
460
+ else
461
+ {
462
+ // use defualt value
463
+ url = url.Replace(" {" + variable.Key + " }" , (string)serverVariables[" default_value" ]);
464
+ }
465
+ }
466
+
467
+ return url;
468
+ }
469
+ { {/servers.0} }
340
470
341
471
/// <summary >
342
472
/// Gets and Sets the HTTPSigningConfiuration
@@ -431,4 +561,4 @@ namespace {{packageName}}.Client
431
561
}
432
562
#endregion Static Members
433
563
}
434
- }
564
+ }
0 commit comments