Skip to content

Commit f592414

Browse files
committed
Merge branch 'master' of github.com:wordnik/swagger-codegen
2 parents e1c8f58 + 4870ed7 commit f592414

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ and override the `templateDir` in your script to point to the right place. It a
130130
### Where is Javascript???
131131
See our [javascript library](http://github.com/wordnik/swagger.js)--it's completely dynamic and doesn't require
132132
static code generation.
133+
There is a third-party component called [swagger-js-codegen](https://github.com/wcandillon/swagger-js-codegen) that can generate angularjs or nodejs source code from a swagger specification.
134+
133135

134136
#### Generating a client from flat files (i.e. no remote server calls)
135137
If you don't want to call your server, you can save the swagger spec files into a directory and pass an argument

src/main/resources/csharp/api.mustache

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@
88
namespace {{package}} {
99
{{#operations}}
1010
public class {{classname}} {
11-
string basePath = "{{basePath}}";
11+
string basePath;
1212
private readonly ApiInvoker apiInvoker = ApiInvoker.GetInstance();
1313
14+
public {{classname}}(String basePath = "{{basePath}}")
15+
{
16+
this.basePath = basePath;
17+
}
18+
1419
public ApiInvoker getInvoker() {
1520
return apiInvoker;
1621
}
17-
22+
1823
// Sets the endpoint base url for the services being accessed
1924
public void setBasePath(string basePath) {
2025
this.basePath = basePath;
2126
}
22-
27+
2328
// Gets the endpoint base url for the services being accessed
2429
public String getBasePath() {
2530
return basePath;

src/main/resources/csharp/apiInvoker.mustache

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public static ApiInvoker GetInstance() {
1515
return _instance;
1616
}
17-
17+
1818
public void addDefaultHeader(string key, string value) {
1919
defaultHeaderMap.Add(key, value);
2020
}
@@ -46,7 +46,7 @@
4646

4747
public string invokeAPI(string host, string path, string method, Dictionary<String, String> queryParams, object body, Dictionary<String, String> headerParams) {
4848
var b = new StringBuilder();
49-
49+
5050
foreach (var queryParamItem in queryParams)
5151
{
5252
var value = queryParamItem.Value;
@@ -71,7 +71,7 @@
7171
{
7272
client.Headers.Add(defaultHeaderMapItem.Key, defaultHeaderMapItem.Value);
7373
}
74-
74+
7575
switch (method)
7676
{
7777
case "GET":
@@ -84,13 +84,17 @@
8484
swRequestWriter.Close();
8585
break;
8686
default:
87-
throw new ApiException(500, "unknown method type " + method);
87+
throw new ApiException(500, "unknown method type " + method);
8888
}
8989

9090
try
9191
{
9292
var webResponse = (HttpWebResponse)client.GetResponse();
93-
if (webResponse.StatusCode != HttpStatusCode.OK) throw new ApiException((int)webResponse.StatusCode, webResponse.StatusDescription);
93+
if (webResponse.StatusCode != HttpStatusCode.OK)
94+
{
95+
webResponse.Close();
96+
throw new ApiException((int)webResponse.StatusCode, webResponse.StatusDescription);
97+
}
9498

9599
var responseReader = new StreamReader(webResponse.GetResponseStream());
96100
var responseData = responseReader.ReadToEnd();
@@ -104,6 +108,7 @@
104108
if (response != null)
105109
{
106110
statusCode = (int)response.StatusCode;
111+
response.Close();
107112
}
108113
throw new ApiException(statusCode, ex.Message);
109114
}

0 commit comments

Comments
 (0)