Skip to content

Commit 61690d6

Browse files
committed
change the constructor signature to be backwards compatible
update petstore samples for angular and node
1 parent 1cd8141 commit 61690d6

File tree

6 files changed

+176
-178
lines changed

6 files changed

+176
-178
lines changed

modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module {{package}} {
1616
1717
static $inject: string[] = ['$http', '$httpParamSerializer'];
1818
19-
constructor(private $http: ng.IHttpService, private $httpParamSerializer: (any) => any, basePath?: string) {
19+
constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (any) => any) {
2020
if (basePath) {
2121
this.basePath = basePath;
2222
}

samples/client/petstore/typescript-angular/API/Client/PetApi.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module API.Client {
88
export class PetApi {
99
private basePath = 'http://petstore.swagger.io/v2';
1010

11-
static $inject: string[] = ['$http'];
11+
static $inject: string[] = ['$http', '$httpParamSerializer'];
1212

13-
constructor(private $http: ng.IHttpService, basePath?: string) {
13+
constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (any) => any) {
1414
if (basePath) {
1515
this.basePath = basePath;
1616
}
@@ -21,13 +21,13 @@ module API.Client {
2121

2222
var queryParameters: any = {};
2323
var headerParams: any = {};
24-
2524
var httpRequestParams: any = {
2625
method: 'PUT',
2726
url: path,
2827
json: true,
2928
data: body,
3029

30+
3131
params: queryParameters,
3232
headers: headerParams
3333
};
@@ -48,13 +48,13 @@ module API.Client {
4848

4949
var queryParameters: any = {};
5050
var headerParams: any = {};
51-
5251
var httpRequestParams: any = {
5352
method: 'POST',
5453
url: path,
5554
json: true,
5655
data: body,
5756

57+
5858
params: queryParameters,
5959
headers: headerParams
6060
};
@@ -75,7 +75,6 @@ module API.Client {
7575

7676
var queryParameters: any = {};
7777
var headerParams: any = {};
78-
7978
if (status !== undefined) {
8079
queryParameters['status'] = status;
8180
}
@@ -85,6 +84,7 @@ module API.Client {
8584
url: path,
8685
json: true,
8786

87+
8888
params: queryParameters,
8989
headers: headerParams
9090
};
@@ -105,7 +105,6 @@ module API.Client {
105105

106106
var queryParameters: any = {};
107107
var headerParams: any = {};
108-
109108
if (tags !== undefined) {
110109
queryParameters['tags'] = tags;
111110
}
@@ -115,6 +114,7 @@ module API.Client {
115114
url: path,
116115
json: true,
117116

117+
118118
params: queryParameters,
119119
headers: headerParams
120120
};
@@ -137,7 +137,6 @@ module API.Client {
137137

138138
var queryParameters: any = {};
139139
var headerParams: any = {};
140-
141140
// verify required parameter 'petId' is set
142141
if (!petId) {
143142
throw new Error('Missing required parameter petId when calling getPetById');
@@ -148,6 +147,7 @@ module API.Client {
148147
url: path,
149148
json: true,
150149

150+
151151
params: queryParameters,
152152
headers: headerParams
153153
};
@@ -170,16 +170,25 @@ module API.Client {
170170

171171
var queryParameters: any = {};
172172
var headerParams: any = {};
173+
var formParams: any = {};
173174

174175
// verify required parameter 'petId' is set
175176
if (!petId) {
176177
throw new Error('Missing required parameter petId when calling updatePetWithForm');
177178
}
178179

180+
headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
181+
182+
formParams['name'] = name;
183+
184+
formParams['status'] = status;
185+
179186
var httpRequestParams: any = {
180187
method: 'POST',
181188
url: path,
182-
json: true,
189+
json: false,
190+
191+
data: this.$httpParamSerializer(formParams),
183192

184193
params: queryParameters,
185194
headers: headerParams
@@ -203,19 +212,19 @@ module API.Client {
203212

204213
var queryParameters: any = {};
205214
var headerParams: any = {};
206-
207215
// verify required parameter 'petId' is set
208216
if (!petId) {
209217
throw new Error('Missing required parameter petId when calling deletePet');
210218
}
211219

212-
headerParams['apiKey'] = apiKey;
220+
headerParams['api_key'] = apiKey;
213221

214222
var httpRequestParams: any = {
215223
method: 'DELETE',
216224
url: path,
217225
json: true,
218226

227+
219228
params: queryParameters,
220229
headers: headerParams
221230
};
@@ -238,16 +247,25 @@ module API.Client {
238247

239248
var queryParameters: any = {};
240249
var headerParams: any = {};
250+
var formParams: any = {};
241251

242252
// verify required parameter 'petId' is set
243253
if (!petId) {
244254
throw new Error('Missing required parameter petId when calling uploadFile');
245255
}
246256

257+
headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
258+
259+
formParams['additionalMetadata'] = additionalMetadata;
260+
261+
formParams['file'] = file;
262+
247263
var httpRequestParams: any = {
248264
method: 'POST',
249265
url: path,
250-
json: true,
266+
json: false,
267+
268+
data: this.$httpParamSerializer(formParams),
251269

252270
params: queryParameters,
253271
headers: headerParams

samples/client/petstore/typescript-angular/API/Client/StoreApi.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module API.Client {
88
export class StoreApi {
99
private basePath = 'http://petstore.swagger.io/v2';
1010

11-
static $inject: string[] = ['$http'];
11+
static $inject: string[] = ['$http', '$httpParamSerializer'];
1212

13-
constructor(private $http: ng.IHttpService, basePath?: string) {
13+
constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (any) => any) {
1414
if (basePath) {
1515
this.basePath = basePath;
1616
}
@@ -21,12 +21,12 @@ module API.Client {
2121

2222
var queryParameters: any = {};
2323
var headerParams: any = {};
24-
2524
var httpRequestParams: any = {
2625
method: 'GET',
2726
url: path,
2827
json: true,
2928

29+
3030
params: queryParameters,
3131
headers: headerParams
3232
};
@@ -47,13 +47,13 @@ module API.Client {
4747

4848
var queryParameters: any = {};
4949
var headerParams: any = {};
50-
5150
var httpRequestParams: any = {
5251
method: 'POST',
5352
url: path,
5453
json: true,
5554
data: body,
5655

56+
5757
params: queryParameters,
5858
headers: headerParams
5959
};
@@ -76,7 +76,6 @@ module API.Client {
7676

7777
var queryParameters: any = {};
7878
var headerParams: any = {};
79-
8079
// verify required parameter 'orderId' is set
8180
if (!orderId) {
8281
throw new Error('Missing required parameter orderId when calling getOrderById');
@@ -87,6 +86,7 @@ module API.Client {
8786
url: path,
8887
json: true,
8988

89+
9090
params: queryParameters,
9191
headers: headerParams
9292
};
@@ -109,7 +109,6 @@ module API.Client {
109109

110110
var queryParameters: any = {};
111111
var headerParams: any = {};
112-
113112
// verify required parameter 'orderId' is set
114113
if (!orderId) {
115114
throw new Error('Missing required parameter orderId when calling deleteOrder');
@@ -120,6 +119,7 @@ module API.Client {
120119
url: path,
121120
json: true,
122121

122+
123123
params: queryParameters,
124124
headers: headerParams
125125
};

samples/client/petstore/typescript-angular/API/Client/UserApi.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module API.Client {
88
export class UserApi {
99
private basePath = 'http://petstore.swagger.io/v2';
1010

11-
static $inject: string[] = ['$http'];
11+
static $inject: string[] = ['$http', '$httpParamSerializer'];
1212

13-
constructor(private $http: ng.IHttpService, basePath?: string) {
13+
constructor(private $http: ng.IHttpService, basePath?: string, private $httpParamSerializer?: (any) => any) {
1414
if (basePath) {
1515
this.basePath = basePath;
1616
}
@@ -21,13 +21,13 @@ module API.Client {
2121

2222
var queryParameters: any = {};
2323
var headerParams: any = {};
24-
2524
var httpRequestParams: any = {
2625
method: 'POST',
2726
url: path,
2827
json: true,
2928
data: body,
3029

30+
3131
params: queryParameters,
3232
headers: headerParams
3333
};
@@ -48,13 +48,13 @@ module API.Client {
4848

4949
var queryParameters: any = {};
5050
var headerParams: any = {};
51-
5251
var httpRequestParams: any = {
5352
method: 'POST',
5453
url: path,
5554
json: true,
5655
data: body,
5756

57+
5858
params: queryParameters,
5959
headers: headerParams
6060
};
@@ -75,13 +75,13 @@ module API.Client {
7575

7676
var queryParameters: any = {};
7777
var headerParams: any = {};
78-
7978
var httpRequestParams: any = {
8079
method: 'POST',
8180
url: path,
8281
json: true,
8382
data: body,
8483

84+
8585
params: queryParameters,
8686
headers: headerParams
8787
};
@@ -102,7 +102,6 @@ module API.Client {
102102

103103
var queryParameters: any = {};
104104
var headerParams: any = {};
105-
106105
if (username !== undefined) {
107106
queryParameters['username'] = username;
108107
}
@@ -116,6 +115,7 @@ module API.Client {
116115
url: path,
117116
json: true,
118117

118+
119119
params: queryParameters,
120120
headers: headerParams
121121
};
@@ -136,12 +136,12 @@ module API.Client {
136136

137137
var queryParameters: any = {};
138138
var headerParams: any = {};
139-
140139
var httpRequestParams: any = {
141140
method: 'GET',
142141
url: path,
143142
json: true,
144143

144+
145145
params: queryParameters,
146146
headers: headerParams
147147
};
@@ -164,7 +164,6 @@ module API.Client {
164164

165165
var queryParameters: any = {};
166166
var headerParams: any = {};
167-
168167
// verify required parameter 'username' is set
169168
if (!username) {
170169
throw new Error('Missing required parameter username when calling getUserByName');
@@ -175,6 +174,7 @@ module API.Client {
175174
url: path,
176175
json: true,
177176

177+
178178
params: queryParameters,
179179
headers: headerParams
180180
};
@@ -197,7 +197,6 @@ module API.Client {
197197

198198
var queryParameters: any = {};
199199
var headerParams: any = {};
200-
201200
// verify required parameter 'username' is set
202201
if (!username) {
203202
throw new Error('Missing required parameter username when calling updateUser');
@@ -209,6 +208,7 @@ module API.Client {
209208
json: true,
210209
data: body,
211210

211+
212212
params: queryParameters,
213213
headers: headerParams
214214
};
@@ -231,7 +231,6 @@ module API.Client {
231231

232232
var queryParameters: any = {};
233233
var headerParams: any = {};
234-
235234
// verify required parameter 'username' is set
236235
if (!username) {
237236
throw new Error('Missing required parameter username when calling deleteUser');
@@ -242,6 +241,7 @@ module API.Client {
242241
url: path,
243242
json: true,
244243

244+
245245
params: queryParameters,
246246
headers: headerParams
247247
};

samples/client/petstore/typescript-angular/API/Client/api.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
/// <reference path="Order.ts" />
66

77
/// <reference path="UserApi.ts" />
8-
/// <reference path="PetApi.ts" />
98
/// <reference path="StoreApi.ts" />
9+
/// <reference path="PetApi.ts" />

0 commit comments

Comments
 (0)