-
-
Notifications
You must be signed in to change notification settings - Fork 245
Open
Labels
bug π₯Something isn't workingSomething isn't workingclientClient package relatedClient package related
Description
Description
Motivation
using Headers
with a client that has generated headers (e.g. every post request)
Issue
the generated types for the client allow for headers to either be passed as a POJO or an instance of Headers.
In certain cases, hey api generates headers to be used in addition to the user provided headers.
The desired behavior is, that those will be merged with the user provided headers.
Example:
/**
* generated api function example (note that `Content-Type` is generated by hey SDK
* & will be merged with the user provided headers
*/
export const todoApiAdd = (options) => {
return (options.client ?? _heyApiClient).post({
url: '/todo/add',
...options,
headers: {
'Content-Type': 'application/json',
...options.headers
}
});
};
However, this implementation (introduced in #1065 )does not take into account that option.headers
could be an instance of Headers
.
Proposed fix
I believe the best path forward would be modifying the generated code to allow lossless merging of the two:
/**
* Example of what a fix could look like
*/
export const todoApiAdd = (options) => {
// create new headers object from headers, works with both headers instance and POJO
const headers = new Headers(options.headers)
// set generated headers
headers.set('Content-Type', 'application/json')
return (options.client ?? _heyApiClient).post({
url: '/todo/add',
...options,
headers
});
};
Reproducible example or configuration
OpenAPI specification (optional)
No response
System information (optional)
No response
mrlubos
Metadata
Metadata
Assignees
Labels
bug π₯Something isn't workingSomething isn't workingclientClient package relatedClient package related