Skip to content

Commit c7a5385

Browse files
committed
Merge pull request #66 from NSwag/master
Release v2.8
2 parents a6d777c + f9f0e15 commit c7a5385

File tree

12 files changed

+146
-149
lines changed

12 files changed

+146
-149
lines changed

src/NSwag.Annotations/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
[assembly: AssemblyCompany("Rico Suter")]
66
[assembly: AssemblyProduct("NSwag.Annotations")]
77
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
8-
[assembly: AssemblyVersion("2.7.*")]
8+
[assembly: AssemblyVersion("2.8.*")]

src/NSwag.CodeGeneration.Tests/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
//
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
34-
// [assembly: AssemblyVersion("2.7.*")]
34+
// [assembly: AssemblyVersion("2.8.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]
3636
[assembly: AssemblyFileVersion("1.0.0.0")]

src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/Angular2.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
9090
<if(response.IsFile)>
9191
var data = response.blob();
9292
<else>
93-
var text = response.text().replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \});
94-
var data = JSON.parse(text, this.jsonParseReviver);
93+
var data = JSON.parse(response.text(), this.jsonParseReviver);
9594
<endif>
9695
var status = response.status.toString();
9796

Lines changed: 133 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,133 @@
1-
// The Angular client template is currently NOT TESTET!
2-
3-
<if(hasOperations)>
4-
<if(generateClientInterfaces)>
5-
export interface I<class> {
6-
<operations:{operation |
7-
<if(operation.HasDocumentation)> /**
8-
<if(operation.HasSummary)> * <operation.Summary><endif>
9-
<operation.Parameters:{parameter |
10-
<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}>
11-
<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif>
12-
*/
13-
<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>>;
14-
}>}
15-
<endif>
16-
17-
export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
18-
baseUrl: string = undefined;
19-
http: ng.IHttpService = null;
20-
21-
constructor($http: ng.IHttpService, baseUrl?: string) {
22-
this.http = $http;
23-
this.baseUrl = baseUrl !== undefined ? baseUrl : "<baseUrl>";
24-
}
25-
<operations:{operation |
26-
27-
<if(operation.HasDocumentation)> /**
28-
<if(operation.HasSummary)> * <operation.Summary><endif>
29-
<operation.Parameters:{parameter |
30-
<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}>
31-
<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif>
32-
*/
33-
<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>> {
34-
var url = this.baseUrl + "/<operation.Path>?";
35-
36-
<operation.PathParameters:{parameter |
37-
if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null)
38-
throw new Error("The parameter '<parameter.VariableNameLower>' must be defined.");
39-
<if(parameter.IsDate)>
40-
url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>.toJSON());
41-
<else>
42-
url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>);
43-
<endif>
44-
}>
45-
46-
<operation.QueryParameters:{parameter |
47-
<if(parameter.IsOptional)>
48-
if (<parameter.VariableNameLower> !== undefined && <parameter.VariableNameLower> !== null)
49-
<else>
50-
if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null)
51-
throw new Error("The parameter '<parameter.VariableNameLower>' must be defined.");
52-
else
53-
<endif>
54-
<if(parameter.IsDate)>
55-
<if(parameter.IsArray)>
56-
<parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item.toJSON()) + "&"; \});
57-
<else>
58-
url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>.toJSON()) + "&";
59-
<endif>
60-
<else>
61-
<if(parameter.IsArray)>
62-
<parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item) + "&"; \});
63-
<else>
64-
url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>) + "&";
65-
<endif>
66-
<endif>
67-
}>
68-
69-
<if(operation.HasContent)>
70-
var content = JSON.stringify(<operation.ContentParameter.VariableNameLower>);
71-
<else>
72-
var content = "";
73-
<endif>
74-
75-
return this.http({
76-
url: url,
77-
method: "<operation.HttpMethodUpper>",
78-
data: content,
79-
transformResponse: [],
80-
headers: {
81-
<operation.HeaderParameters:{parameter |
82-
"<parameter.Name>": <parameter.VariableNameLower>,
83-
}> "Content-Type": "application/json; charset=UTF-8"
84-
\}
85-
\}).then((response) => {
86-
return this.process<operation.OperationNameUpper>(response);
87-
\});
88-
\}
89-
90-
private process<operation.OperationNameUpper>(response: any) {
91-
var data = response.data.replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \});
92-
var status = response.status;
93-
94-
<operation.Responses:{response |
95-
if (status === <response.StatusCode>) {
96-
<if(response.HasType)>
97-
var result<response.StatusCode>: <response.Type> = null;
98-
<if(response.IsDate)>
99-
result<response.StatusCode> = new Date(data);
100-
<else>
101-
result<response.StatusCode> = \<<response.Type>>JSON.parse(data);
102-
<endif>
103-
<if(response.IsSuccess)>
104-
return result<response.StatusCode>;
105-
<else>
106-
throw result<response.StatusCode>;
107-
<endif>
108-
<endif>
109-
\}
110-
else}>
111-
{
112-
<if(operation.HasDefaultResponse)>
113-
var result: <operation.DefaultResponse.Type> = null;
114-
<if(operation.DefaultResponse.IsDate)>
115-
result = new Date(data);
116-
<else>
117-
result = \<<operation.DefaultResponse.Type>>JSON.parse(data);
118-
<endif>
119-
<if(operation.DefaultResponse.IsSuccess)>
120-
return result;
121-
<else>
122-
throw result;
123-
<endif>
124-
<else>
125-
throw "error_no_callback_for_the_received_http_status";
126-
<endif>
127-
\}
128-
\}
129-
}>}
130-
<endif>
131-
1+
// The Angular client template is currently NOT TESTET!
2+
3+
<if(hasOperations)>
4+
<if(generateClientInterfaces)>
5+
export interface I<class> {
6+
<operations:{operation |
7+
<if(operation.HasDocumentation)> /**
8+
<if(operation.HasSummary)> * <operation.Summary><endif>
9+
<operation.Parameters:{parameter |
10+
<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}>
11+
<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif>
12+
*/
13+
<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>>;
14+
}>}
15+
<endif>
16+
17+
export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
18+
private baseUrl: string = undefined;
19+
private http: ng.IHttpService = null;
20+
private jsonParseReviver: (key: string, value: any) => any = undefined;
21+
22+
constructor($http: ng.IHttpService, baseUrl?: string, jsonParseReviver?: (key: string, value: any) => any) {
23+
this.http = $http;
24+
this.baseUrl = baseUrl !== undefined ? baseUrl : "<baseUrl>";
25+
this.jsonParseReviver = jsonParseReviver;
26+
}
27+
<operations:{operation |
28+
29+
<if(operation.HasDocumentation)> /**
30+
<if(operation.HasSummary)> * <operation.Summary><endif>
31+
<operation.Parameters:{parameter |
32+
<if(parameter.HasDescription)> * @<parameter.VariableNameLower> <parameter.Description><endif>}>
33+
<if(operation.HasResultDescription)> * @return <operation.ResultDescription><endif>
34+
*/
35+
<endif> <operation.OperationNameLower>(<operation.Parameters:{parameter | <parameter.VariableNameLower>: <parameter.Type><if(!parameter.IsLast)>, <endif>}>): ng.IPromise\<<operation.ResultType>> {
36+
var url = this.baseUrl + "/<operation.Path>?";
37+
38+
<operation.PathParameters:{parameter |
39+
if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null)
40+
throw new Error("The parameter '<parameter.VariableNameLower>' must be defined.");
41+
<if(parameter.IsDate)>
42+
url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>.toJSON());
43+
<else>
44+
url = url.replace("{<parameter.Name>\}", "" + <parameter.VariableNameLower>);
45+
<endif>
46+
}>
47+
48+
<operation.QueryParameters:{parameter |
49+
<if(parameter.IsOptional)>
50+
if (<parameter.VariableNameLower> !== undefined && <parameter.VariableNameLower> !== null)
51+
<else>
52+
if (<parameter.VariableNameLower> === undefined || <parameter.VariableNameLower> === null)
53+
throw new Error("The parameter '<parameter.VariableNameLower>' must be defined.");
54+
else
55+
<endif>
56+
<if(parameter.IsDate)>
57+
<if(parameter.IsArray)>
58+
<parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item.toJSON()) + "&"; \});
59+
<else>
60+
url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>.toJSON()) + "&";
61+
<endif>
62+
<else>
63+
<if(parameter.IsArray)>
64+
<parameter.VariableNameLower>.forEach(item => { url += "<parameter.Name>=" + encodeURIComponent("" + item) + "&"; \});
65+
<else>
66+
url += "<parameter.Name>=" + encodeURIComponent("" + <parameter.VariableNameLower>) + "&";
67+
<endif>
68+
<endif>
69+
}>
70+
71+
<if(operation.HasContent)>
72+
var content = JSON.stringify(<operation.ContentParameter.VariableNameLower>);
73+
<else>
74+
var content = "";
75+
<endif>
76+
77+
return this.http({
78+
url: url,
79+
method: "<operation.HttpMethodUpper>",
80+
data: content,
81+
transformResponse: [],
82+
headers: {
83+
<operation.HeaderParameters:{parameter |
84+
"<parameter.Name>": <parameter.VariableNameLower>,
85+
}> "Content-Type": "application/json; charset=UTF-8"
86+
\}
87+
\}).then((response) => {
88+
return this.process<operation.OperationNameUpper>(response);
89+
\});
90+
\}
91+
92+
private process<operation.OperationNameUpper>(response: any) {
93+
var data = response.data;
94+
var status = response.status;
95+
96+
<operation.Responses:{response |
97+
if (status === <response.StatusCode>) {
98+
<if(response.HasType)>
99+
var result<response.StatusCode>: <response.Type> = null;
100+
<if(response.IsDate)>
101+
result<response.StatusCode> = new Date(data);
102+
<else>
103+
result<response.StatusCode> = \<<response.Type>>JSON.parse(data, this.jsonParseReviver);
104+
<endif>
105+
<if(response.IsSuccess)>
106+
return result<response.StatusCode>;
107+
<else>
108+
throw result<response.StatusCode>;
109+
<endif>
110+
<endif>
111+
\}
112+
else}>
113+
{
114+
<if(operation.HasDefaultResponse)>
115+
var result: <operation.DefaultResponse.Type> = null;
116+
<if(operation.DefaultResponse.IsDate)>
117+
result = new Date(data);
118+
<else>
119+
result = \<<operation.DefaultResponse.Type>>JSON.parse(data, this.jsonParseReviver);
120+
<endif>
121+
<if(operation.DefaultResponse.IsSuccess)>
122+
return result;
123+
<else>
124+
throw result;
125+
<endif>
126+
<else>
127+
throw "error_no_callback_for_the_received_http_status";
128+
<endif>
129+
\}
130+
\}
131+
}>}
132+
<endif>
133+

