Skip to content

Commit

Permalink
Revert "Fix: Incorrect serialisation of maps and sets in typescript-a…
Browse files Browse the repository at this point in the history
…xios (#1…" (OpenAPITools#18452)

This reverts commit 8152052.
  • Loading branch information
macjohnny authored Apr 22, 2024
1 parent c64d569 commit 36911c7
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 615 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,50 +118,10 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any,
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
: nonString;
return needsSerialization
? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {})
? JSON.stringify(value !== undefined ? 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<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
42 changes: 1 addition & 41 deletions samples/client/echo_api/typescript-axios/build/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,50 +126,10 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any,
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
: nonString;
return needsSerialization
? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {})
? JSON.stringify(value !== undefined ? 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<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,50 +126,10 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any,
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
: nonString;
return needsSerialization
? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {})
? JSON.stringify(value !== undefined ? 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<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,50 +126,10 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any,
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
: nonString;
return needsSerialization
? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {})
? JSON.stringify(value !== undefined ? 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<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,50 +126,10 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any,
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
: nonString;
return needsSerialization
? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {})
? JSON.stringify(value !== undefined ? 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<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,50 +126,10 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any,
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
: nonString;
return needsSerialization
? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {})
? JSON.stringify(value !== undefined ? 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<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,50 +126,10 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any,
? configuration.isJsonMime(requestOptions.headers['Content-Type'])
: nonString;
return needsSerialization
? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {})
? JSON.stringify(value !== undefined ? 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<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand Down
Loading

0 comments on commit 36911c7

Please sign in to comment.