Skip to content

Commit 8a330e9

Browse files
committed
Improve type checking for closure-angular
Closure angular now has more accurate type checking enabled.
1 parent f1ba6f5 commit 8a330e9

File tree

4 files changed

+243
-203
lines changed

4 files changed

+243
-203
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ goog.require('{{import}}');
4747
/** @private {!angular.$http} */
4848
this.http_ = $http;
4949

50-
/** @private {!Object} */
51-
this.httpParamSerializer_ = $injector.get('$httpParamSerializer');
50+
/** @package {!Object} */
51+
this.httpParamSerializer = $injector.get('$httpParamSerializer');
5252
}
5353
{{package}}.{{classname}}.$inject = ['$http', '$httpParamSerializer', '$injector'];
5454
{{#operation}}
@@ -69,7 +69,7 @@ goog.require('{{import}}');
6969
var queryParameters = {};
7070

7171
/** @type {!Object} */
72-
var headerParams = angular.extend({}, this.defaultHeaders);
72+
var headerParams = angular.extend({}, this.defaultHeaders_);
7373
{{#hasFormParams}}
7474
/** @type {!Object} */
7575
var formParams = {};
@@ -108,7 +108,7 @@ goog.require('{{import}}');
108108
json: {{#hasFormParams}}false{{/hasFormParams}}{{^hasFormParams}}true{{/hasFormParams}},
109109
{{#bodyParam}}data: {{^required}}opt_{{/required}}{{paramName}},
110110
{{/bodyParam}}
111-
{{#hasFormParams}}data: this.httpParamSerializer_(formParams),
111+
{{#hasFormParams}}data: this.httpParamSerializer(formParams),
112112
{{/hasFormParams}}
113113
params: queryParameters,
114114
headers: headerParams
@@ -118,7 +118,7 @@ goog.require('{{import}}');
118118
httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams);
119119
}
120120

121-
return this.http_(httpRequestParams);
121+
return (/** @type {?} */ (this.http_))(httpRequestParams);
122122
}
123123
{{/operation}}
124124
{{/operations}}

samples/client/petstore/javascript-closure-angular/API/Client/PetApi.js

Lines changed: 86 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Do not edit this file by hand or your changes will be lost next time it is
44
* generated.
55
*
6-
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
6+
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
77
* Version: 1.0.0
8-
* Generated at: 2016-04-16T18:02:07.029+08:00
8+
* Generated at: 2016-04-28T06:15:51.482Z
99
* Generated by: class io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen
1010
*/
1111
/**
@@ -40,86 +40,87 @@ API.Client.PetApi = function($http, $httpParamSerializer, $injector) {
4040
/** @private {!angular.$http} */
4141
this.http_ = $http;
4242

43-
/** @private {!Object} */
44-
this.httpParamSerializer_ = $injector.get('$httpParamSerializer');
43+
/** @package {!Object} */
44+
this.httpParamSerializer = $injector.get('$httpParamSerializer');
4545
}
4646
API.Client.PetApi.$inject = ['$http', '$httpParamSerializer', '$injector'];
4747

4848
/**
49-
* Add a new pet to the store
49+
* Update an existing pet
5050
*
5151
* @param {!Pet} body Pet object that needs to be added to the store
5252
* @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send.
5353
* @return {!angular.$q.Promise}
5454
*/
55-
API.Client.PetApi.prototype.addPet = function(body, opt_extraHttpRequestParams) {
55+
API.Client.PetApi.prototype.updatePet = function(body, opt_extraHttpRequestParams) {
5656
/** @const {string} */
5757
var path = this.basePath_ + '/pet';
5858

5959
/** @type {!Object} */
6060
var queryParameters = {};
6161

6262
/** @type {!Object} */
63-
var headerParams = angular.extend({}, this.defaultHeaders);
63+
var headerParams = angular.extend({}, this.defaultHeaders_);
6464
// verify required parameter 'body' is set
6565
if (!body) {
66-
throw new Error('Missing required parameter body when calling addPet');
66+
throw new Error('Missing required parameter body when calling updatePet');
6767
}
6868
/** @type {!Object} */
6969
var httpRequestParams = {
70-
method: 'POST',
70+
method: 'PUT',
7171
url: path,
7272
json: true,
7373
data: body,
74-
params: queryParameters,
74+
75+
76+
params: queryParameters,
7577
headers: headerParams
7678
};
7779

7880
if (opt_extraHttpRequestParams) {
7981
httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams);
8082
}
8183

82-
return this.http_(httpRequestParams);
84+
return (/** @type {?} */ (this.http_))(httpRequestParams);
8385
}
8486

8587
/**
86-
* Deletes a pet
88+
* Add a new pet to the store
8789
*
88-
* @param {!number} petId Pet id to delete
89-
* @param {!string=} opt_apiKey
90+
* @param {!Pet} body Pet object that needs to be added to the store
9091
* @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send.
9192
* @return {!angular.$q.Promise}
9293
*/
93-
API.Client.PetApi.prototype.deletePet = function(petId, opt_apiKey, opt_extraHttpRequestParams) {
94+
API.Client.PetApi.prototype.addPet = function(body, opt_extraHttpRequestParams) {
9495
/** @const {string} */
95-
var path = this.basePath_ + '/pet/{petId}'
96-
.replace('{' + 'petId' + '}', String(petId));
96+
var path = this.basePath_ + '/pet';
9797

9898
/** @type {!Object} */
9999
var queryParameters = {};
100100

101101
/** @type {!Object} */
102-
var headerParams = angular.extend({}, this.defaultHeaders);
103-
// verify required parameter 'petId' is set
104-
if (!petId) {
105-
throw new Error('Missing required parameter petId when calling deletePet');
102+
var headerParams = angular.extend({}, this.defaultHeaders_);
103+
// verify required parameter 'body' is set
104+
if (!body) {
105+
throw new Error('Missing required parameter body when calling addPet');
106106
}
107-
headerParams['api_key'] = opt_apiKey;
108-
109107
/** @type {!Object} */
110108
var httpRequestParams = {
111-
method: 'DELETE',
109+
method: 'POST',
112110
url: path,
113111
json: true,
114-
params: queryParameters,
112+
data: body,
113+
114+
115+
params: queryParameters,
115116
headers: headerParams
116117
};
117118

118119
if (opt_extraHttpRequestParams) {
119120
httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams);
120121
}
121122

122-
return this.http_(httpRequestParams);
123+
return (/** @type {?} */ (this.http_))(httpRequestParams);
123124
}
124125

125126
/**
@@ -137,7 +138,7 @@ API.Client.PetApi.prototype.findPetsByStatus = function(status, opt_extraHttpReq
137138
var queryParameters = {};
138139

139140
/** @type {!Object} */
140-
var headerParams = angular.extend({}, this.defaultHeaders);
141+
var headerParams = angular.extend({}, this.defaultHeaders_);
141142
// verify required parameter 'status' is set
142143
if (!status) {
143144
throw new Error('Missing required parameter status when calling findPetsByStatus');
@@ -151,15 +152,17 @@ API.Client.PetApi.prototype.findPetsByStatus = function(status, opt_extraHttpReq
151152
method: 'GET',
152153
url: path,
153154
json: true,
154-
params: queryParameters,
155+
156+
157+
params: queryParameters,
155158
headers: headerParams
156159
};
157160

158161
if (opt_extraHttpRequestParams) {
159162
httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams);
160163
}
161164

162-
return this.http_(httpRequestParams);
165+
return (/** @type {?} */ (this.http_))(httpRequestParams);
163166
}
164167

165168
/**
@@ -177,7 +180,7 @@ API.Client.PetApi.prototype.findPetsByTags = function(tags, opt_extraHttpRequest
177180
var queryParameters = {};
178181

179182
/** @type {!Object} */
180-
var headerParams = angular.extend({}, this.defaultHeaders);
183+
var headerParams = angular.extend({}, this.defaultHeaders_);
181184
// verify required parameter 'tags' is set
182185
if (!tags) {
183186
throw new Error('Missing required parameter tags when calling findPetsByTags');
@@ -191,15 +194,17 @@ API.Client.PetApi.prototype.findPetsByTags = function(tags, opt_extraHttpRequest
191194
method: 'GET',
192195
url: path,
193196
json: true,
194-
params: queryParameters,
197+
198+
199+
params: queryParameters,
195200
headers: headerParams
196201
};
197202

198203
if (opt_extraHttpRequestParams) {
199204
httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams);
200205
}
201206

202-
return this.http_(httpRequestParams);
207+
return (/** @type {?} */ (this.http_))(httpRequestParams);
203208
}
204209

205210
/**
@@ -218,7 +223,7 @@ API.Client.PetApi.prototype.getPetById = function(petId, opt_extraHttpRequestPar
218223
var queryParameters = {};
219224

220225
/** @type {!Object} */
221-
var headerParams = angular.extend({}, this.defaultHeaders);
226+
var headerParams = angular.extend({}, this.defaultHeaders_);
222227
// verify required parameter 'petId' is set
223228
if (!petId) {
224229
throw new Error('Missing required parameter petId when calling getPetById');
@@ -228,64 +233,79 @@ API.Client.PetApi.prototype.getPetById = function(petId, opt_extraHttpRequestPar
228233
method: 'GET',
229234
url: path,
230235
json: true,
231-
params: queryParameters,
236+
237+
238+
params: queryParameters,
232239
headers: headerParams
233240
};
234241

235242
if (opt_extraHttpRequestParams) {
236243
httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams);
237244
}
238245

239-
return this.http_(httpRequestParams);
246+
return (/** @type {?} */ (this.http_))(httpRequestParams);
240247
}
241248

242249
/**
243-
* Update an existing pet
250+
* Updates a pet in the store with form data
244251
*
245-
* @param {!Pet} body Pet object that needs to be added to the store
252+
* @param {!number} petId ID of pet that needs to be updated
253+
* @param {!string=} opt_name Updated name of the pet
254+
* @param {!string=} opt_status Updated status of the pet
246255
* @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send.
247256
* @return {!angular.$q.Promise}
248257
*/
249-
API.Client.PetApi.prototype.updatePet = function(body, opt_extraHttpRequestParams) {
258+
API.Client.PetApi.prototype.updatePetWithForm = function(petId, opt_name, opt_status, opt_extraHttpRequestParams) {
250259
/** @const {string} */
251-
var path = this.basePath_ + '/pet';
260+
var path = this.basePath_ + '/pet/{petId}'
261+
.replace('{' + 'petId' + '}', String(petId));
252262

253263
/** @type {!Object} */
254264
var queryParameters = {};
255265

256266
/** @type {!Object} */
257-
var headerParams = angular.extend({}, this.defaultHeaders);
258-
// verify required parameter 'body' is set
259-
if (!body) {
260-
throw new Error('Missing required parameter body when calling updatePet');
267+
var headerParams = angular.extend({}, this.defaultHeaders_);
268+
/** @type {!Object} */
269+
var formParams = {};
270+
271+
// verify required parameter 'petId' is set
272+
if (!petId) {
273+
throw new Error('Missing required parameter petId when calling updatePetWithForm');
261274
}
275+
headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
276+
277+
formParams['name'] = opt_name;
278+
279+
formParams['status'] = opt_status;
280+
262281
/** @type {!Object} */
263282
var httpRequestParams = {
264-
method: 'PUT',
283+
method: 'POST',
265284
url: path,
266-
json: true,
267-
data: body,
268-
params: queryParameters,
285+
json: false,
286+
287+
data: this.httpParamSerializer(formParams),
288+
289+
params: queryParameters,
269290
headers: headerParams
270291
};
271292

272293
if (opt_extraHttpRequestParams) {
273294
httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams);
274295
}
275296

276-
return this.http_(httpRequestParams);
297+
return (/** @type {?} */ (this.http_))(httpRequestParams);
277298
}
278299

279300
/**
280-
* Updates a pet in the store with form data
301+
* Deletes a pet
281302
*
282-
* @param {!number} petId ID of pet that needs to be updated
283-
* @param {!string=} opt_name Updated name of the pet
284-
* @param {!string=} opt_status Updated status of the pet
303+
* @param {!number} petId Pet id to delete
304+
* @param {!string=} opt_apiKey
285305
* @param {!angular.$http.Config=} opt_extraHttpRequestParams Extra HTTP parameters to send.
286306
* @return {!angular.$q.Promise}
287307
*/
288-
API.Client.PetApi.prototype.updatePetWithForm = function(petId, opt_name, opt_status, opt_extraHttpRequestParams) {
308+
API.Client.PetApi.prototype.deletePet = function(petId, opt_apiKey, opt_extraHttpRequestParams) {
289309
/** @const {string} */
290310
var path = this.basePath_ + '/pet/{petId}'
291311
.replace('{' + 'petId' + '}', String(petId));
@@ -294,26 +314,20 @@ API.Client.PetApi.prototype.updatePetWithForm = function(petId, opt_name, opt_st
294314
var queryParameters = {};
295315

296316
/** @type {!Object} */
297-
var headerParams = angular.extend({}, this.defaultHeaders);
298-
/** @type {!Object} */
299-
var formParams = {};
300-
317+
var headerParams = angular.extend({}, this.defaultHeaders_);
301318
// verify required parameter 'petId' is set
302319
if (!petId) {
303-
throw new Error('Missing required parameter petId when calling updatePetWithForm');
320+
throw new Error('Missing required parameter petId when calling deletePet');
304321
}
305-
headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
306-
307-
formParams['name'] = opt_name;
308-
309-
formParams['status'] = opt_status;
322+
headerParams['api_key'] = opt_apiKey;
310323

311324
/** @type {!Object} */
312325
var httpRequestParams = {
313-
method: 'POST',
326+
method: 'DELETE',
314327
url: path,
315-
json: false,
316-
data: this.httpParamSerializer_(formParams),
328+
json: true,
329+
330+
317331
params: queryParameters,
318332
headers: headerParams
319333
};
@@ -322,7 +336,7 @@ API.Client.PetApi.prototype.updatePetWithForm = function(petId, opt_name, opt_st
322336
httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams);
323337
}
324338

325-
return this.http_(httpRequestParams);
339+
return (/** @type {?} */ (this.http_))(httpRequestParams);
326340
}
327341

328342
/**
@@ -343,7 +357,7 @@ API.Client.PetApi.prototype.uploadFile = function(petId, opt_additionalMetadata,
343357
var queryParameters = {};
344358

345359
/** @type {!Object} */
346-
var headerParams = angular.extend({}, this.defaultHeaders);
360+
var headerParams = angular.extend({}, this.defaultHeaders_);
347361
/** @type {!Object} */
348362
var formParams = {};
349363

@@ -362,7 +376,9 @@ API.Client.PetApi.prototype.uploadFile = function(petId, opt_additionalMetadata,
362376
method: 'POST',
363377
url: path,
364378
json: false,
365-
data: this.httpParamSerializer_(formParams),
379+
380+
data: this.httpParamSerializer(formParams),
381+
366382
params: queryParameters,
367383
headers: headerParams
368384
};
@@ -371,5 +387,5 @@ API.Client.PetApi.prototype.uploadFile = function(petId, opt_additionalMetadata,
371387
httpRequestParams = angular.extend(httpRequestParams, opt_extraHttpRequestParams);
372388
}
373389

374-
return this.http_(httpRequestParams);
390+
return (/** @type {?} */ (this.http_))(httpRequestParams);
375391
}

0 commit comments

Comments
 (0)