Skip to content

Commit

Permalink
fix(client): various warnings in generated client
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanshatford committed Mar 27, 2024
1 parent 98f9d38 commit 33028b7
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-wombats-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

fix various warnings in generated client code
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 !== undefined && value !== null)
.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 !== undefined && value !== null)
.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 !== undefined && value !== null)
.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/base64.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const base64 = (str: string): string => {
try {
return btoa(str);
} catch (err) {
// @ts-ignore
// @ts-expect-error Buffer may not be found.
return Buffer.from(str).toString('base64');
}
};
4 changes: 2 additions & 2 deletions src/templates/core/functions/getFormData.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
if (options.formData) {
const formData = new FormData();

const process = (key: string, value: any) => {
const process = (key: string, value: unknown) => {
if (isString(value) || isBlob(value)) {
formData.append(key, value);
} else {
Expand All @@ -11,7 +11,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
};

Object.entries(options.formData)
.filter(([_, value]) => value !== undefined && value !== null)
.filter(([, value]) => value !== undefined && value !== null)
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
Expand Down
1 change: 0 additions & 1 deletion src/templates/core/functions/isBlob.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const isBlob = (value: any): value is Blob => {
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
// @ts-ignore
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
};
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 !== undefined && value !== null)
.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 !== undefined && value !== null)
.filter(([, value]) => value !== undefined && value !== null)
.reduce((headers, [key, value]) => ({
...headers,
[key]: String(value),
Expand Down
9 changes: 4 additions & 5 deletions test/__snapshots__/v2/test/generated/v2/core/request.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const isBlob = (value: any): value is Blob => {
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
// @ts-ignore
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
};
Expand All @@ -36,7 +35,7 @@ export const base64 = (str: string): string => {
try {
return btoa(str);
} catch (err) {
// @ts-ignore
// @ts-expect-error Buffer may not be found.
return Buffer.from(str).toString('base64');
}
};
Expand Down Expand Up @@ -87,7 +86,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
if (options.formData) {
const formData = new FormData();

const process = (key: string, value: any) => {
const process = (key: string, value: unknown) => {
if (isString(value) || isBlob(value)) {
formData.append(key, value);
} else {
Expand All @@ -96,7 +95,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
};

Object.entries(options.formData)
.filter(([_, value]) => value !== undefined && value !== null)
.filter(([, value]) => value !== undefined && value !== null)
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
Expand Down Expand Up @@ -132,7 +131,7 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio
...additionalHeaders,
...options.headers,
})
.filter(([_, value]) => value !== undefined && value !== null)
.filter(([, value]) => value !== undefined && value !== null)
.reduce(
(headers, [key, value]) => ({
...headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const isBlob = (value: any): value is Blob => {
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
// @ts-ignore
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
};
Expand All @@ -36,7 +35,7 @@ export const base64 = (str: string): string => {
try {
return btoa(str);
} catch (err) {
// @ts-ignore
// @ts-expect-error Buffer may not be found.
return Buffer.from(str).toString('base64');
}
};
Expand Down Expand Up @@ -87,7 +86,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
if (options.formData) {
const formData = new FormData();

const process = (key: string, value: any) => {
const process = (key: string, value: unknown) => {
if (isString(value) || isBlob(value)) {
formData.append(key, value);
} else {
Expand All @@ -96,7 +95,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
};

Object.entries(options.formData)
.filter(([_, value]) => value !== undefined && value !== null)
.filter(([, value]) => value !== undefined && value !== null)
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
Expand Down Expand Up @@ -132,7 +131,7 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio
...additionalHeaders,
...options.headers,
})
.filter(([_, value]) => value !== undefined && value !== null)
.filter(([, value]) => value !== undefined && value !== null)
.reduce(
(headers, [key, value]) => ({
...headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const isBlob = (value: any): value is Blob => {
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
// @ts-ignore
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
};
Expand All @@ -36,7 +35,7 @@ export const base64 = (str: string): string => {
try {
return btoa(str);
} catch (err) {
// @ts-ignore
// @ts-expect-error Buffer may not be found.
return Buffer.from(str).toString('base64');
}
};
Expand Down Expand Up @@ -87,7 +86,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
if (options.formData) {
const formData = new FormData();

const process = (key: string, value: any) => {
const process = (key: string, value: unknown) => {
if (isString(value) || isBlob(value)) {
formData.append(key, value);
} else {
Expand All @@ -96,7 +95,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
};

Object.entries(options.formData)
.filter(([_, value]) => value !== undefined && value !== null)
.filter(([, value]) => value !== undefined && value !== null)
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
Expand Down Expand Up @@ -132,7 +131,7 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio
...additionalHeaders,
...options.headers,
})
.filter(([_, value]) => value !== undefined && value !== null)
.filter(([, value]) => value !== undefined && value !== null)
.reduce(
(headers, [key, value]) => ({
...headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const isBlob = (value: any): value is Blob => {
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
// @ts-ignore
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
};
Expand All @@ -36,7 +35,7 @@ export const base64 = (str: string): string => {
try {
return btoa(str);
} catch (err) {
// @ts-ignore
// @ts-expect-error Buffer may not be found.
return Buffer.from(str).toString('base64');
}
};
Expand Down Expand Up @@ -87,7 +86,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
if (options.formData) {
const formData = new FormData();

const process = (key: string, value: any) => {
const process = (key: string, value: unknown) => {
if (isString(value) || isBlob(value)) {
formData.append(key, value);
} else {
Expand All @@ -96,7 +95,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
};

Object.entries(options.formData)
.filter(([_, value]) => value !== undefined && value !== null)
.filter(([, value]) => value !== undefined && value !== null)
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
Expand Down Expand Up @@ -132,7 +131,7 @@ export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptio
...additionalHeaders,
...options.headers,
})
.filter(([_, value]) => value !== undefined && value !== null)
.filter(([, value]) => value !== undefined && value !== null)
.reduce(
(headers, [key, value]) => ({
...headers,
Expand Down
9 changes: 4 additions & 5 deletions test/__snapshots__/v3/test/generated/v3/core/request.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const isBlob = (value: any): value is Blob => {
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
// @ts-ignore
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
};
Expand All @@ -36,7 +35,7 @@ export const base64 = (str: string): string => {
try {
return btoa(str);
} catch (err) {
// @ts-ignore
// @ts-expect-error Buffer may not be found.
return Buffer.from(str).toString('base64');
}
};
Expand Down Expand Up @@ -87,7 +86,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
if (options.formData) {
const formData = new FormData();

const process = (key: string, value: any) => {
const process = (key: string, value: unknown) => {
if (isString(value) || isBlob(value)) {
formData.append(key, value);
} else {
Expand All @@ -96,7 +95,7 @@ export const getFormData = (options: ApiRequestOptions): FormData | undefined =>
};

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

0 comments on commit 33028b7

Please sign in to comment.