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

FormData Breaks Headers #1179

Open
mannanj opened this issue Oct 21, 2024 · 1 comment
Open

FormData Breaks Headers #1179

mannanj opened this issue Oct 21, 2024 · 1 comment
Labels
bug 🔥 Something isn't working

Comments

@mannanj
Copy link

mannanj commented Oct 21, 2024

Description

Using a request body of type content: multipart/form-data breaks the headers generated by hey-api for solid query.

Compared to other methods that do not use form data, the library decides to generate a client post method that overwrites all headers (incorrectly) in order to set the content-type to null to respect browser boundaries.

Example: (broken headers behavior)

export const methodName = <ThrowOnError extends boolean = false>(options: Options<MethodDataType, ThrowOnError>, ) => {
return (options?.client ?? client).post<
MethodNameResponseType,
MethodNameErrorType,
ThrowOnError>({

...options,
...formDataBodySerializer,
headers: { 
  'Content-Type': null,
}
url: <url here>,
});
};

This behavior makes it so the method ignores all headers passed in, such as required Accept headers.

This is what should happen: (What I do to fix the behavior is pass the options.headers through spread syntax).

export const methodName = <ThrowOnError extends boolean = false>(options: Options<MethodDataType, ThrowOnError>, ) => {
return (options?.client ?? client).post<
MethodNameResponseType,
MethodNameErrorType,
ThrowOnError>({

...options,
...formDataBodySerializer,
headers: {  
  ...options.headers, // FIX HERE
  'Content-Type': null,
}
url: <url here>,
});
};

Reproducible example or configuration

import { defineConfig } from '@hey-api/openapi-ts';

defineConfig({
client: '@hey-api/client-fetch',
input: '<path to yaml>',
output: { path: '<path to output>', format: 'prettier'}
plugins: ['@tanstack/solid-query']
})

OpenAPI specification (optional)

< endpoint url >:
post:
summary: <summary>
operationId: <name here>
parameters: 
   ... can be provided upon request. they are just 3 string parameters in the path that are required.
 -$ref: <ref to accept header here>
 -$ref: <ref to source header here>

requestBody: 
required: true
content: 
multipart/form-data:
schema: 
type: object

System information (optional)

node v18.20.1
@hey-api/openapi-ts ^0.53
@hey-api/client-fetch ^0.24

@tanstack/solid-query plug.

Note: It does not matter what headers I specify in the .yaml, the method generated for the form data does not respect them.

@mannanj mannanj added the bug 🔥 Something isn't working label Oct 21, 2024
@mrlubos
Copy link
Member

mrlubos commented Oct 21, 2024

Hey @mannanj, are you sure you're on the latest version? This has been fixed in https://github.com/hey-api/openapi-ts/releases/tag/%40hey-api/openapi-ts%400.53.2

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

2 participants