diff --git a/.changeset/fresh-actors-kiss.md b/.changeset/fresh-actors-kiss.md new file mode 100644 index 0000000..253bba0 --- /dev/null +++ b/.changeset/fresh-actors-kiss.md @@ -0,0 +1,5 @@ +--- +"typed-openapi": minor +--- + +zod-runtime: add typecast in ApiClient methods to match the desired type diff --git a/packages/typed-openapi/src/generator.ts b/packages/typed-openapi/src/generator.ts index b70ec8c..633eb35 100644 --- a/packages/typed-openapi/src/generator.ts +++ b/packages/typed-openapi/src/generator.ts @@ -293,7 +293,8 @@ export class ApiClient { .with("zod", "yup", () => infer(`TEndpoint["response"]`)) .with("arktype", "io-ts", "typebox", "valibot", () => infer(`TEndpoint`) + `["response"]`) .otherwise(() => `TEndpoint["response"]`)}> { - return this.fetcher("${method}", this.baseUrl + path, params[0]); + return this.fetcher("${method}", this.baseUrl + path, params[0])${match(ctx.runtime) + .with("zod", () => `as Promise `).otherwise(() => ``)}; } // ` diff --git a/packages/typed-openapi/tests/snapshots/docker.openapi.zod.ts b/packages/typed-openapi/tests/snapshots/docker.openapi.zod.ts index a44ab20..b109780 100644 --- a/packages/typed-openapi/tests/snapshots/docker.openapi.zod.ts +++ b/packages/typed-openapi/tests/snapshots/docker.openapi.zod.ts @@ -3461,7 +3461,7 @@ export class ApiClient { path: Path, ...params: MaybeOptionalArg> ): Promise> { - return this.fetcher("get", this.baseUrl + path, params[0]); + return this.fetcher("get", this.baseUrl + path, params[0]) as Promise; } // @@ -3470,7 +3470,7 @@ export class ApiClient { path: Path, ...params: MaybeOptionalArg> ): Promise> { - return this.fetcher("post", this.baseUrl + path, params[0]); + return this.fetcher("post", this.baseUrl + path, params[0]) as Promise; } // @@ -3479,7 +3479,7 @@ export class ApiClient { path: Path, ...params: MaybeOptionalArg> ): Promise> { - return this.fetcher("delete", this.baseUrl + path, params[0]); + return this.fetcher("delete", this.baseUrl + path, params[0]) as Promise; } // @@ -3488,7 +3488,7 @@ export class ApiClient { path: Path, ...params: MaybeOptionalArg> ): Promise> { - return this.fetcher("put", this.baseUrl + path, params[0]); + return this.fetcher("put", this.baseUrl + path, params[0]) as Promise; } // @@ -3497,7 +3497,7 @@ export class ApiClient { path: Path, ...params: MaybeOptionalArg> ): Promise> { - return this.fetcher("head", this.baseUrl + path, params[0]); + return this.fetcher("head", this.baseUrl + path, params[0]) as Promise; } // } diff --git a/packages/typed-openapi/tests/snapshots/petstore.zod.ts b/packages/typed-openapi/tests/snapshots/petstore.zod.ts index 3377d42..807e11d 100644 --- a/packages/typed-openapi/tests/snapshots/petstore.zod.ts +++ b/packages/typed-openapi/tests/snapshots/petstore.zod.ts @@ -389,7 +389,7 @@ export class ApiClient { path: Path, ...params: MaybeOptionalArg> ): Promise> { - return this.fetcher("put", this.baseUrl + path, params[0]); + return this.fetcher("put", this.baseUrl + path, params[0]) as Promise; } // @@ -398,7 +398,7 @@ export class ApiClient { path: Path, ...params: MaybeOptionalArg> ): Promise> { - return this.fetcher("post", this.baseUrl + path, params[0]); + return this.fetcher("post", this.baseUrl + path, params[0]) as Promise; } // @@ -407,7 +407,7 @@ export class ApiClient { path: Path, ...params: MaybeOptionalArg> ): Promise> { - return this.fetcher("get", this.baseUrl + path, params[0]); + return this.fetcher("get", this.baseUrl + path, params[0]) as Promise; } // @@ -416,7 +416,7 @@ export class ApiClient { path: Path, ...params: MaybeOptionalArg> ): Promise> { - return this.fetcher("delete", this.baseUrl + path, params[0]); + return this.fetcher("delete", this.baseUrl + path, params[0]) as Promise; } // }