From 72b9e2dd817891f539cf4ab9114b796d8b10696e Mon Sep 17 00:00:00 2001 From: xhh Date: Thu, 25 Feb 2016 10:43:45 +0800 Subject: [PATCH] Update petstore javascript-promise sample and tests --- .../javascript-promise/src/api/PetApi.js | 114 ++++++++---------- .../javascript-promise/src/api/StoreApi.js | 27 ++--- .../javascript-promise/src/api/UserApi.js | 77 +++++------- .../javascript-promise/src/model/Pet.js | 2 +- .../javascript-promise/test/api/PetApiTest.js | 2 +- .../javascript-promise/test/run_tests.html | 1 + 6 files changed, 97 insertions(+), 126 deletions(-) diff --git a/samples/client/petstore/javascript-promise/src/api/PetApi.js b/samples/client/petstore/javascript-promise/src/api/PetApi.js index 26e0e633ad..b9dd09d6d9 100644 --- a/samples/client/petstore/javascript-promise/src/api/PetApi.js +++ b/samples/client/petstore/javascript-promise/src/api/PetApi.js @@ -24,14 +24,13 @@ /** * Update an existing pet * - * @param {Pet} body Pet object that needs to be added to the store - + * @param {Pet} opts['body'] Pet object that needs to be added to the store */ - self.updatePet = function(body) { - var postBody = body; + self.updatePet = function(opts) { + opts = opts || {}; + var postBody = opts['body']; - var pathParams = { }; var queryParams = { @@ -51,20 +50,19 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Add a new pet to the store * - * @param {Pet} body Pet object that needs to be added to the store - + * @param {Pet} opts['body'] Pet object that needs to be added to the store */ - self.addPet = function(body) { - var postBody = body; + self.addPet = function(opts) { + opts = opts || {}; + var postBody = opts['body']; - var pathParams = { }; var queryParams = { @@ -84,25 +82,24 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Finds Pets by status * Multiple status values can be provided with comma seperated strings - * @param {[String]} status Status values that need to be considered for filter - + * @param {[String]} opts['status'] Status values that need to be considered for filter * data is of type: [Pet] */ - self.findPetsByStatus = function(status) { + self.findPetsByStatus = function(opts) { + opts = opts || {}; var postBody = null; - var pathParams = { }; var queryParams = { - 'status': this.apiClient.buildCollectionParam(status, 'multi') + 'status': this.apiClient.buildCollectionParam(opts['status'], 'multi') }; var headerParams = { }; @@ -119,25 +116,24 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Finds Pets by tags * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. - * @param {[String]} tags Tags to filter by - + * @param {[String]} opts['tags'] Tags to filter by * data is of type: [Pet] */ - self.findPetsByTags = function(tags) { + self.findPetsByTags = function(opts) { + opts = opts || {}; var postBody = null; - var pathParams = { }; var queryParams = { - 'tags': this.apiClient.buildCollectionParam(tags, 'multi') + 'tags': this.apiClient.buildCollectionParam(opts['tags'], 'multi') }; var headerParams = { }; @@ -154,14 +150,13 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Find pet by ID * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - * @param {Integer} petId ID of pet that needs to be fetched - + * @param {Integer} petId ID of pet that needs to be fetched * data is of type: Pet */ self.getPetById = function(petId) { @@ -173,7 +168,6 @@ } - var pathParams = { 'petId': petId }; @@ -194,18 +188,18 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Updates a pet in the store with form data * - * @param {String} petId ID of pet that needs to be updated - * @param {String} name Updated name of the pet - * @param {String} status Updated status of the pet - + * @param {String} petId ID of pet that needs to be updated + * @param {String} opts['name'] Updated name of the pet + * @param {String} opts['status'] Updated status of the pet */ - self.updatePetWithForm = function(petId, name, status) { + self.updatePetWithForm = function(petId, opts) { + opts = opts || {}; var postBody = null; // verify the required parameter 'petId' is set @@ -214,7 +208,6 @@ } - var pathParams = { 'petId': petId }; @@ -223,8 +216,8 @@ var headerParams = { }; var formParams = { - 'name': name, - 'status': status + 'name': opts['name'], + 'status': opts['status'] }; var authNames = ['petstore_auth']; @@ -237,17 +230,17 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Deletes a pet * - * @param {Integer} petId Pet id to delete - * @param {String} apiKey - + * @param {Integer} petId Pet id to delete + * @param {String} opts['apiKey'] */ - self.deletePet = function(petId, apiKey) { + self.deletePet = function(petId, opts) { + opts = opts || {}; var postBody = null; // verify the required parameter 'petId' is set @@ -256,14 +249,13 @@ } - var pathParams = { 'petId': petId }; var queryParams = { }; var headerParams = { - 'api_key': apiKey + 'api_key': opts['apiKey'] }; var formParams = { }; @@ -278,18 +270,18 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * uploads an image * - * @param {Integer} petId ID of pet to update - * @param {String} additionalMetadata Additional data to pass to server - * @param {File} file file to upload - + * @param {Integer} petId ID of pet to update + * @param {String} opts['additionalMetadata'] Additional data to pass to server + * @param {File} opts['file'] file to upload */ - self.uploadFile = function(petId, additionalMetadata, file) { + self.uploadFile = function(petId, opts) { + opts = opts || {}; var postBody = null; // verify the required parameter 'petId' is set @@ -298,7 +290,6 @@ } - var pathParams = { 'petId': petId }; @@ -307,8 +298,8 @@ var headerParams = { }; var formParams = { - 'additionalMetadata': additionalMetadata, - 'file': file + 'additionalMetadata': opts['additionalMetadata'], + 'file': opts['file'] }; var authNames = ['petstore_auth']; @@ -321,14 +312,13 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Fake endpoint to test byte array return by 'Find pet by ID' * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions - * @param {Integer} petId ID of pet that needs to be fetched - + * @param {Integer} petId ID of pet that needs to be fetched * data is of type: 'String' */ self.getPetByIdWithByteArray = function(petId) { @@ -340,7 +330,6 @@ } - var pathParams = { 'petId': petId }; @@ -361,20 +350,19 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Fake endpoint to test byte array in body parameter for adding a new pet to the store * - * @param {String} body Pet object in the form of byte array - + * @param {String} opts['body'] Pet object in the form of byte array */ - self.addPetUsingByteArray = function(body) { - var postBody = body; + self.addPetUsingByteArray = function(opts) { + opts = opts || {}; + var postBody = opts['body']; - var pathParams = { }; var queryParams = { @@ -394,7 +382,7 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } diff --git a/samples/client/petstore/javascript-promise/src/api/StoreApi.js b/samples/client/petstore/javascript-promise/src/api/StoreApi.js index 57a3c57d86..d47898d749 100644 --- a/samples/client/petstore/javascript-promise/src/api/StoreApi.js +++ b/samples/client/petstore/javascript-promise/src/api/StoreApi.js @@ -24,14 +24,12 @@ /** * Returns pet inventories by status * Returns a map of status codes to quantities - * data is of type: {'String': 'Integer'} */ self.getInventory = function() { var postBody = null; - var pathParams = { }; var queryParams = { @@ -51,21 +49,20 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Place an order for a pet * - * @param {Order} body order placed for purchasing the pet - + * @param {Order} opts['body'] order placed for purchasing the pet * data is of type: Order */ - self.placeOrder = function(body) { - var postBody = body; + self.placeOrder = function(opts) { + opts = opts || {}; + var postBody = opts['body']; - var pathParams = { }; var queryParams = { @@ -85,14 +82,13 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - * @param {String} orderId ID of pet that needs to be fetched - + * @param {String} orderId ID of pet that needs to be fetched * data is of type: Order */ self.getOrderById = function(orderId) { @@ -104,7 +100,6 @@ } - var pathParams = { 'orderId': orderId }; @@ -125,14 +120,13 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Delete purchase order by ID * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - * @param {String} orderId ID of the order that needs to be deleted - + * @param {String} orderId ID of the order that needs to be deleted */ self.deleteOrder = function(orderId) { var postBody = null; @@ -143,7 +137,6 @@ } - var pathParams = { 'orderId': orderId }; @@ -164,7 +157,7 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } diff --git a/samples/client/petstore/javascript-promise/src/api/UserApi.js b/samples/client/petstore/javascript-promise/src/api/UserApi.js index bb93561ec1..893ab3e68f 100644 --- a/samples/client/petstore/javascript-promise/src/api/UserApi.js +++ b/samples/client/petstore/javascript-promise/src/api/UserApi.js @@ -24,14 +24,13 @@ /** * Create user * This can only be done by the logged in user. - * @param {User} body Created user object - + * @param {User} opts['body'] Created user object */ - self.createUser = function(body) { - var postBody = body; + self.createUser = function(opts) { + opts = opts || {}; + var postBody = opts['body']; - var pathParams = { }; var queryParams = { @@ -51,20 +50,19 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Creates list of users with given input array * - * @param {[User]} body List of user object - + * @param {[User]} opts['body'] List of user object */ - self.createUsersWithArrayInput = function(body) { - var postBody = body; + self.createUsersWithArrayInput = function(opts) { + opts = opts || {}; + var postBody = opts['body']; - var pathParams = { }; var queryParams = { @@ -84,20 +82,19 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Creates list of users with given input array * - * @param {[User]} body List of user object - + * @param {[User]} opts['body'] List of user object */ - self.createUsersWithListInput = function(body) { - var postBody = body; + self.createUsersWithListInput = function(opts) { + opts = opts || {}; + var postBody = opts['body']; - var pathParams = { }; var queryParams = { @@ -117,27 +114,26 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Logs user into the system * - * @param {String} username The user name for login - * @param {String} password The password for login in clear text - + * @param {String} opts['username'] The user name for login + * @param {String} opts['password'] The password for login in clear text * data is of type: 'String' */ - self.loginUser = function(username, password) { + self.loginUser = function(opts) { + opts = opts || {}; var postBody = null; - var pathParams = { }; var queryParams = { - 'username': username, - 'password': password + 'username': opts['username'], + 'password': opts['password'] }; var headerParams = { }; @@ -154,19 +150,17 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Logs out current logged in user session * - */ self.logoutUser = function() { var postBody = null; - var pathParams = { }; var queryParams = { @@ -186,14 +180,13 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Get user by user name * - * @param {String} username The name that needs to be fetched. Use user1 for testing. - + * @param {String} username The name that needs to be fetched. Use user1 for testing. * data is of type: User */ self.getUserByName = function(username) { @@ -205,7 +198,6 @@ } - var pathParams = { 'username': username }; @@ -226,18 +218,18 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Updated user * This can only be done by the logged in user. - * @param {String} username name that need to be deleted - * @param {User} body Updated user object - + * @param {String} username name that need to be deleted + * @param {User} opts['body'] Updated user object */ - self.updateUser = function(username, body) { - var postBody = body; + self.updateUser = function(username, opts) { + opts = opts || {}; + var postBody = opts['body']; // verify the required parameter 'username' is set if (username == null) { @@ -245,7 +237,6 @@ } - var pathParams = { 'username': username }; @@ -266,14 +257,13 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } /** * Delete user * This can only be done by the logged in user. - * @param {String} username The name that needs to be deleted - + * @param {String} username The name that needs to be deleted */ self.deleteUser = function(username) { var postBody = null; @@ -284,7 +274,6 @@ } - var pathParams = { 'username': username }; @@ -305,7 +294,7 @@ pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType ); - + } diff --git a/samples/client/petstore/javascript-promise/src/model/Pet.js b/samples/client/petstore/javascript-promise/src/model/Pet.js index 6b43162941..3b8bdeef12 100644 --- a/samples/client/petstore/javascript-promise/src/model/Pet.js +++ b/samples/client/petstore/javascript-promise/src/model/Pet.js @@ -16,7 +16,7 @@ 'use strict'; - var Pet = function Pet(photoUrls, name) { + var Pet = function Pet(name, photoUrls) { /** * datatype: String diff --git a/samples/client/petstore/javascript-promise/test/api/PetApiTest.js b/samples/client/petstore/javascript-promise/test/api/PetApiTest.js index f57770999b..d444529a92 100644 --- a/samples/client/petstore/javascript-promise/test/api/PetApiTest.js +++ b/samples/client/petstore/javascript-promise/test/api/PetApiTest.js @@ -29,7 +29,7 @@ var createRandomPet = function() { describe('PetApi', function() { it('should create and get pet', function(done) { var pet = createRandomPet(); - api.addPet(pet) + api.addPet({body: pet}) .then(function() { return api.getPetById(pet.id) }) diff --git a/samples/client/petstore/javascript-promise/test/run_tests.html b/samples/client/petstore/javascript-promise/test/run_tests.html index 2916234bcf..2f3e3f1e33 100644 --- a/samples/client/petstore/javascript-promise/test/run_tests.html +++ b/samples/client/petstore/javascript-promise/test/run_tests.html @@ -9,6 +9,7 @@ +