openapi-typescript-codegen
openapi-typescript-codegen copied to clipboard
fix: Object.entries(formData) in getFormData
When you use Object.entries(formData), it attempts to convert the FormData object into an array of key-value pairs, as it would with a regular JavaScript object. However, since FormData doesn't store its data in enumerable properties, Object.entries returns an empty array.
This will not work:
Object.entries(options.formData)
.filter(([_, value]) => isDefined(value))
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
} else {
process(key, value);
}
});
On the other hand, formData.entries() is a method specifically provided by the FormData interface. It returns an iterator allowing for the traversal of all key/value pairs contained in the FormData object. This method is designed to understand and interact with the internal structure of FormData, so it successfully retrieves the data.
This will work:
for (let [key, value] of options.formData.entries()) {
if (isDefined(value)) {
if (Array.isArray(value)) {
value.forEach((v) => process(key, v));
} else {
process(key, value);
}
}
}
Hi, will this be added any time soon?
+1, waiting for this fix as well
+1
Check out our fork of this repository @hey-api/openapi-ts. We have fixed this issue in v0.32.1
. If you run into any further issues, open an issue in our repository. Thanks.