src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryCallbacks.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
103103
<if(response.IsFile)>
104104
result<response.StatusCode> = data;
105105
<else>
106-
result<response.StatusCode> = data === "" ? null : \<<response.Type>>jQuery.parseJSON(
107-
data.replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \}));
106+
result<response.StatusCode> = data === "" ? null : \<<response.Type>>jQuery.parseJSON(data);
108107
<endif>
109108
<endif>
110109
\} catch(e) {
@@ -139,8 +138,7 @@ export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
139138
<if(response.IsFile)>
140139
result = data;
141140
<else>
142-
result = \<<operation.DefaultResponse.Type>>jQuery.parseJSON(
143-
data.replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \}));
141+
result = \<<operation.DefaultResponse.Type>>jQuery.parseJSON(data);
144142
<endif>
145143
<endif>
146144
\} catch(e) {

src/NSwag.CodeGeneration/CodeGenerators/TypeScript/Templates/JQueryPromises.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
109109
<if(response.IsFile)>
110110
result<response.StatusCode> = data;
111111
<else>
112-
result<response.StatusCode> = data === "" ? null : \<<response.Type>>jQuery.parseJSON(
113-
data.replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \}));
112+
result<response.StatusCode> = data === "" ? null : \<<response.Type>>jQuery.parseJSON(data);
114113
<endif>
115114
<endif>
116115
\} catch(e) {
@@ -145,8 +144,7 @@ export class <class> <if(generateClientInterfaces)>implements I<class> <endif>{
145144
<if(response.IsFile)>
146145
result = data;
147146
<else>
148-
result = \<<operation.DefaultResponse.Type>>jQuery.parseJSON(
149-
data.replace(/\/Date((-?\d*))\//, (a: string, b: string) => { return new Date(+b); \}));
147+
result = \<<operation.DefaultResponse.Type>>jQuery.parseJSON(data);
150148
<endif>
151149
<endif>
152150
\} catch(e) {

src/NSwag.CodeGeneration/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
[assembly: AssemblyCompany("Rico Suter")]
66
[assembly: AssemblyProduct("NSwag.CodeGeneration")]
77
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
8-
[assembly: AssemblyVersion("2.7.*")]
8+
[assembly: AssemblyVersion("2.8.*")]

src/NSwag.Core/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
[assembly: AssemblyCompany("Rico Suter")]
66
[assembly: AssemblyProduct("NSwag")]
77
[assembly: AssemblyCopyright("Copyright © Rico Suter, 2015")]
8-
[assembly: AssemblyVersion("2.7.*")]
8+
[assembly: AssemblyVersion("2.8.*")]

src/NSwag.Demo.Client/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@
5050
//
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
53-
// [assembly: AssemblyVersion("2.7.*")]
53+
// [assembly: AssemblyVersion("2.8.*")]
5454
[assembly: AssemblyVersion("1.0.0.0")]
5555
[assembly: AssemblyFileVersion("1.0.0.0")]

src/NSwag.Tests/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
//
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
34-
// [assembly: AssemblyVersion("2.7.*")]
34+
// [assembly: AssemblyVersion("2.8.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]
3636
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)