Add "servers" support to operation, path in the JS client (#2060)

* add operation, path servers to js es6 client

* add servers support to operation, path in js es5

* fix null check
This commit is contained in:
William Cheng
2019-02-09 22:25:01 +08:00
committed by GitHub
parent 8f5fa4df83
commit 348c22c883
40 changed files with 322 additions and 643 deletions

View File

@@ -112,19 +112,26 @@ class ApiClient {
return param.toString();
}
/**
/**
* Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
* NOTE: query parameters are not handled here.
* @param {String} path The path to append to the base URL.
* @param {Object} pathParams The parameter values to append.
* @param {String} apiBasePath Base path defined in the path, operation level to override the default one
* @returns {String} The encoded path with parameter values substituted.
*/
buildUrl(path, pathParams) {
buildUrl(path, pathParams, apiBasePath) {
if (!path.match(/^\//)) {
path = '/' + path;
}
var url = this.basePath + path;
// use API (operation, path) base path if defined
if (apiBasePath !== null && apiBasePath !== undefined) {
url = apiBasePath + path;
}
url = url.replace(/\{([\w-]+)\}/g, (fullMatch, key) => {
var value;
if (pathParams.hasOwnProperty(key)) {
@@ -308,7 +315,7 @@ class ApiClient {
});
}
/**
/**
* Deserializes an HTTP response body into a value of the specified type.
* @param {Object} response A SuperAgent response object.
* @param {(String|Array.<String>|Object.<String, Object>|Function)} returnType The type to return. Pass a string for simple types
@@ -333,7 +340,7 @@ class ApiClient {
return ApiClient.convertToType(data, returnType);
}
/**
/**
* Callback function to receive the result of the operation.
* @callback module:ApiClient~callApiCallback
* @param {String} error Error message, if any.
@@ -341,7 +348,7 @@ class ApiClient {
* @param {String} response The complete HTTP response.
*/
/**
/**
* Invokes the REST service using the supplied settings and parameters.
* @param {String} path The base URL to invoke.
* @param {String} httpMethod The HTTP method to use.
@@ -355,14 +362,15 @@ class ApiClient {
* @param {Array.<String>} accepts An array of acceptable response MIME types.
* @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
* constructor for a complex type.
* @param {String} apiBasePath base path defined in the operation/path level to override the default one
* @param {module:ApiClient~callApiCallback} callback The callback function.
* @returns {Object} The SuperAgent request object.
*/
callApi(path, httpMethod, pathParams,
queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts,
returnType, callback) {
returnType, apiBasePath, callback) {
var url = this.buildUrl(path, pathParams);
var url = this.buildUrl(path, pathParams, apiBasePath);
var request = superagent(httpMethod, url);
if (this.plugins !== null) {
@@ -443,8 +451,6 @@ class ApiClient {
}
}
request.end((error, response) => {
if (callback) {
var data = null;