Skip to content

fix: Object.entries(formData) in getFormData#1894

Open
dmitriyzhukcoso wants to merge 1 commit intoferdikoomen:mainfrom
dmitriyzhukcoso:patch-1
Open

fix: Object.entries(formData) in getFormData#1894
dmitriyzhukcoso wants to merge 1 commit intoferdikoomen:mainfrom
dmitriyzhukcoso:patch-1

Conversation

@dmitriyzhukcoso
Copy link
Copy Markdown

@dmitriyzhukcoso dmitriyzhukcoso commented Nov 17, 2023

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);
        }
      }
    }

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);
        }
      }
    }
@dmitriyzhukcoso dmitriyzhukcoso changed the title Fix for Object.entries(formData) in getFormData fix: Object.entries(formData) in getFormData Nov 18, 2023
@dmitriyzhuk
Copy link
Copy Markdown

Hi, will this be added any time soon?

@stasdrvn
Copy link
Copy Markdown

+1, waiting for this fix as well

@illiaDream
Copy link
Copy Markdown

+1

@jordanshatford
Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants