Skip to content

Commit

Permalink
Merge pull request #2287 from vzeman/issue-2275
Browse files Browse the repository at this point in the history
Add option to set request timeout for Javascript request
  • Loading branch information
wing328 committed Mar 1, 2016
2 parents 6ca6606 + 734681a commit ab98f1a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
* The default HTTP headers to be included for all API calls.
*/
this.defaultHeaders = {};

/**
* The default HTTP timeout for all API calls.
*/
this.timeout = 60000;
};

ApiClient.prototype.paramToString = function paramToString(param) {
Expand Down Expand Up @@ -231,6 +236,9 @@
// set header parameters
request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));
//set request timeout
request.timeout(this.timeout);
var contentType = this.jsonPreferredMime(contentTypes);
if (contentType) {
request.type(contentType);
Expand Down
16 changes: 12 additions & 4 deletions samples/client/petstore/javascript/src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,23 @@
this.basePath = 'http://petstore.swagger.io/v2'.replace(/\/+$/, '');

this.authentications = {
'petstore_auth': {type: 'oauth2'},
'test_api_client_id': {type: 'apiKey', in: 'header', name: 'x-test_api_client_id'},
'test_api_client_secret': {type: 'apiKey', in: 'header', name: 'x-test_api_client_secret'},
'test_api_key_header': {type: 'apiKey', in: 'header', name: 'test_api_key_header'},
'api_key': {type: 'apiKey', in: 'header', name: 'api_key'},
'test_api_client_secret': {type: 'apiKey', in: 'header', name: 'x-test_api_client_secret'},
'test_api_client_id': {type: 'apiKey', in: 'header', name: 'x-test_api_client_id'},
'test_api_key_query': {type: 'apiKey', in: 'query', name: 'test_api_key_query'},
'test_api_key_header': {type: 'apiKey', in: 'header', name: 'test_api_key_header'}
'petstore_auth': {type: 'oauth2'}
};

/**
* The default HTTP headers to be included for all API calls.
*/
this.defaultHeaders = {};

/**
* The default HTTP timeout for all API calls.
*/
this.timeout = 60000;
};

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

//set request timeout
request.timeout(this.timeout);

var contentType = this.jsonPreferredMime(contentTypes);
if (contentType) {
request.type(contentType);
Expand Down
8 changes: 4 additions & 4 deletions samples/client/petstore/javascript/src/api/PetApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@

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

var authNames = ['petstore_auth', 'api_key'];
var authNames = ['api_key', 'petstore_auth'];
var contentTypes = [];
var accepts = ['application/json', 'application/xml'];
var returnType = Pet;
Expand Down Expand Up @@ -349,7 +349,7 @@
var formParams = {
};

var authNames = ['petstore_auth', 'api_key'];
var authNames = ['api_key', 'petstore_auth'];
var contentTypes = [];
var accepts = ['application/json', 'application/xml'];
var returnType = 'String';
Expand Down
37 changes: 36 additions & 1 deletion samples/client/petstore/javascript/src/api/StoreApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,41 @@
var self = this;


/**
* Finds orders by status
* A single status value can be provided as a string
* @param {String} opts['status'] Status value that needs to be considered for query
* @param {function} callback the callback function, accepting three arguments: error, data, response
* data is of type: [Order]
*/
self.findOrdersByStatus = function(opts, callback) {
opts = opts || {};
var postBody = null;


var pathParams = {
};
var queryParams = {
'status': opts['status']
};
var headerParams = {
};
var formParams = {
};

var authNames = ['test_api_client_id', 'test_api_client_secret'];
var contentTypes = [];
var accepts = ['application/json', 'application/xml'];
var returnType = [Order];

return this.apiClient.callApi(
'/store/findByStatus', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);

}

/**
* Returns pet inventories by status
* Returns a map of status codes to quantities
Expand Down Expand Up @@ -113,7 +148,7 @@
var formParams = {
};

var authNames = ['test_api_key_query', 'test_api_key_header'];
var authNames = ['test_api_key_header', 'test_api_key_query'];
var contentTypes = [];
var accepts = ['application/json', 'application/xml'];
var returnType = Order;
Expand Down
14 changes: 7 additions & 7 deletions samples/client/petstore/javascript/src/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
(function(factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['./ApiClient', './model/Order', './model/User', './model/Category', './model/Tag', './model/Pet', './api/UserApi', './api/StoreApi', './api/PetApi'], factory);
define(['./ApiClient', './model/User', './model/Category', './model/Pet', './model/Tag', './model/Order', './api/UserApi', './api/PetApi', './api/StoreApi'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
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'));
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'));
}
}(function(ApiClient, Order, User, Category, Tag, Pet, UserApi, StoreApi, PetApi) {
}(function(ApiClient, User, Category, Pet, Tag, Order, UserApi, PetApi, StoreApi) {
'use strict';

return {
ApiClient: ApiClient,
Order: Order,
User: User,
Category: Category,
Tag: Tag,
Pet: Pet,
Tag: Tag,
Order: Order,
UserApi: UserApi,
StoreApi: StoreApi,
PetApi: PetApi
PetApi: PetApi,
StoreApi: StoreApi
};
}));

0 comments on commit ab98f1a

Please sign in to comment.