forked from loafle/openapi-generator-original
Add petstore tests for usePromises version
This commit is contained in:
parent
bf71e6b145
commit
7301618671
34
bin/javascript-promise-petstore.sh
Executable file
34
bin/javascript-promise-petstore.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/javascript \
|
||||
-i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l javascript \
|
||||
-o samples/client/petstore/javascript-promise \
|
||||
--additional-properties usePromises=true"
|
||||
|
||||
java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags
|
1
samples/client/petstore/javascript-promise/.gitignore
vendored
Normal file
1
samples/client/petstore/javascript-promise/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/node_modules/
|
17
samples/client/petstore/javascript-promise/package.json
Normal file
17
samples/client/petstore/javascript-promise/package.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "swagger-petstore",
|
||||
"version": "1.0.0",
|
||||
"description": "This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters",
|
||||
"license": "Apache 2.0",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"test": "./node_modules/mocha/bin/mocha --recursive"
|
||||
},
|
||||
"dependencies": {
|
||||
"superagent": "1.7.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "~2.3.4",
|
||||
"expect.js": "~0.3.1"
|
||||
}
|
||||
}
|
45
samples/client/petstore/javascript-promise/pom.xml
Normal file
45
samples/client/petstore/javascript-promise/pom.xml
Normal file
@ -0,0 +1,45 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-petstore-javascript-promise</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>Swagger Petstore - Javascript Client (Promise version)</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>npm-install</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>install</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>mocha</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
291
samples/client/petstore/javascript-promise/src/ApiClient.js
Normal file
291
samples/client/petstore/javascript-promise/src/ApiClient.js
Normal file
@ -0,0 +1,291 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['superagent'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
module.exports = factory(require('superagent'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
if (!root.SwaggerPetstore) {
|
||||
root.SwaggerPetstore = {};
|
||||
}
|
||||
root.SwaggerPetstore.ApiClient = factory(root.superagent);
|
||||
}
|
||||
}(this, function(superagent) {
|
||||
'use strict';
|
||||
|
||||
var ApiClient = function ApiClient() {
|
||||
/**
|
||||
* The base path to put in front of every API call's (relative) path.
|
||||
*/
|
||||
this.basePath = 'http://petstore.swagger.io/v2'.replace(/\/+$/, '');
|
||||
|
||||
/**
|
||||
* The default HTTP headers to be included for all API calls.
|
||||
*/
|
||||
this.defaultHeaders = {};
|
||||
};
|
||||
|
||||
ApiClient.prototype.paramToString = function paramToString(param) {
|
||||
if (param == null) {
|
||||
// return empty string for null and undefined
|
||||
return '';
|
||||
} else if (param instanceof Date) {
|
||||
return param.toJSON();
|
||||
} else {
|
||||
return param.toString();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Build full URL by appending the given path to base path and replacing
|
||||
* path parameter placeholders with parameter values.
|
||||
* NOTE: query parameters are not handled here.
|
||||
*/
|
||||
ApiClient.prototype.buildUrl = function buildUrl(path, pathParams) {
|
||||
if (!path.match(/^\//)) {
|
||||
path = '/' + path;
|
||||
}
|
||||
var url = this.basePath + path;
|
||||
var _this = this;
|
||||
url = url.replace(/\{([\w-]+)\}/g, function(fullMatch, key) {
|
||||
var value;
|
||||
if (pathParams.hasOwnProperty(key)) {
|
||||
value = _this.paramToString(pathParams[key]);
|
||||
} else {
|
||||
value = fullMatch;
|
||||
}
|
||||
return encodeURIComponent(value);
|
||||
});
|
||||
return url;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the given MIME is a JSON MIME.
|
||||
* JSON MIME examples:
|
||||
* application/json
|
||||
* application/json; charset=UTF8
|
||||
* APPLICATION/JSON
|
||||
*/
|
||||
ApiClient.prototype.isJsonMime = function isJsonMime(mime) {
|
||||
return Boolean(mime != null && mime.match(/^application\/json(;.*)?$/i));
|
||||
};
|
||||
|
||||
/**
|
||||
* Choose a MIME from the given MIMEs with JSON preferred,
|
||||
* i.e. return JSON if included, otherwise return the first one.
|
||||
*/
|
||||
ApiClient.prototype.jsonPreferredMime = function jsonPreferredMime(mimes) {
|
||||
var len = mimes.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
if (this.isJsonMime(mimes[i])) {
|
||||
return mimes[i];
|
||||
}
|
||||
}
|
||||
return mimes[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the given parameter value is like file content.
|
||||
*/
|
||||
ApiClient.prototype.isFileParam = function isFileParam(param) {
|
||||
// fs.ReadStream in Node.js (but not in runtime like browserify)
|
||||
if (typeof window === 'undefined' &&
|
||||
typeof require === 'function' &&
|
||||
require('fs') &&
|
||||
param instanceof require('fs').ReadStream) {
|
||||
return true;
|
||||
}
|
||||
// Buffer in Node.js
|
||||
if (typeof Buffer === 'function' && param instanceof Buffer) {
|
||||
return true;
|
||||
}
|
||||
// Blob in browser
|
||||
if (typeof Blob === 'function' && param instanceof Blob) {
|
||||
return true;
|
||||
}
|
||||
// File in browser (it seems File object is also instance of Blob, but keep this for safe)
|
||||
if (typeof File === 'function' && param instanceof File) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize parameters values:
|
||||
* remove nils,
|
||||
* keep files and arrays,
|
||||
* format to string with `paramToString` for other cases.
|
||||
*/
|
||||
ApiClient.prototype.normalizeParams = function normalizeParams(params) {
|
||||
var newParams = {};
|
||||
for (var key in params) {
|
||||
if (params.hasOwnProperty(key) && params[key] != null) {
|
||||
var value = params[key];
|
||||
if (this.isFileParam(value) || Array.isArray(value)) {
|
||||
newParams[key] = value;
|
||||
} else {
|
||||
newParams[key] = this.paramToString(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return newParams;
|
||||
};
|
||||
|
||||
/**
|
||||
* Build parameter value according to the given collection format.
|
||||
* @param {String} collectionFormat one of 'csv', 'ssv', 'tsv', 'pipes' and 'multi'
|
||||
*/
|
||||
ApiClient.prototype.buildCollectionParam = function buildCollectionParam(param, collectionFormat) {
|
||||
if (param == null) {
|
||||
return null;
|
||||
}
|
||||
switch (collectionFormat) {
|
||||
case 'csv':
|
||||
return param.map(this.paramToString).join(',');
|
||||
case 'ssv':
|
||||
return param.map(this.paramToString).join(' ');
|
||||
case 'tsv':
|
||||
return param.map(this.paramToString).join('\t');
|
||||
case 'pipes':
|
||||
return param.map(this.paramToString).join('|');
|
||||
case 'multi':
|
||||
// return the array directly as Superagent will handle it as expected
|
||||
return param.map(this.paramToString);
|
||||
default:
|
||||
throw new Error('Unknown collection format: ' + collectionFormat);
|
||||
}
|
||||
};
|
||||
|
||||
ApiClient.prototype.deserialize = function deserialize(response, returnType) {
|
||||
if (response == null || returnType == null) {
|
||||
return null;
|
||||
}
|
||||
// Rely on Superagent for parsing response body.
|
||||
// See http://visionmedia.github.io/superagent/#parsing-response-bodies
|
||||
var data = response.body;
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
return ApiClient.convertToType(data, returnType);
|
||||
};
|
||||
|
||||
ApiClient.prototype.callApi = function callApi(path, httpMethod, pathParams,
|
||||
queryParams, headerParams, formParams, bodyParam, contentTypes, accepts,
|
||||
returnType, callback) {
|
||||
var _this = this;
|
||||
var url = this.buildUrl(path, pathParams);
|
||||
var request = superagent(httpMethod, url);
|
||||
|
||||
// set query parameters
|
||||
request.query(this.normalizeParams(queryParams));
|
||||
|
||||
// set header parameters
|
||||
request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));
|
||||
|
||||
var contentType = this.jsonPreferredMime(contentTypes);
|
||||
if (contentType) {
|
||||
request.type(contentType);
|
||||
} else if (!request.header['Content-Type']) {
|
||||
request.type('application/json');
|
||||
}
|
||||
|
||||
if (contentType === 'application/x-www-form-urlencoded') {
|
||||
request.send(this.normalizeParams(formParams));
|
||||
} else if (contentType == 'multipart/form-data') {
|
||||
var _formParams = this.normalizeParams(formParams);
|
||||
for (var key in _formParams) {
|
||||
if (_formParams.hasOwnProperty(key)) {
|
||||
if (this.isFileParam(_formParams[key])) {
|
||||
// file field
|
||||
request.attach(key, _formParams[key]);
|
||||
} else {
|
||||
request.field(key, _formParams[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (bodyParam) {
|
||||
request.send(bodyParam);
|
||||
}
|
||||
|
||||
var accept = this.jsonPreferredMime(accepts);
|
||||
if (accept) {
|
||||
request.accept(accept);
|
||||
}
|
||||
|
||||
|
||||
return new Promise( function(resolve,reject) {
|
||||
request.end(function(error, response) {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
else {
|
||||
var data = _this.deserialize(response, returnType);
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
ApiClient.parseDate = function parseDate(str) {
|
||||
str = str.replace(/T/i, ' ');
|
||||
return new Date(str);
|
||||
};
|
||||
|
||||
ApiClient.convertToType = function convertToType(data, type) {
|
||||
switch (type) {
|
||||
case 'Boolean':
|
||||
return Boolean(data);
|
||||
case 'Integer':
|
||||
return parseInt(data, 10);
|
||||
case 'Number':
|
||||
return parseFloat(data);
|
||||
case 'String':
|
||||
return String(data);
|
||||
case 'Date':
|
||||
return this.parseDate(String(data));
|
||||
default:
|
||||
if (typeof type === 'function') {
|
||||
// for model type like: User
|
||||
var model = new type();
|
||||
model.constructFromObject(data);
|
||||
return model;
|
||||
} else if (Array.isArray(type)) {
|
||||
// for array type like: ['String']
|
||||
var itemType = type[0];
|
||||
return data.map(function(item) {
|
||||
return ApiClient.convertToType(item, itemType);
|
||||
});
|
||||
} else if (typeof type === 'object') {
|
||||
// for plain object type like: {'String': 'Integer'}
|
||||
var keyType, valueType;
|
||||
for (var k in type) {
|
||||
if (type.hasOwnProperty(k)) {
|
||||
keyType = k;
|
||||
valueType = type[k];
|
||||
break;
|
||||
}
|
||||
}
|
||||
var result = {};
|
||||
for (var k in data) {
|
||||
if (data.hasOwnProperty(k)) {
|
||||
var key = ApiClient.convertToType(k, keyType);
|
||||
var value = ApiClient.convertToType(data[k], valueType);
|
||||
result[key] = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
// for unknown type, return the data directly
|
||||
return data;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ApiClient.default = new ApiClient();
|
||||
|
||||
return ApiClient;
|
||||
}));
|
394
samples/client/petstore/javascript-promise/src/api/PetApi.js
Normal file
394
samples/client/petstore/javascript-promise/src/api/PetApi.js
Normal file
@ -0,0 +1,394 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['../ApiClient', '../model/Pet'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
module.exports = factory(require('../ApiClient'), require('../model/Pet'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
if (!root.SwaggerPetstore) {
|
||||
root.SwaggerPetstore = {};
|
||||
}
|
||||
root.SwaggerPetstore.PetApi = factory(root.SwaggerPetstore.ApiClient, root.SwaggerPetstore.Pet);
|
||||
}
|
||||
}(this, function(ApiClient, Pet) {
|
||||
'use strict';
|
||||
|
||||
var PetApi = function PetApi(apiClient) {
|
||||
this.apiClient = apiClient || ApiClient.default;
|
||||
|
||||
var self = this;
|
||||
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*
|
||||
* @param {Pet} body Pet object that needs to be added to the store
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.updatePet = function(body, callback) {
|
||||
var postBody = body;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = ['application/json', 'application/xml'];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/pet', 'PUT',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*
|
||||
* @param {Pet} body Pet object that needs to be added to the store
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.addPet = function(body, callback) {
|
||||
var postBody = body;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = ['application/json', 'application/xml'];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/pet', 'POST',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {function} callback the callback function, accepting three arguments: error, data, response
|
||||
* data is of type: [Pet]
|
||||
*/
|
||||
self.findPetsByStatus = function(status, callback) {
|
||||
var postBody = null;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
'status': this.buildCollectionParam(status, 'multi')
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = [Pet];
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/pet/findByStatus', 'GET',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {function} callback the callback function, accepting three arguments: error, data, response
|
||||
* data is of type: [Pet]
|
||||
*/
|
||||
self.findPetsByTags = function(tags, callback) {
|
||||
var postBody = null;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
'tags': this.buildCollectionParam(tags, 'multi')
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = [Pet];
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/pet/findByTags', 'GET',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {function} callback the callback function, accepting three arguments: error, data, response
|
||||
* data is of type: Pet
|
||||
*/
|
||||
self.getPetById = function(petId, callback) {
|
||||
var postBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
if (petId == null) {
|
||||
throw "Missing the required parameter 'petId' when calling getPetById";
|
||||
}
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
'petId': petId
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = Pet;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/pet/{petId}', 'GET',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.updatePetWithForm = function(petId, name, status, callback) {
|
||||
var postBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
if (petId == null) {
|
||||
throw "Missing the required parameter 'petId' when calling updatePetWithForm";
|
||||
}
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
'petId': petId
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
'name': name,
|
||||
'status': status
|
||||
};
|
||||
|
||||
var contentTypes = ['application/x-www-form-urlencoded'];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/pet/{petId}', 'POST',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param {Integer} petId Pet id to delete
|
||||
* @param {String} apiKey
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.deletePet = function(petId, apiKey, callback) {
|
||||
var postBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
if (petId == null) {
|
||||
throw "Missing the required parameter 'petId' when calling deletePet";
|
||||
}
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
'petId': petId
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
'api_key': apiKey
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/pet/{petId}', 'DELETE',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.uploadFile = function(petId, additionalMetadata, file, callback) {
|
||||
var postBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
if (petId == null) {
|
||||
throw "Missing the required parameter 'petId' when calling uploadFile";
|
||||
}
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
'petId': petId
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
'additionalMetadata': additionalMetadata,
|
||||
'file': file
|
||||
};
|
||||
|
||||
var contentTypes = ['multipart/form-data'];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/pet/{petId}/uploadImage', 'POST',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {function} callback the callback function, accepting three arguments: error, data, response
|
||||
* data is of type: 'String'
|
||||
*/
|
||||
self.getPetByIdWithByteArray = function(petId, callback) {
|
||||
var postBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
if (petId == null) {
|
||||
throw "Missing the required parameter 'petId' when calling getPetByIdWithByteArray";
|
||||
}
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
'petId': petId
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = 'String';
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/pet/{petId}?testing_byte_array=true', 'GET',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.addPetUsingByteArray = function(body, callback) {
|
||||
var postBody = body;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = ['application/json', 'application/xml'];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/pet?testing_byte_array=true', 'POST',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
return PetApi;
|
||||
}));
|
170
samples/client/petstore/javascript-promise/src/api/StoreApi.js
Normal file
170
samples/client/petstore/javascript-promise/src/api/StoreApi.js
Normal file
@ -0,0 +1,170 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['../ApiClient', '../model/Order'], 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'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
if (!root.SwaggerPetstore) {
|
||||
root.SwaggerPetstore = {};
|
||||
}
|
||||
root.SwaggerPetstore.StoreApi = factory(root.SwaggerPetstore.ApiClient, root.SwaggerPetstore.Order);
|
||||
}
|
||||
}(this, function(ApiClient, Order) {
|
||||
'use strict';
|
||||
|
||||
var StoreApi = function StoreApi(apiClient) {
|
||||
this.apiClient = apiClient || ApiClient.default;
|
||||
|
||||
var self = this;
|
||||
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
* data is of type: {'String': 'Integer'}
|
||||
*/
|
||||
self.getInventory = function(callback) {
|
||||
var postBody = null;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = {'String': 'Integer'};
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/store/inventory', 'GET',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param {Order} body order placed for purchasing the pet
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
* data is of type: Order
|
||||
*/
|
||||
self.placeOrder = function(body, callback) {
|
||||
var postBody = body;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = Order;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/store/order', 'POST',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {function} callback the callback function, accepting three arguments: error, data, response
|
||||
* data is of type: Order
|
||||
*/
|
||||
self.getOrderById = function(orderId, callback) {
|
||||
var postBody = null;
|
||||
|
||||
// verify the required parameter 'orderId' is set
|
||||
if (orderId == null) {
|
||||
throw "Missing the required parameter 'orderId' when calling getOrderById";
|
||||
}
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
'orderId': orderId
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = Order;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/store/order/{orderId}', 'GET',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.deleteOrder = function(orderId, callback) {
|
||||
var postBody = null;
|
||||
|
||||
// verify the required parameter 'orderId' is set
|
||||
if (orderId == null) {
|
||||
throw "Missing the required parameter 'orderId' when calling deleteOrder";
|
||||
}
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
'orderId': orderId
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/store/order/{orderId}', 'DELETE',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
return StoreApi;
|
||||
}));
|
307
samples/client/petstore/javascript-promise/src/api/UserApi.js
Normal file
307
samples/client/petstore/javascript-promise/src/api/UserApi.js
Normal file
@ -0,0 +1,307 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['../ApiClient', '../model/User'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
module.exports = factory(require('../ApiClient'), require('../model/User'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
if (!root.SwaggerPetstore) {
|
||||
root.SwaggerPetstore = {};
|
||||
}
|
||||
root.SwaggerPetstore.UserApi = factory(root.SwaggerPetstore.ApiClient, root.SwaggerPetstore.User);
|
||||
}
|
||||
}(this, function(ApiClient, User) {
|
||||
'use strict';
|
||||
|
||||
var UserApi = function UserApi(apiClient) {
|
||||
this.apiClient = apiClient || ApiClient.default;
|
||||
|
||||
var self = this;
|
||||
|
||||
|
||||
/**
|
||||
* Create user
|
||||
* This can only be done by the logged in user.
|
||||
* @param {User} body Created user object
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.createUser = function(body, callback) {
|
||||
var postBody = body;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/user', 'POST',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param {[User]} body List of user object
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.createUsersWithArrayInput = function(body, callback) {
|
||||
var postBody = body;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/user/createWithArray', 'POST',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param {[User]} body List of user object
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.createUsersWithListInput = function(body, callback) {
|
||||
var postBody = body;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/user/createWithList', 'POST',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*
|
||||
* @param {String} username The user name for login
|
||||
* @param {String} password The password for login in clear text
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
* data is of type: 'String'
|
||||
*/
|
||||
self.loginUser = function(username, password, callback) {
|
||||
var postBody = null;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
'username': username,
|
||||
'password': password
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = 'String';
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/user/login', 'GET',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.logoutUser = function(callback) {
|
||||
var postBody = null;
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/user/logout', 'GET',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*
|
||||
* @param {String} username The name that needs to be fetched. Use user1 for testing.
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
* data is of type: User
|
||||
*/
|
||||
self.getUserByName = function(username, callback) {
|
||||
var postBody = null;
|
||||
|
||||
// verify the required parameter 'username' is set
|
||||
if (username == null) {
|
||||
throw "Missing the required parameter 'username' when calling getUserByName";
|
||||
}
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
'username': username
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = User;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/user/{username}', 'GET',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.updateUser = function(username, body, callback) {
|
||||
var postBody = body;
|
||||
|
||||
// verify the required parameter 'username' is set
|
||||
if (username == null) {
|
||||
throw "Missing the required parameter 'username' when calling updateUser";
|
||||
}
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
'username': username
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/user/{username}', 'PUT',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user
|
||||
* This can only be done by the logged in user.
|
||||
* @param {String} username The name that needs to be deleted
|
||||
* @param {function} callback the callback function, accepting three arguments: error, data, response
|
||||
*/
|
||||
self.deleteUser = function(username, callback) {
|
||||
var postBody = null;
|
||||
|
||||
// verify the required parameter 'username' is set
|
||||
if (username == null) {
|
||||
throw "Missing the required parameter 'username' when calling deleteUser";
|
||||
}
|
||||
|
||||
|
||||
|
||||
var pathParams = {
|
||||
'username': username
|
||||
};
|
||||
var queryParams = {
|
||||
};
|
||||
var headerParams = {
|
||||
};
|
||||
var formParams = {
|
||||
};
|
||||
|
||||
var contentTypes = [];
|
||||
var accepts = ['application/json', 'application/xml'];
|
||||
var returnType = null;
|
||||
|
||||
return this.apiClient.callApi(
|
||||
'/user/{username}', 'DELETE',
|
||||
pathParams, queryParams, headerParams, formParams, postBody,
|
||||
contentTypes, accepts, returnType, callback
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
return UserApi;
|
||||
}));
|
23
samples/client/petstore/javascript-promise/src/index.js
Normal file
23
samples/client/petstore/javascript-promise/src/index.js
Normal file
@ -0,0 +1,23 @@
|
||||
(function(factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['./ApiClient', './model/User', './model/Category', './model/Pet', './model/Tag', './model/Order', './api/UserApi', './api/StoreApi', './api/PetApi'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
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/StoreApi'), require('./api/PetApi'));
|
||||
}
|
||||
}(function(ApiClient, User, Category, Pet, Tag, Order, UserApi, StoreApi, PetApi) {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
ApiClient: ApiClient,
|
||||
User: User,
|
||||
Category: Category,
|
||||
Pet: Pet,
|
||||
Tag: Tag,
|
||||
Order: Order,
|
||||
UserApi: UserApi,
|
||||
StoreApi: StoreApi,
|
||||
PetApi: PetApi
|
||||
};
|
||||
}));
|
@ -0,0 +1,89 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([undefined, '../ApiClient'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
module.exports = factory(undefined, require('../ApiClient'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
if (!root.SwaggerPetstore) {
|
||||
root.SwaggerPetstore = {};
|
||||
}
|
||||
factory(root.SwaggerPetstore, root.SwaggerPetstore.ApiClient);
|
||||
}
|
||||
}(this, function(module, ApiClient) {
|
||||
'use strict';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var Category = function Category() {
|
||||
|
||||
/**
|
||||
* datatype: Integer
|
||||
**/
|
||||
this['id'] = null;
|
||||
|
||||
/**
|
||||
* datatype: String
|
||||
**/
|
||||
this['name'] = null;
|
||||
|
||||
};
|
||||
|
||||
Category.prototype.constructFromObject = function(data) {
|
||||
if (!data) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this['id'] = ApiClient.convertToType(data['id'], 'Integer');
|
||||
|
||||
this['name'] = ApiClient.convertToType(data['name'], 'String');
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {Integer}
|
||||
**/
|
||||
Category.prototype.getId = function() {
|
||||
return this['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Integer} id
|
||||
**/
|
||||
Category.prototype.setId = function(id) {
|
||||
this['id'] = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
**/
|
||||
Category.prototype.getName = function() {
|
||||
return this['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} name
|
||||
**/
|
||||
Category.prototype.setName = function(name) {
|
||||
this['name'] = name;
|
||||
}
|
||||
|
||||
|
||||
Category.prototype.toJson = function() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
|
||||
if (module) {
|
||||
module.Category = Category;
|
||||
}
|
||||
|
||||
return Category;
|
||||
|
||||
|
||||
}));
|
204
samples/client/petstore/javascript-promise/src/model/Order.js
Normal file
204
samples/client/petstore/javascript-promise/src/model/Order.js
Normal file
@ -0,0 +1,204 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([undefined, '../ApiClient'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
module.exports = factory(undefined, require('../ApiClient'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
if (!root.SwaggerPetstore) {
|
||||
root.SwaggerPetstore = {};
|
||||
}
|
||||
factory(root.SwaggerPetstore, root.SwaggerPetstore.ApiClient);
|
||||
}
|
||||
}(this, function(module, ApiClient) {
|
||||
'use strict';
|
||||
|
||||
|
||||
|
||||
//export module
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
define('StatusEnum', [], function() {
|
||||
return StatusEnum;
|
||||
});
|
||||
}
|
||||
|
||||
var StatusEnum = function StatusEnum() {
|
||||
var self = this;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
self.PLACED = "placed",
|
||||
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
self.APPROVED = "approved",
|
||||
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
self.DELIVERED = "delivered";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
var Order = function Order() {
|
||||
|
||||
/**
|
||||
* datatype: Integer
|
||||
**/
|
||||
this['id'] = null;
|
||||
|
||||
/**
|
||||
* datatype: Integer
|
||||
**/
|
||||
this['petId'] = null;
|
||||
|
||||
/**
|
||||
* datatype: Integer
|
||||
**/
|
||||
this['quantity'] = null;
|
||||
|
||||
/**
|
||||
* datatype: Date
|
||||
**/
|
||||
this['shipDate'] = null;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
* datatype: StatusEnum
|
||||
**/
|
||||
this['status'] = null;
|
||||
|
||||
/**
|
||||
* datatype: Boolean
|
||||
**/
|
||||
this['complete'] = null;
|
||||
|
||||
};
|
||||
|
||||
Order.prototype.constructFromObject = function(data) {
|
||||
if (!data) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this['id'] = ApiClient.convertToType(data['id'], 'Integer');
|
||||
|
||||
this['petId'] = ApiClient.convertToType(data['petId'], 'Integer');
|
||||
|
||||
this['quantity'] = ApiClient.convertToType(data['quantity'], 'Integer');
|
||||
|
||||
this['shipDate'] = ApiClient.convertToType(data['shipDate'], 'Date');
|
||||
|
||||
this['status'] = ApiClient.convertToType(data['status'], 'String');
|
||||
|
||||
this['complete'] = ApiClient.convertToType(data['complete'], 'Boolean');
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {Integer}
|
||||
**/
|
||||
Order.prototype.getId = function() {
|
||||
return this['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Integer} id
|
||||
**/
|
||||
Order.prototype.setId = function(id) {
|
||||
this['id'] = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Integer}
|
||||
**/
|
||||
Order.prototype.getPetId = function() {
|
||||
return this['petId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Integer} petId
|
||||
**/
|
||||
Order.prototype.setPetId = function(petId) {
|
||||
this['petId'] = petId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Integer}
|
||||
**/
|
||||
Order.prototype.getQuantity = function() {
|
||||
return this['quantity'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Integer} quantity
|
||||
**/
|
||||
Order.prototype.setQuantity = function(quantity) {
|
||||
this['quantity'] = quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Date}
|
||||
**/
|
||||
Order.prototype.getShipDate = function() {
|
||||
return this['shipDate'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Date} shipDate
|
||||
**/
|
||||
Order.prototype.setShipDate = function(shipDate) {
|
||||
this['shipDate'] = shipDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Order Status
|
||||
* @return {StatusEnum}
|
||||
**/
|
||||
Order.prototype.getStatus = function() {
|
||||
return this['status'];
|
||||
}
|
||||
|
||||
/**
|
||||
* set Order Status
|
||||
* @param {StatusEnum} status
|
||||
**/
|
||||
Order.prototype.setStatus = function(status) {
|
||||
this['status'] = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Boolean}
|
||||
**/
|
||||
Order.prototype.getComplete = function() {
|
||||
return this['complete'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Boolean} complete
|
||||
**/
|
||||
Order.prototype.setComplete = function(complete) {
|
||||
this['complete'] = complete;
|
||||
}
|
||||
|
||||
|
||||
Order.prototype.toJson = function() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
|
||||
if (module) {
|
||||
module.Order = Order;
|
||||
}
|
||||
|
||||
return Order;
|
||||
|
||||
|
||||
}));
|
206
samples/client/petstore/javascript-promise/src/model/Pet.js
Normal file
206
samples/client/petstore/javascript-promise/src/model/Pet.js
Normal file
@ -0,0 +1,206 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([undefined, '../ApiClient', './Category', './Tag'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
module.exports = factory(undefined, require('../ApiClient'), require('./Category'), require('./Tag'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
if (!root.SwaggerPetstore) {
|
||||
root.SwaggerPetstore = {};
|
||||
}
|
||||
factory(root.SwaggerPetstore, root.SwaggerPetstore.ApiClient, root.SwaggerPetstore.Category, root.SwaggerPetstore.Tag);
|
||||
}
|
||||
}(this, function(module, ApiClient, Category, Tag) {
|
||||
'use strict';
|
||||
|
||||
|
||||
|
||||
//export module
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
define('StatusEnum', [], function() {
|
||||
return StatusEnum;
|
||||
});
|
||||
}
|
||||
|
||||
var StatusEnum = function StatusEnum() {
|
||||
var self = this;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
self.AVAILABLE = "available",
|
||||
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
self.PENDING = "pending",
|
||||
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
self.SOLD = "sold";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
var Pet = function Pet(photoUrls, name) {
|
||||
|
||||
/**
|
||||
* datatype: Integer
|
||||
**/
|
||||
this['id'] = null;
|
||||
|
||||
/**
|
||||
* datatype: Category
|
||||
**/
|
||||
this['category'] = new Category();
|
||||
|
||||
/**
|
||||
* datatype: String
|
||||
* required
|
||||
**/
|
||||
this['name'] = name;
|
||||
|
||||
/**
|
||||
* datatype: [String]
|
||||
* required
|
||||
**/
|
||||
this['photoUrls'] = photoUrls;
|
||||
|
||||
/**
|
||||
* datatype: [Tag]
|
||||
**/
|
||||
this['tags'] = [];
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
* datatype: StatusEnum
|
||||
**/
|
||||
this['status'] = null;
|
||||
|
||||
};
|
||||
|
||||
Pet.prototype.constructFromObject = function(data) {
|
||||
if (!data) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this['id'] = ApiClient.convertToType(data['id'], 'Integer');
|
||||
|
||||
this['category'].constructFromObject(data['category']);
|
||||
|
||||
this['name'] = ApiClient.convertToType(data['name'], 'String');
|
||||
|
||||
this['photoUrls'] = ApiClient.convertToType(data['photoUrls'], ['String']);
|
||||
|
||||
this['tags'] = ApiClient.convertToType(data['tags'], [Tag]);
|
||||
|
||||
this['status'] = ApiClient.convertToType(data['status'], 'String');
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {Integer}
|
||||
**/
|
||||
Pet.prototype.getId = function() {
|
||||
return this['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Integer} id
|
||||
**/
|
||||
Pet.prototype.setId = function(id) {
|
||||
this['id'] = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Category}
|
||||
**/
|
||||
Pet.prototype.getCategory = function() {
|
||||
return this['category'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Category} category
|
||||
**/
|
||||
Pet.prototype.setCategory = function(category) {
|
||||
this['category'] = category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
**/
|
||||
Pet.prototype.getName = function() {
|
||||
return this['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} name
|
||||
**/
|
||||
Pet.prototype.setName = function(name) {
|
||||
this['name'] = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {[String]}
|
||||
**/
|
||||
Pet.prototype.getPhotoUrls = function() {
|
||||
return this['photoUrls'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {[String]} photoUrls
|
||||
**/
|
||||
Pet.prototype.setPhotoUrls = function(photoUrls) {
|
||||
this['photoUrls'] = photoUrls;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {[Tag]}
|
||||
**/
|
||||
Pet.prototype.getTags = function() {
|
||||
return this['tags'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {[Tag]} tags
|
||||
**/
|
||||
Pet.prototype.setTags = function(tags) {
|
||||
this['tags'] = tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* get pet status in the store
|
||||
* @return {StatusEnum}
|
||||
**/
|
||||
Pet.prototype.getStatus = function() {
|
||||
return this['status'];
|
||||
}
|
||||
|
||||
/**
|
||||
* set pet status in the store
|
||||
* @param {StatusEnum} status
|
||||
**/
|
||||
Pet.prototype.setStatus = function(status) {
|
||||
this['status'] = status;
|
||||
}
|
||||
|
||||
|
||||
Pet.prototype.toJson = function() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
|
||||
if (module) {
|
||||
module.Pet = Pet;
|
||||
}
|
||||
|
||||
return Pet;
|
||||
|
||||
|
||||
}));
|
89
samples/client/petstore/javascript-promise/src/model/Tag.js
Normal file
89
samples/client/petstore/javascript-promise/src/model/Tag.js
Normal file
@ -0,0 +1,89 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([undefined, '../ApiClient'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
module.exports = factory(undefined, require('../ApiClient'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
if (!root.SwaggerPetstore) {
|
||||
root.SwaggerPetstore = {};
|
||||
}
|
||||
factory(root.SwaggerPetstore, root.SwaggerPetstore.ApiClient);
|
||||
}
|
||||
}(this, function(module, ApiClient) {
|
||||
'use strict';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var Tag = function Tag() {
|
||||
|
||||
/**
|
||||
* datatype: Integer
|
||||
**/
|
||||
this['id'] = null;
|
||||
|
||||
/**
|
||||
* datatype: String
|
||||
**/
|
||||
this['name'] = null;
|
||||
|
||||
};
|
||||
|
||||
Tag.prototype.constructFromObject = function(data) {
|
||||
if (!data) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this['id'] = ApiClient.convertToType(data['id'], 'Integer');
|
||||
|
||||
this['name'] = ApiClient.convertToType(data['name'], 'String');
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {Integer}
|
||||
**/
|
||||
Tag.prototype.getId = function() {
|
||||
return this['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Integer} id
|
||||
**/
|
||||
Tag.prototype.setId = function(id) {
|
||||
this['id'] = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
**/
|
||||
Tag.prototype.getName = function() {
|
||||
return this['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} name
|
||||
**/
|
||||
Tag.prototype.setName = function(name) {
|
||||
this['name'] = name;
|
||||
}
|
||||
|
||||
|
||||
Tag.prototype.toJson = function() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
|
||||
if (module) {
|
||||
module.Tag = Tag;
|
||||
}
|
||||
|
||||
return Tag;
|
||||
|
||||
|
||||
}));
|
218
samples/client/petstore/javascript-promise/src/model/User.js
Normal file
218
samples/client/petstore/javascript-promise/src/model/User.js
Normal file
@ -0,0 +1,218 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([undefined, '../ApiClient'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
module.exports = factory(undefined, require('../ApiClient'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
if (!root.SwaggerPetstore) {
|
||||
root.SwaggerPetstore = {};
|
||||
}
|
||||
factory(root.SwaggerPetstore, root.SwaggerPetstore.ApiClient);
|
||||
}
|
||||
}(this, function(module, ApiClient) {
|
||||
'use strict';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var User = function User() {
|
||||
|
||||
/**
|
||||
* datatype: Integer
|
||||
**/
|
||||
this['id'] = null;
|
||||
|
||||
/**
|
||||
* datatype: String
|
||||
**/
|
||||
this['username'] = null;
|
||||
|
||||
/**
|
||||
* datatype: String
|
||||
**/
|
||||
this['firstName'] = null;
|
||||
|
||||
/**
|
||||
* datatype: String
|
||||
**/
|
||||
this['lastName'] = null;
|
||||
|
||||
/**
|
||||
* datatype: String
|
||||
**/
|
||||
this['email'] = null;
|
||||
|
||||
/**
|
||||
* datatype: String
|
||||
**/
|
||||
this['password'] = null;
|
||||
|
||||
/**
|
||||
* datatype: String
|
||||
**/
|
||||
this['phone'] = null;
|
||||
|
||||
/**
|
||||
* User Status
|
||||
* datatype: Integer
|
||||
**/
|
||||
this['userStatus'] = null;
|
||||
|
||||
};
|
||||
|
||||
User.prototype.constructFromObject = function(data) {
|
||||
if (!data) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this['id'] = ApiClient.convertToType(data['id'], 'Integer');
|
||||
|
||||
this['username'] = ApiClient.convertToType(data['username'], 'String');
|
||||
|
||||
this['firstName'] = ApiClient.convertToType(data['firstName'], 'String');
|
||||
|
||||
this['lastName'] = ApiClient.convertToType(data['lastName'], 'String');
|
||||
|
||||
this['email'] = ApiClient.convertToType(data['email'], 'String');
|
||||
|
||||
this['password'] = ApiClient.convertToType(data['password'], 'String');
|
||||
|
||||
this['phone'] = ApiClient.convertToType(data['phone'], 'String');
|
||||
|
||||
this['userStatus'] = ApiClient.convertToType(data['userStatus'], 'Integer');
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {Integer}
|
||||
**/
|
||||
User.prototype.getId = function() {
|
||||
return this['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Integer} id
|
||||
**/
|
||||
User.prototype.setId = function(id) {
|
||||
this['id'] = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
**/
|
||||
User.prototype.getUsername = function() {
|
||||
return this['username'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} username
|
||||
**/
|
||||
User.prototype.setUsername = function(username) {
|
||||
this['username'] = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
**/
|
||||
User.prototype.getFirstName = function() {
|
||||
return this['firstName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} firstName
|
||||
**/
|
||||
User.prototype.setFirstName = function(firstName) {
|
||||
this['firstName'] = firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
**/
|
||||
User.prototype.getLastName = function() {
|
||||
return this['lastName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} lastName
|
||||
**/
|
||||
User.prototype.setLastName = function(lastName) {
|
||||
this['lastName'] = lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
**/
|
||||
User.prototype.getEmail = function() {
|
||||
return this['email'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} email
|
||||
**/
|
||||
User.prototype.setEmail = function(email) {
|
||||
this['email'] = email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
**/
|
||||
User.prototype.getPassword = function() {
|
||||
return this['password'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} password
|
||||
**/
|
||||
User.prototype.setPassword = function(password) {
|
||||
this['password'] = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {String}
|
||||
**/
|
||||
User.prototype.getPhone = function() {
|
||||
return this['phone'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} phone
|
||||
**/
|
||||
User.prototype.setPhone = function(phone) {
|
||||
this['phone'] = phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* get User Status
|
||||
* @return {Integer}
|
||||
**/
|
||||
User.prototype.getUserStatus = function() {
|
||||
return this['userStatus'];
|
||||
}
|
||||
|
||||
/**
|
||||
* set User Status
|
||||
* @param {Integer} userStatus
|
||||
**/
|
||||
User.prototype.setUserStatus = function(userStatus) {
|
||||
this['userStatus'] = userStatus;
|
||||
}
|
||||
|
||||
|
||||
User.prototype.toJson = function() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
|
||||
if (module) {
|
||||
module.User = User;
|
||||
}
|
||||
|
||||
return User;
|
||||
|
||||
|
||||
}));
|
155
samples/client/petstore/javascript-promise/test/ApiClientTest.js
Normal file
155
samples/client/petstore/javascript-promise/test/ApiClientTest.js
Normal file
@ -0,0 +1,155 @@
|
||||
if (typeof module === 'object' && module.exports) {
|
||||
var expect = require('expect.js');
|
||||
var SwaggerPetstore = require('../src/index');
|
||||
}
|
||||
|
||||
var apiClient = SwaggerPetstore.ApiClient.default;
|
||||
|
||||
describe('ApiClient', function() {
|
||||
describe('defaults', function() {
|
||||
it('should have correct default values with the default API client', function() {
|
||||
expect(apiClient).to.be.ok();
|
||||
expect(apiClient.basePath).to.be('http://petstore.swagger.io/v2');
|
||||
});
|
||||
|
||||
it('should have correct default values with new API client and can customize it', function() {
|
||||
var newClient = new SwaggerPetstore.ApiClient;
|
||||
expect(newClient.basePath).to.be('http://petstore.swagger.io/v2');
|
||||
expect(newClient.buildUrl('/abc', {})).to.be('http://petstore.swagger.io/v2/abc');
|
||||
|
||||
newClient.basePath = 'http://example.com';
|
||||
expect(newClient.basePath).to.be('http://example.com');
|
||||
expect(newClient.buildUrl('/abc', {})).to.be('http://example.com/abc');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#paramToString', function() {
|
||||
it('should return empty string for null and undefined', function() {
|
||||
expect(apiClient.paramToString(null)).to.be('');
|
||||
expect(apiClient.paramToString(undefined)).to.be('');
|
||||
});
|
||||
|
||||
it('should return string', function() {
|
||||
expect(apiClient.paramToString('')).to.be('');
|
||||
expect(apiClient.paramToString('abc')).to.be('abc');
|
||||
expect(apiClient.paramToString(123)).to.be('123');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#buildCollectionParam', function() {
|
||||
var param;
|
||||
|
||||
beforeEach(function() {
|
||||
param = ['aa', 'bb', 123];
|
||||
});
|
||||
|
||||
it('works for csv', function() {
|
||||
expect(apiClient.buildCollectionParam(param, 'csv')).to.be('aa,bb,123');
|
||||
});
|
||||
|
||||
it('works for ssv', function() {
|
||||
expect(apiClient.buildCollectionParam(param, 'ssv')).to.be('aa bb 123');
|
||||
});
|
||||
|
||||
it('works for tsv', function() {
|
||||
expect(apiClient.buildCollectionParam(param, 'tsv')).to.be('aa\tbb\t123');
|
||||
});
|
||||
|
||||
it('works for pipes', function() {
|
||||
expect(apiClient.buildCollectionParam(param, 'pipes')).to.be('aa|bb|123');
|
||||
});
|
||||
|
||||
it('works for multi', function() {
|
||||
expect(apiClient.buildCollectionParam(param, 'multi')).to.eql(['aa', 'bb', '123']);
|
||||
});
|
||||
|
||||
it('fails for invalid collection format', function() {
|
||||
expect(function() { apiClient.buildCollectionParam(param, 'INVALID'); }).to.throwError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#buildUrl', function() {
|
||||
it('should work without path parameters in the path', function() {
|
||||
expect(apiClient.buildUrl('/abc', {})).to
|
||||
.be('http://petstore.swagger.io/v2/abc');
|
||||
expect(apiClient.buildUrl('/abc/def?ok', {id: 123})).to
|
||||
.be('http://petstore.swagger.io/v2/abc/def?ok');
|
||||
});
|
||||
|
||||
it('should work with path parameters in the path', function() {
|
||||
expect(apiClient.buildUrl('/{id}', {id: 123})).to
|
||||
.be('http://petstore.swagger.io/v2/123');
|
||||
expect(apiClient.buildUrl('/abc/{id}/{name}?ok', {id: 456, name: 'a b'})).to.
|
||||
be('http://petstore.swagger.io/v2/abc/456/a%20b?ok');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isJsonMime', function() {
|
||||
it('should return true for JSON MIME', function() {
|
||||
expect(apiClient.isJsonMime('application/json')).to.be(true);
|
||||
expect(apiClient.isJsonMime('application/json; charset=UTF8')).to.be(true);
|
||||
expect(apiClient.isJsonMime('APPLICATION/JSON')).to.be(true);
|
||||
});
|
||||
|
||||
it('should return false for non-JSON MIME', function() {
|
||||
expect(apiClient.isJsonMime('')).to.be(false);
|
||||
expect(apiClient.isJsonMime('text/plain')).to.be(false);
|
||||
expect(apiClient.isJsonMime('application/xml')).to.be(false);
|
||||
expect(apiClient.isJsonMime('application/jsonp')).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
describe('#defaultHeaders', function() {
|
||||
it('should initialize default headers to be an empty object', function() {
|
||||
expect(apiClient.defaultHeaders).to.eql({});
|
||||
});
|
||||
|
||||
it('should put default headers in request', function() {
|
||||
var newClient = new SwaggerPetstore.ApiClient;
|
||||
newClient.defaultHeaders['Content-Type'] = 'text/plain'
|
||||
newClient.defaultHeaders['api_key'] = 'special-key'
|
||||
|
||||
var expected = {'Content-Type': 'text/plain', 'api_key': 'special-key'};
|
||||
expect(newClient.defaultHeaders).to.eql(expected);
|
||||
var req = makeDumbRequest(newClient);
|
||||
req.unset('User-Agent');
|
||||
expect(req.header).to.eql(expected);
|
||||
});
|
||||
|
||||
it('should override default headers with provided header params', function() {
|
||||
var newClient = new SwaggerPetstore.ApiClient;
|
||||
newClient.defaultHeaders['Content-Type'] = 'text/plain'
|
||||
newClient.defaultHeaders['api_key'] = 'special-key'
|
||||
|
||||
var headerParams = {'Content-Type': 'application/json', 'Authorization': 'Bearer test-token'}
|
||||
var expected = {
|
||||
'Content-Type': 'application/json',
|
||||
'api_key': 'special-key',
|
||||
'Authorization': 'Bearer test-token'
|
||||
};
|
||||
var req = makeDumbRequest(newClient, {headerParams: headerParams});
|
||||
req.unset('User-Agent');
|
||||
expect(req.header).to.eql(expected);
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
});
|
||||
|
||||
function makeDumbRequest(apiClient, opts) {
|
||||
opts = opts || {};
|
||||
var path = opts.path || '/store/inventory';
|
||||
var httpMethod = opts.httpMethod || 'GET';
|
||||
var pathParams = opts.pathParams || {};
|
||||
var queryParams = opts.queryParams || {};
|
||||
var headerParams = opts.headerParams || {};
|
||||
var formParams = opts.formParams || {};
|
||||
var bodyParam = opts.bodyParam;
|
||||
var contentTypes = opts.contentTypes || [];
|
||||
var accepts = opts.accepts || [];
|
||||
var callback = opts.callback;
|
||||
return apiClient.callApi(path, httpMethod, pathParams, queryParams,
|
||||
headerParams, formParams, bodyParam, contentTypes, accepts, callback
|
||||
);
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
if (typeof module === 'object' && module.exports) {
|
||||
var expect = require('expect.js');
|
||||
var SwaggerPetstore = require('../../src/index');
|
||||
}
|
||||
|
||||
var api;
|
||||
|
||||
beforeEach(function() {
|
||||
api = new SwaggerPetstore.PetApi();
|
||||
});
|
||||
|
||||
var createRandomPet = function() {
|
||||
var id = new Date().getTime();
|
||||
var pet = new SwaggerPetstore.Pet();
|
||||
pet.setId(id);
|
||||
pet.setName("gorilla" + id);
|
||||
|
||||
var category = new SwaggerPetstore.Category();
|
||||
category.setName("really-happy");
|
||||
pet.setCategory(category);
|
||||
|
||||
pet.setStatus('available');
|
||||
var photos = ["http://foo.bar.com/1", "http://foo.bar.com/2"];
|
||||
pet.setPhotoUrls(photos);
|
||||
|
||||
return pet;
|
||||
};
|
||||
|
||||
describe('PetApi', function() {
|
||||
it('should create and get pet', function(done) {
|
||||
var pet = createRandomPet();
|
||||
api.addPet(pet)
|
||||
.then(function() {
|
||||
return api.getPetById(pet.id)
|
||||
})
|
||||
.then(function(fetched) {
|
||||
//expect(response.status).to.be(200);
|
||||
//expect(response.ok).to.be(true);
|
||||
//expect(response.get('Content-Type')).to.be('application/json');
|
||||
expect(fetched).to.be.ok();
|
||||
expect(fetched.id).to.be(pet.id);
|
||||
expect(fetched.getPhotoUrls()).to.eql(pet.getPhotoUrls());
|
||||
expect(fetched.getCategory()).to.be.ok();
|
||||
expect(fetched.getCategory().getName()).to.be(pet.getCategory().getName());
|
||||
|
||||
api.deletePet(pet.id);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void testUpdatePet() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
pet.setName("programmer");
|
||||
|
||||
api.updatePet(pet);
|
||||
|
||||
Pet fetched = api.getPetById(pet.getId());
|
||||
assertNotNull(fetched);
|
||||
assertEquals(pet.getId(), fetched.getId());
|
||||
assertNotNull(fetched.getCategory());
|
||||
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindPetsByStatus() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
pet.setName("programmer");
|
||||
pet.setStatus(Pet.StatusEnum.AVAILABLE);
|
||||
|
||||
api.updatePet(pet);
|
||||
|
||||
List<Pet> pets = api.findPetsByStatus(Arrays.asList(new String[]{"available"}));
|
||||
assertNotNull(pets);
|
||||
|
||||
boolean found = false;
|
||||
for (Pet fetched : pets) {
|
||||
if (fetched.getId().equals(pet.getId())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(found);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindPetsByTags() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
pet.setName("monster");
|
||||
pet.setStatus(Pet.StatusEnum.AVAILABLE);
|
||||
|
||||
List<Tag> tags = new ArrayList<Tag>();
|
||||
Tag tag1 = new Tag();
|
||||
tag1.setName("friendly");
|
||||
tags.add(tag1);
|
||||
pet.setTags(tags);
|
||||
|
||||
api.updatePet(pet);
|
||||
|
||||
List<Pet> pets = api.findPetsByTags(Arrays.asList(new String[]{"friendly"}));
|
||||
assertNotNull(pets);
|
||||
|
||||
boolean found = false;
|
||||
for (Pet fetched : pets) {
|
||||
if (fetched.getId().equals(pet.getId())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePetWithForm() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
pet.setName("frank");
|
||||
api.addPet(pet);
|
||||
|
||||
Pet fetched = api.getPetById(pet.getId());
|
||||
|
||||
api.updatePetWithForm(String.valueOf(fetched.getId()), "furt", null);
|
||||
Pet updated = api.getPetById(fetched.getId());
|
||||
|
||||
assertEquals(updated.getName(), "furt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletePet() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
api.addPet(pet);
|
||||
|
||||
Pet fetched = api.getPetById(pet.getId());
|
||||
api.deletePet(fetched.getId(), null);
|
||||
|
||||
try {
|
||||
fetched = api.getPetById(fetched.getId());
|
||||
fail("expected an error");
|
||||
} catch (ApiException e) {
|
||||
assertEquals(404, e.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUploadFile() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
api.addPet(pet);
|
||||
|
||||
File file = new File("hello.txt");
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
||||
writer.write("Hello world!");
|
||||
writer.close();
|
||||
|
||||
api.uploadFile(pet.getId(), "a test file", new File(file.getAbsolutePath()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsAndHashCode() {
|
||||
Pet pet1 = new Pet();
|
||||
Pet pet2 = new Pet();
|
||||
assertTrue(pet1.equals(pet2));
|
||||
assertTrue(pet2.equals(pet1));
|
||||
assertTrue(pet1.hashCode() == pet2.hashCode());
|
||||
assertTrue(pet1.equals(pet1));
|
||||
assertTrue(pet1.hashCode() == pet1.hashCode());
|
||||
|
||||
pet2.setName("really-happy");
|
||||
pet2.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"}));
|
||||
assertFalse(pet1.equals(pet2));
|
||||
assertFalse(pet2.equals(pet1));
|
||||
assertFalse(pet1.hashCode() == (pet2.hashCode()));
|
||||
assertTrue(pet2.equals(pet2));
|
||||
assertTrue(pet2.hashCode() == pet2.hashCode());
|
||||
|
||||
pet1.setName("really-happy");
|
||||
pet1.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"}));
|
||||
assertTrue(pet1.equals(pet2));
|
||||
assertTrue(pet2.equals(pet1));
|
||||
assertTrue(pet1.hashCode() == pet2.hashCode());
|
||||
assertTrue(pet1.equals(pet1));
|
||||
assertTrue(pet1.hashCode() == pet1.hashCode());
|
||||
}
|
||||
}
|
||||
*/
|
@ -0,0 +1 @@
|
||||
--timeout 10000
|
@ -0,0 +1,40 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Mocha Tests</title>
|
||||
<link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
|
||||
<script src="https://cdn.rawgit.com/jquery/jquery/2.1.4/dist/jquery.min.js"></script>
|
||||
<script src="https://cdn.rawgit.com/Automattic/expect.js/0.3.1/index.js"></script>
|
||||
<script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script>
|
||||
<script>
|
||||
mocha.setup({
|
||||
ui: 'bdd',
|
||||
timeout: 10000
|
||||
});
|
||||
</script>
|
||||
|
||||
<script src="../node_modules/superagent/superagent.js"></script>
|
||||
|
||||
<script src="../src/ApiClient.js"></script>
|
||||
|
||||
<script src="../src/model/Category.js"></script>
|
||||
<script src="../src/model/Tag.js"></script>
|
||||
<script src="../src/model/Pet.js"></script>
|
||||
<script src="../src/model/User.js"></script>
|
||||
|
||||
<script src="../src/api/PetApi.js"></script>
|
||||
|
||||
<script src="ApiClientTest.js"></script>
|
||||
<script src="api/PetApiTest.js"></script>
|
||||
|
||||
<script>
|
||||
mocha.checkLeaks();
|
||||
mocha.globals(['jQuery']);
|
||||
mocha.run();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user