diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/common.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/common.mustache index aa594015c7f9..004fc11fdae8 100755 --- a/modules/openapi-generator/src/main/resources/typescript-axios/common.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/common.mustache @@ -118,10 +118,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/echo_api/typescript-axios/build/common.ts b/samples/client/echo_api/typescript-axios/build/common.ts index fc1881f27b35..c4b85d352ca7 100644 --- a/samples/client/echo_api/typescript-axios/build/common.ts +++ b/samples/client/echo_api/typescript-axios/build/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/others/typescript-axios/with-separate-models-and-api-inheritance/common.ts b/samples/client/others/typescript-axios/with-separate-models-and-api-inheritance/common.ts index 95d62a0dcddb..71ef49eebeb4 100644 --- a/samples/client/others/typescript-axios/with-separate-models-and-api-inheritance/common.ts +++ b/samples/client/others/typescript-axios/with-separate-models-and-api-inheritance/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/composed-schemas/common.ts b/samples/client/petstore/typescript-axios/builds/composed-schemas/common.ts index d629dec4427f..259040a2b386 100644 --- a/samples/client/petstore/typescript-axios/builds/composed-schemas/common.ts +++ b/samples/client/petstore/typescript-axios/builds/composed-schemas/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/default/common.ts b/samples/client/petstore/typescript-axios/builds/default/common.ts index d5b9e4718aea..c58729d6aaf5 100644 --- a/samples/client/petstore/typescript-axios/builds/default/common.ts +++ b/samples/client/petstore/typescript-axios/builds/default/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/es6-target/common.ts b/samples/client/petstore/typescript-axios/builds/es6-target/common.ts index d5b9e4718aea..c58729d6aaf5 100644 --- a/samples/client/petstore/typescript-axios/builds/es6-target/common.ts +++ b/samples/client/petstore/typescript-axios/builds/es6-target/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/test-petstore/common.ts b/samples/client/petstore/typescript-axios/builds/test-petstore/common.ts index c0f62a7b6df1..e1b019a31500 100644 --- a/samples/client/petstore/typescript-axios/builds/test-petstore/common.ts +++ b/samples/client/petstore/typescript-axios/builds/test-petstore/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/with-complex-headers/common.ts b/samples/client/petstore/typescript-axios/builds/with-complex-headers/common.ts index d5b9e4718aea..c58729d6aaf5 100644 --- a/samples/client/petstore/typescript-axios/builds/with-complex-headers/common.ts +++ b/samples/client/petstore/typescript-axios/builds/with-complex-headers/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/with-fake-endpoints-models-for-testing-with-http-signature/common.ts b/samples/client/petstore/typescript-axios/builds/with-fake-endpoints-models-for-testing-with-http-signature/common.ts index c0f62a7b6df1..e1b019a31500 100644 --- a/samples/client/petstore/typescript-axios/builds/with-fake-endpoints-models-for-testing-with-http-signature/common.ts +++ b/samples/client/petstore/typescript-axios/builds/with-fake-endpoints-models-for-testing-with-http-signature/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/with-interfaces/common.ts b/samples/client/petstore/typescript-axios/builds/with-interfaces/common.ts index d5b9e4718aea..c58729d6aaf5 100644 --- a/samples/client/petstore/typescript-axios/builds/with-interfaces/common.ts +++ b/samples/client/petstore/typescript-axios/builds/with-interfaces/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/with-node-imports/common.ts b/samples/client/petstore/typescript-axios/builds/with-node-imports/common.ts index a88b97565783..25f8cc331dce 100644 --- a/samples/client/petstore/typescript-axios/builds/with-node-imports/common.ts +++ b/samples/client/petstore/typescript-axios/builds/with-node-imports/common.ts @@ -127,10 +127,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/with-npm-version-and-separate-models-and-api/common.ts b/samples/client/petstore/typescript-axios/builds/with-npm-version-and-separate-models-and-api/common.ts index d5b9e4718aea..c58729d6aaf5 100644 --- a/samples/client/petstore/typescript-axios/builds/with-npm-version-and-separate-models-and-api/common.ts +++ b/samples/client/petstore/typescript-axios/builds/with-npm-version-and-separate-models-and-api/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/with-npm-version/common.ts b/samples/client/petstore/typescript-axios/builds/with-npm-version/common.ts index d5b9e4718aea..c58729d6aaf5 100644 --- a/samples/client/petstore/typescript-axios/builds/with-npm-version/common.ts +++ b/samples/client/petstore/typescript-axios/builds/with-npm-version/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/with-single-request-parameters/common.ts b/samples/client/petstore/typescript-axios/builds/with-single-request-parameters/common.ts index d5b9e4718aea..c58729d6aaf5 100644 --- a/samples/client/petstore/typescript-axios/builds/with-single-request-parameters/common.ts +++ b/samples/client/petstore/typescript-axios/builds/with-single-request-parameters/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export diff --git a/samples/client/petstore/typescript-axios/builds/with-string-enums/common.ts b/samples/client/petstore/typescript-axios/builds/with-string-enums/common.ts index d5b9e4718aea..c58729d6aaf5 100644 --- a/samples/client/petstore/typescript-axios/builds/with-string-enums/common.ts +++ b/samples/client/petstore/typescript-axios/builds/with-string-enums/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export