Skip to content

Commit ab98f1a

Browse files
committed
Merge pull request #2287 from vzeman/issue-2275
Add option to set request timeout for Javascript request
2 parents 6ca6606 + 734681a commit ab98f1a

File tree

5 files changed

+67
-16
lines changed

5 files changed

+67
-16
lines changed

modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
* The default HTTP headers to be included for all API calls.
3232
*/
3333
this.defaultHeaders = {};
34+
35+
/**
36+
* The default HTTP timeout for all API calls.
37+
*/
38+
this.timeout = 60000;
3439
};
3540

3641
ApiClient.prototype.paramToString = function paramToString(param) {
@@ -231,6 +236,9 @@
231236
// set header parameters
232237
request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));
233238
239+
//set request timeout
240+
request.timeout(this.timeout);
241+
234242
var contentType = this.jsonPreferredMime(contentTypes);
235243
if (contentType) {
236244
request.type(contentType);

samples/client/petstore/javascript/src/ApiClient.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@
2222
this.basePath = 'http://petstore.swagger.io/v2'.replace(/\/+$/, '');
2323

2424
this.authentications = {
25-
'petstore_auth': {type: 'oauth2'},
26-
'test_api_client_id': {type: 'apiKey', in: 'header', name: 'x-test_api_client_id'},
27-
'test_api_client_secret': {type: 'apiKey', in: 'header', name: 'x-test_api_client_secret'},
25+
'test_api_key_header': {type: 'apiKey', in: 'header', name: 'test_api_key_header'},
2826
'api_key': {type: 'apiKey', in: 'header', name: 'api_key'},
27+
'test_api_client_secret': {type: 'apiKey', in: 'header', name: 'x-test_api_client_secret'},
28+
'test_api_client_id': {type: 'apiKey', in: 'header', name: 'x-test_api_client_id'},
2929
'test_api_key_query': {type: 'apiKey', in: 'query', name: 'test_api_key_query'},
30-
'test_api_key_header': {type: 'apiKey', in: 'header', name: 'test_api_key_header'}
30+
'petstore_auth': {type: 'oauth2'}
3131
};
3232

3333
/**
3434
* The default HTTP headers to be included for all API calls.
3535
*/
3636
this.defaultHeaders = {};
37+
38+
/**
39+
* The default HTTP timeout for all API calls.
40+
*/
41+
this.timeout = 60000;
3742
};
3843

3944
ApiClient.prototype.paramToString = function paramToString(param) {
@@ -234,6 +239,9 @@
234239
// set header parameters
235240
request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));
236241

242+
//set request timeout
243+
request.timeout(this.timeout);
244+
237245
var contentType = this.jsonPreferredMime(contentTypes);
238246
if (contentType) {
239247
request.type(contentType);

samples/client/petstore/javascript/src/api/PetApi.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989

9090
/**
9191
* Finds Pets by status
92-
* Multiple status values can be provided with comma seperated strings
93-
* @param {[String]} opts['status'] Status values that need to be considered for filter
92+
* Multiple status values can be provided with comma separated strings
93+
* @param {[String]} opts['status'] Status values that need to be considered for query
9494
* @param {function} callback the callback function, accepting three arguments: error, data, response
9595
* data is of type: [Pet]
9696
*/
@@ -183,7 +183,7 @@
183183
var formParams = {
184184
};
185185

186-
var authNames = ['petstore_auth', 'api_key'];
186+
var authNames = ['api_key', 'petstore_auth'];
187187
var contentTypes = [];
188188
var accepts = ['application/json', 'application/xml'];
189189
var returnType = Pet;
@@ -349,7 +349,7 @@
349349
var formParams = {
350350
};
351351

352-
var authNames = ['petstore_auth', 'api_key'];
352+
var authNames = ['api_key', 'petstore_auth'];
353353
var contentTypes = [];
354354
var accepts = ['application/json', 'application/xml'];
355355
var returnType = 'String';

samples/client/petstore/javascript/src/api/StoreApi.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,41 @@
2121
var self = this;
2222

2323

24+
/**
25+
* Finds orders by status
26+
* A single status value can be provided as a string
27+
* @param {String} opts['status'] Status value that needs to be considered for query
28+
* @param {function} callback the callback function, accepting three arguments: error, data, response
29+
* data is of type: [Order]
30+
*/
31+
self.findOrdersByStatus = function(opts, callback) {
32+
opts = opts || {};
33+
var postBody = null;
34+
35+
36+
var pathParams = {
37+
};
38+
var queryParams = {
39+
'status': opts['status']
40+
};
41+
var headerParams = {
42+
};
43+
var formParams = {
44+
};
45+
46+
var authNames = ['test_api_client_id', 'test_api_client_secret'];
47+
var contentTypes = [];
48+
var accepts = ['application/json', 'application/xml'];
49+
var returnType = [Order];
50+
51+
return this.apiClient.callApi(
52+
'/store/findByStatus', 'GET',
53+
pathParams, queryParams, headerParams, formParams, postBody,
54+
authNames, contentTypes, accepts, returnType, callback
55+
);
56+
57+
}
58+
2459
/**
2560
* Returns pet inventories by status
2661
* Returns a map of status codes to quantities
@@ -113,7 +148,7 @@
113148
var formParams = {
114149
};
115150

116-
var authNames = ['test_api_key_query', 'test_api_key_header'];
151+
var authNames = ['test_api_key_header', 'test_api_key_query'];
117152
var contentTypes = [];
118153
var accepts = ['application/json', 'application/xml'];
119154
var returnType = Order;
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
(function(factory) {
22
if (typeof define === 'function' && define.amd) {
33
// AMD. Register as an anonymous module.
4-
define(['./ApiClient', './model/Order', './model/User', './model/Category', './model/Tag', './model/Pet', './api/UserApi', './api/StoreApi', './api/PetApi'], factory);
4+
define(['./ApiClient', './model/User', './model/Category', './model/Pet', './model/Tag', './model/Order', './api/UserApi', './api/PetApi', './api/StoreApi'], factory);
55
} else if (typeof module === 'object' && module.exports) {
66
// CommonJS-like environments that support module.exports, like Node.
7-
module.exports = factory(require('./ApiClient'), require('./model/Order'), require('./model/User'), require('./model/Category'), require('./model/Tag'), require('./model/Pet'), require('./api/UserApi'), require('./api/StoreApi'), require('./api/PetApi'));
7+
module.exports = factory(require('./ApiClient'), require('./model/User'), require('./model/Category'), require('./model/Pet'), require('./model/Tag'), require('./model/Order'), require('./api/UserApi'), require('./api/PetApi'), require('./api/StoreApi'));
88
}
9-
}(function(ApiClient, Order, User, Category, Tag, Pet, UserApi, StoreApi, PetApi) {
9+
}(function(ApiClient, User, Category, Pet, Tag, Order, UserApi, PetApi, StoreApi) {
1010
'use strict';
1111

1212
return {
1313
ApiClient: ApiClient,
14-
Order: Order,
1514
User: User,
1615
Category: Category,
17-
Tag: Tag,
1816
Pet: Pet,
17+
Tag: Tag,
18+
Order: Order,
1919
UserApi: UserApi,
20-
StoreApi: StoreApi,
21-
PetApi: PetApi
20+
PetApi: PetApi,
21+
StoreApi: StoreApi
2222
};
2323
}));

0 commit comments

Comments
 (0)