Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .changeset/weak-swans-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

**client**: fix: change serializer types from `any` to `unknown`
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const createClient = (config: Config = {}): Client => {
...options,
headers: mergeHeaders(_config.headers, options.headers),
httpClient: options.httpClient ?? _config.httpClient,
serializedBody: undefined,
serializedBody: undefined as string | undefined,
};

if (!opts.httpClient) {
Expand All @@ -79,7 +79,7 @@ export const createClient = (config: Config = {}): Client => {
}

if (opts.body !== undefined && opts.bodySerializer) {
opts.serializedBody = opts.bodySerializer(opts.body);
opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
}

// remove Content-Type header if body is empty to avoid sending invalid requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerialize

export type QuerySerializer = (query: Record<string, unknown>) => string;

export type BodySerializer = (body: any) => any;
export type BodySerializer = (body: unknown) => unknown;

type QuerySerializerOptionsObject = {
allowReserved?: boolean;
Expand Down Expand Up @@ -39,12 +39,10 @@ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value:
};

export const formDataBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
body: T,
): FormData => {
bodySerializer: (body: unknown): FormData => {
const data = new FormData();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand All @@ -60,15 +58,15 @@ export const formDataBodySerializer = {
};

export const jsonBodySerializer = {
bodySerializer: <T>(body: T): string =>
bodySerializer: (body: unknown): string =>
JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
};

export const urlSearchParamsBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): string => {
bodySerializer: (body: unknown): string => {
const data = new URLSearchParams();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi-ts-angular/src/client/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const createClient = (config: Config = {}): Client => {
...options,
headers: mergeHeaders(_config.headers, options.headers),
httpClient: options.httpClient ?? _config.httpClient,
serializedBody: undefined,
serializedBody: undefined as string | undefined,
};

if (!opts.httpClient) {
Expand All @@ -79,7 +79,7 @@ export const createClient = (config: Config = {}): Client => {
}

if (opts.body !== undefined && opts.bodySerializer) {
opts.serializedBody = opts.bodySerializer(opts.body);
opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
}

// remove Content-Type header if body is empty to avoid sending invalid requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerialize

export type QuerySerializer = (query: Record<string, unknown>) => string;

export type BodySerializer = (body: any) => any;
export type BodySerializer = (body: unknown) => unknown;

type QuerySerializerOptionsObject = {
allowReserved?: boolean;
Expand Down Expand Up @@ -39,12 +39,10 @@ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value:
};

export const formDataBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
body: T,
): FormData => {
bodySerializer: (body: unknown): FormData => {
const data = new FormData();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand All @@ -60,15 +58,15 @@ export const formDataBodySerializer = {
};

export const jsonBodySerializer = {
bodySerializer: <T>(body: T): string =>
bodySerializer: (body: unknown): string =>
JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
};

export const urlSearchParamsBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): string => {
bodySerializer: (body: unknown): string => {
const data = new URLSearchParams();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand Down
14 changes: 6 additions & 8 deletions examples/openapi-ts-axios/src/client/core/bodySerializer.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerialize

export type QuerySerializer = (query: Record<string, unknown>) => string;

export type BodySerializer = (body: any) => any;
export type BodySerializer = (body: unknown) => unknown;

type QuerySerializerOptionsObject = {
allowReserved?: boolean;
Expand Down Expand Up @@ -39,12 +39,10 @@ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value:
};

export const formDataBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
body: T,
): FormData => {
bodySerializer: (body: unknown): FormData => {
const data = new FormData();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand All @@ -60,15 +58,15 @@ export const formDataBodySerializer = {
};

export const jsonBodySerializer = {
bodySerializer: <T>(body: T): string =>
bodySerializer: (body: unknown): string =>
JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
};

export const urlSearchParamsBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): string => {
bodySerializer: (body: unknown): string => {
const data = new URLSearchParams();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi-ts-fastify/src/client/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const createClient = (config: Config = {}): Client => {
...options,
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
headers: mergeHeaders(_config.headers, options.headers),
serializedBody: undefined,
serializedBody: undefined as string | undefined,
};

if (opts.security) {
Expand All @@ -52,7 +52,7 @@ export const createClient = (config: Config = {}): Client => {
}

if (opts.body !== undefined && opts.bodySerializer) {
opts.serializedBody = opts.bodySerializer(opts.body);
opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
}

// remove Content-Type header if body is empty to avoid sending invalid requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerialize

export type QuerySerializer = (query: Record<string, unknown>) => string;

export type BodySerializer = (body: any) => any;
export type BodySerializer = (body: unknown) => unknown;

type QuerySerializerOptionsObject = {
allowReserved?: boolean;
Expand Down Expand Up @@ -39,12 +39,10 @@ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value:
};

export const formDataBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
body: T,
): FormData => {
bodySerializer: (body: unknown): FormData => {
const data = new FormData();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand All @@ -60,15 +58,15 @@ export const formDataBodySerializer = {
};

export const jsonBodySerializer = {
bodySerializer: <T>(body: T): string =>
bodySerializer: (body: unknown): string =>
JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
};

export const urlSearchParamsBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): string => {
bodySerializer: (body: unknown): string => {
const data = new URLSearchParams();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi-ts-fetch/src/client/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const createClient = (config: Config = {}): Client => {
...options,
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
headers: mergeHeaders(_config.headers, options.headers),
serializedBody: undefined,
serializedBody: undefined as string | undefined,
};

if (opts.security) {
Expand All @@ -52,7 +52,7 @@ export const createClient = (config: Config = {}): Client => {
}

if (opts.body !== undefined && opts.bodySerializer) {
opts.serializedBody = opts.bodySerializer(opts.body);
opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
}

// remove Content-Type header if body is empty to avoid sending invalid requests
Expand Down
14 changes: 6 additions & 8 deletions examples/openapi-ts-fetch/src/client/core/bodySerializer.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerialize

export type QuerySerializer = (query: Record<string, unknown>) => string;

export type BodySerializer = (body: any) => any;
export type BodySerializer = (body: unknown) => unknown;

type QuerySerializerOptionsObject = {
allowReserved?: boolean;
Expand Down Expand Up @@ -39,12 +39,10 @@ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value:
};

export const formDataBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
body: T,
): FormData => {
bodySerializer: (body: unknown): FormData => {
const data = new FormData();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand All @@ -60,15 +58,15 @@ export const formDataBodySerializer = {
};

export const jsonBodySerializer = {
bodySerializer: <T>(body: T): string =>
bodySerializer: (body: unknown): string =>
JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
};

export const urlSearchParamsBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): string => {
bodySerializer: (body: unknown): string => {
const data = new URLSearchParams();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi-ts-ky/src/client/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const createClient = (config: Config = {}): Client => {
...options,
headers: mergeHeaders(_config.headers, options.headers),
ky: options.ky ?? _config.ky ?? ky,
serializedBody: undefined,
serializedBody: undefined as string | undefined,
};

if (opts.security) {
Expand All @@ -57,7 +57,7 @@ export const createClient = (config: Config = {}): Client => {
}

if (opts.body !== undefined && opts.bodySerializer) {
opts.serializedBody = opts.bodySerializer(opts.body);
opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
}

if (opts.body === undefined || opts.serializedBody === '') {
Expand Down
14 changes: 6 additions & 8 deletions examples/openapi-ts-ky/src/client/core/bodySerializer.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerialize

export type QuerySerializer = (query: Record<string, unknown>) => string;

export type BodySerializer = (body: any) => any;
export type BodySerializer = (body: unknown) => unknown;

type QuerySerializerOptionsObject = {
allowReserved?: boolean;
Expand Down Expand Up @@ -39,12 +39,10 @@ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value:
};

export const formDataBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
body: T,
): FormData => {
bodySerializer: (body: unknown): FormData => {
const data = new FormData();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand All @@ -60,15 +58,15 @@ export const formDataBodySerializer = {
};

export const jsonBodySerializer = {
bodySerializer: <T>(body: T): string =>
bodySerializer: (body: unknown): string =>
JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
};

export const urlSearchParamsBodySerializer = {
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): string => {
bodySerializer: (body: unknown): string => {
const data = new URLSearchParams();

Object.entries(body).forEach(([key, value]) => {
Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
if (value === undefined || value === null) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi-ts-next/src/client/client/client.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const createClient = (config: Config = {}): Client => {
...options,
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
headers: mergeHeaders(_config.headers, options.headers),
serializedBody: undefined,
serializedBody: undefined as string | undefined,
};

if (opts.security) {
Expand All @@ -52,7 +52,7 @@ export const createClient = (config: Config = {}): Client => {
}

if (opts.body !== undefined && opts.bodySerializer) {
opts.serializedBody = opts.bodySerializer(opts.body);
opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
}

// remove Content-Type header if body is empty to avoid sending invalid requests
Expand Down
Loading
Loading