From 42a3f184ff34ea04aee0fe0a2c13ce2e8a9e638b Mon Sep 17 00:00:00 2001 From: Viktor Zeman Date: Tue, 1 Mar 2016 13:33:13 +0100 Subject: [PATCH 1/2] Add option to set request timeout for Javascript request --- .../src/main/resources/Javascript/ApiClient.mustache | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache index 6ef0a6a9dc5..409dbff81e5 100644 --- a/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache @@ -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) { @@ -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); From 734681ad59731f6454f82e078fd84c4a0d55e69e Mon Sep 17 00:00:00 2001 From: Rastislav Kostrab Date: Tue, 1 Mar 2016 14:39:16 +0100 Subject: [PATCH 2/2] Javascript samples updated --- .../petstore/javascript/src/ApiClient.js | 16 ++++++-- .../petstore/javascript/src/api/PetApi.js | 8 ++-- .../petstore/javascript/src/api/StoreApi.js | 37 ++++++++++++++++++- .../client/petstore/javascript/src/index.js | 14 +++---- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/samples/client/petstore/javascript/src/ApiClient.js b/samples/client/petstore/javascript/src/ApiClient.js index d4377e34d1a..304cac7e68d 100644 --- a/samples/client/petstore/javascript/src/ApiClient.js +++ b/samples/client/petstore/javascript/src/ApiClient.js @@ -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) { @@ -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); diff --git a/samples/client/petstore/javascript/src/api/PetApi.js b/samples/client/petstore/javascript/src/api/PetApi.js index d63d58c3c68..88f53633fce 100644 --- a/samples/client/petstore/javascript/src/api/PetApi.js +++ b/samples/client/petstore/javascript/src/api/PetApi.js @@ -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] */ @@ -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; @@ -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'; diff --git a/samples/client/petstore/javascript/src/api/StoreApi.js b/samples/client/petstore/javascript/src/api/StoreApi.js index 6abe687b7f4..0f30f8776fc 100644 --- a/samples/client/petstore/javascript/src/api/StoreApi.js +++ b/samples/client/petstore/javascript/src/api/StoreApi.js @@ -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 @@ -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; diff --git a/samples/client/petstore/javascript/src/index.js b/samples/client/petstore/javascript/src/index.js index dcf02fc1547..8b77f995df4 100644 --- a/samples/client/petstore/javascript/src/index.js +++ b/samples/client/petstore/javascript/src/index.js @@ -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 }; }));