Skip to content

Commit

Permalink
Merge pull request #103 from nicolas-chaulet/fix/falsy-headers
Browse files Browse the repository at this point in the history
fix(api): handle falsy headers
  • Loading branch information
mrlubos authored Mar 20, 2024
2 parents 8382138 + 5011b06 commit e3fdbf2
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/templates/core/angular/getHeaders.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getHeaders = (config: OpenAPIConfig, options: ApiRequestOptions): O
...additionalHeaders,
...options.headers,
})
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.reduce((headers, [key, value]) => ({
...headers,
[key]: String(value),
Expand Down
2 changes: 1 addition & 1 deletion src/templates/core/axios/getHeaders.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio
...options.headers,
...formHeaders,
})
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.reduce((headers, [key, value]) => ({
...headers,
[key]: String(value),
Expand Down
2 changes: 1 addition & 1 deletion src/templates/core/fetch/getHeaders.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio
...additionalHeaders,
...options.headers,
})
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.reduce((headers, [key, value]) => ({
...headers,
[key]: String(value),
Expand Down
2 changes: 1 addition & 1 deletion src/templates/core/functions/getFormData.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
};

Object.entries(options.formData)
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
Expand Down
2 changes: 1 addition & 1 deletion src/templates/core/node/getHeaders.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio
...additionalHeaders,
...options.headers,
})
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.reduce((headers, [key, value]) => ({
...headers,
[key]: String(value),
Expand Down
2 changes: 1 addition & 1 deletion src/templates/core/xhr/getHeaders.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio
...additionalHeaders,
...options.headers,
})
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.reduce((headers, [key, value]) => ({
...headers,
[key]: String(value),
Expand Down
12 changes: 6 additions & 6 deletions test/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
};

Object.entries(options.formData)
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
Expand Down Expand Up @@ -367,7 +367,7 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio
...additionalHeaders,
...options.headers,
})
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.reduce(
(headers, [key, value]) => ({
...headers,
Expand Down Expand Up @@ -3298,7 +3298,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
};

Object.entries(options.formData)
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
Expand Down Expand Up @@ -3334,7 +3334,7 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio
...additionalHeaders,
...options.headers,
})
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.reduce(
(headers, [key, value]) => ({
...headers,
Expand Down Expand Up @@ -8378,7 +8378,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
};

Object.entries(options.formData)
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
Expand Down Expand Up @@ -8414,7 +8414,7 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio
...additionalHeaders,
...options.headers,
})
.filter(([_, value]) => value)
.filter(([_, value]) => value !== undefined && value !== null)
.reduce(
(headers, [key, value]) => ({
...headers,
Expand Down

0 comments on commit e3fdbf2

Please sign in to comment.