forked from loafle/openapi-generator-original
This commit is contained in:
@@ -119,9 +119,28 @@
|
|||||||
if (param instanceof Date) {
|
if (param instanceof Date) {
|
||||||
return param.toJSON();
|
return param.toJSON();
|
||||||
}
|
}
|
||||||
|
if (this.canBeJsonified(param)) {
|
||||||
|
return JSON.stringify(param);
|
||||||
|
}
|
||||||
return param.toString();
|
return param.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
{{#emitJSDoc}} /**
|
||||||
|
* Returns a boolean indicating if the parameter could be JSON.stringified
|
||||||
|
* @param param The actual parameter
|
||||||
|
* @returns {Boolean} Flag indicating if <code>param</code> can be JSON.stringified
|
||||||
|
*/
|
||||||
|
{{/emitJSDoc}} exports.prototype.canBeJsonified = function(str) {
|
||||||
|
if (typeof str !== 'string' && typeof str !== 'object') return false;
|
||||||
|
try {
|
||||||
|
const type = str.toString();
|
||||||
|
return type === '[object Object]'
|
||||||
|
|| type === '[object Array]';
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
{{#emitJSDoc}}
|
{{#emitJSDoc}}
|
||||||
/**
|
/**
|
||||||
* Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
|
* Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
|
||||||
|
|||||||
@@ -108,10 +108,29 @@ class ApiClient {
|
|||||||
if (param instanceof Date) {
|
if (param instanceof Date) {
|
||||||
return param.toJSON();
|
return param.toJSON();
|
||||||
}
|
}
|
||||||
|
if (ApiClient.canBeJsonified(param)) {
|
||||||
|
return JSON.stringify(param);
|
||||||
|
}
|
||||||
|
|
||||||
return param.toString();
|
return param.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{{#emitJSDoc}}/**
|
||||||
|
* Returns a boolean indicating if the parameter could be JSON.stringified
|
||||||
|
* @param param The actual parameter
|
||||||
|
* @returns {Boolean} Flag indicating if <code>param</code> can be JSON.stringified
|
||||||
|
*/{{/emitJSDoc}}
|
||||||
|
static canBeJsonified(str) {
|
||||||
|
if (typeof str !== 'string' && typeof str !== 'object') return false;
|
||||||
|
try {
|
||||||
|
const type = str.toString();
|
||||||
|
return type === '[object Object]'
|
||||||
|
|| type === '[object Array]';
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
{{#emitJSDoc}}
|
{{#emitJSDoc}}
|
||||||
/**
|
/**
|
||||||
* Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
|
* Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
|
||||||
|
|||||||
@@ -109,10 +109,29 @@ class ApiClient {
|
|||||||
if (param instanceof Date) {
|
if (param instanceof Date) {
|
||||||
return param.toJSON();
|
return param.toJSON();
|
||||||
}
|
}
|
||||||
|
if (ApiClient.canBeJsonified(param)) {
|
||||||
|
return JSON.stringify(param);
|
||||||
|
}
|
||||||
|
|
||||||
return param.toString();
|
return param.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a boolean indicating if the parameter could be JSON.stringified
|
||||||
|
* @param param The actual parameter
|
||||||
|
* @returns {Boolean} Flag indicating if <code>param</code> can be JSON.stringified
|
||||||
|
*/
|
||||||
|
static canBeJsonified(str) {
|
||||||
|
if (typeof str !== 'string' && typeof str !== 'object') return false;
|
||||||
|
try {
|
||||||
|
const type = str.toString();
|
||||||
|
return type === '[object Object]'
|
||||||
|
|| type === '[object Array]';
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
|
* 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.
|
* NOTE: query parameters are not handled here.
|
||||||
|
|||||||
@@ -109,10 +109,29 @@ class ApiClient {
|
|||||||
if (param instanceof Date) {
|
if (param instanceof Date) {
|
||||||
return param.toJSON();
|
return param.toJSON();
|
||||||
}
|
}
|
||||||
|
if (ApiClient.canBeJsonified(param)) {
|
||||||
|
return JSON.stringify(param);
|
||||||
|
}
|
||||||
|
|
||||||
return param.toString();
|
return param.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a boolean indicating if the parameter could be JSON.stringified
|
||||||
|
* @param param The actual parameter
|
||||||
|
* @returns {Boolean} Flag indicating if <code>param</code> can be JSON.stringified
|
||||||
|
*/
|
||||||
|
static canBeJsonified(str) {
|
||||||
|
if (typeof str !== 'string' && typeof str !== 'object') return false;
|
||||||
|
try {
|
||||||
|
const type = str.toString();
|
||||||
|
return type === '[object Object]'
|
||||||
|
|| type === '[object Array]';
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
|
* 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.
|
* NOTE: query parameters are not handled here.
|
||||||
|
|||||||
Reference in New Issue
Block a user