Skip to content

Commit 32f2f77

Browse files
committed
feat: serialize sets to array for payloads
when requests go over the wire, sets should become arrays. OpenAPITools/openapi-generator#11746 for reference
1 parent d0c0607 commit 32f2f77

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

templates-js/common.mustache

+21
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,33 @@ export const setSearchParams = function (url: URL, ...objects: any[]) {
107107
url.search = searchParams.toString();
108108
}
109109

110+
/**
111+
*
112+
* @export
113+
*/
114+
export const recursiveSerializeSetToArray = function (value: any) {
115+
if (value instanceof Set) {
116+
return Array.from(value);
117+
}
118+
else if (typeof value === 'object') {
119+
for (const key in value) {
120+
value[key] = recursiveSerializeSetToArray(value[key]);
121+
}
122+
}
123+
return value;
124+
}
125+
110126
/**
111127
*
112128
* @export
113129
*/
114130
export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
115131
const nonString = typeof value !== 'string';
132+
// if value is an object, iterate through the values, and if any of them are of type Set, convert them to Array
133+
if (nonString && typeof value === 'object') {
134+
value = recursiveSerializeSetToArray(value)
135+
}
136+
116137
const needsSerialization = nonString && configuration && configuration.isJsonMime
117138
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
118139
: nonString;

0 commit comments

Comments
 (0)