Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dmitriyzhukcoso
Copy link

@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

Hi, will this be added any time soon?

@stasdrvn
Copy link

+1, waiting for this fix as well

@illiaDream
Copy link

+1

@jordanshatford
Copy link

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.

None yet

5 participants