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

Edge cases with FormData body conversion #1585

Open
ntjess opened this issue Jan 18, 2025 · 1 comment
Open

Edge cases with FormData body conversion #1585

ntjess opened this issue Jan 18, 2025 · 1 comment
Labels
bug 🔥 Something isn't working

Comments

@ntjess
Copy link

ntjess commented Jan 18, 2025

Description

When hey-api converts a body payload into a form for multipart/form-data, nested arrays with one element lose their distinction as nested upon serialization. Instead, they look like the unnested data type. It is due to this code (and its equivalent for other backends):

value.forEach((v) => serializeFormDataPair(formData, key, v));

When only one value exists, the form has no indication to wrap the inner element as a list and instead treats it as a single list

Reproducible example or configuration

repro-heyapi.zip

  • Ensure fastapi is installed with python >=3.10 as the server (optional, only to verify the 422 unprocessible entity error)
  • Ensure npm packages are available (provided in the zip for node 22.5.1)
  • Execute ./run_frontend_backend.sh and open localhost:5173 in browser
  • Click the button and observe the POST data is incorrectly formatted (list[int] is created, not list[list[int]])

To regenerate the hey-api client api, ensure the fastapi server is running (it provides the openapi file), and run npx openapi-ts

OpenAPI specification (optional)

3.1.1

System information (optional)

macos

@ntjess ntjess added the bug 🔥 Something isn't working label Jan 18, 2025
@ntjess
Copy link
Author

ntjess commented Jan 18, 2025

Minor update: main.ts:16 should POST [[7]], not [7]. The 422 error still occurs when posting the correct data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant