-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
Payload for "application/x-www-form-urlencoded" is actually for "multipart/form-data" #1441
Comments
Ok, it seems like the types for So some other fix is needed. |
@soulchild I ran into the same problem today, and found a fix by patching the generated services after generation. In case the mediaType is for url-encoded form data, you can replace: |
You can create new script to fix with a single liner |
I ran into this today as well, from looking at the code, the request templates all need to become contextually aware of the different potential encoding strategies for Forms based on if the As an example, for clients generated to use
There are two potential, simpler, fixes here - (1) either the const formHeaders = typeof formData?.getHeaders === 'function' && formData?.getHeaders(
!!options.mediaType ? { 'Content-Type': options.mediaType} : {},
) || {} or (2) alter the order of the object expansion operations: const headers = Object.entries({
Accept: 'application/json',
...additionalHeaders,
+ ...formHeaders,
...options.headers,
- ...formHeaders,
}) Of the above two, the former is likely more resilient due to allowing Would either of these solutions be acceptable as a PR? |
Check out our fork of this repository @hey-api/openapi-ts. We have fixed this issue in |
I have an OpenAPI specification with a contentType of
application/x-www-form-urlencoded
:This library creates POST data using
FormData
which ends up being suitable for a contentType ofmultipart/form-data
, notapplication/x-www-form-urlencoded
.In other words, instead of something like:
it generates a base64-encoded payload, which decodes to:
I believe the FormData needs to be passed through
URLSearchParams()
to generate a payload suitable forapplication/x-www-form-urlencoded
:Or am I missing something here? Thanks! 😄
The text was updated successfully, but these errors were encountered: