Skip to content

Commit 4fac0aa

Browse files
nilshartmannastahmer
authored andcommitted
Add missing infer in zod-based ApiClient methods
1 parent d445858 commit 4fac0aa

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

.changeset/sharp-pillows-rule.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"typed-openapi": patch
3+
---
4+
5+
Fix typecast in zod-based ApiClient methods

packages/typed-openapi/src/generator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export class ApiClient {
294294
.with("arktype", "io-ts", "typebox", "valibot", () => infer(`TEndpoint`) + `["response"]`)
295295
.otherwise(() => `TEndpoint["response"]`)}> {
296296
return this.fetcher("${method}", this.baseUrl + path, params[0])${match(ctx.runtime)
297-
.with("zod", () => `as Promise<TEndpoint["response"]> `).otherwise(() => ``)};
297+
.with("zod", () => `as Promise<${infer(`TEndpoint["response"]`)}>`).otherwise(() => ``)};
298298
}
299299
// </ApiClient.${method}>
300300
`

packages/typed-openapi/tests/snapshots/docker.openapi.zod.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3461,7 +3461,7 @@ export class ApiClient {
34613461
path: Path,
34623462
...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>
34633463
): Promise<z.infer<TEndpoint["response"]>> {
3464-
return this.fetcher("get", this.baseUrl + path, params[0]) as Promise<TEndpoint["response"]>;
3464+
return this.fetcher("get", this.baseUrl + path, params[0]) as Promise<z.infer<TEndpoint["response"]>>;
34653465
}
34663466
// </ApiClient.get>
34673467

@@ -3470,7 +3470,7 @@ export class ApiClient {
34703470
path: Path,
34713471
...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>
34723472
): Promise<z.infer<TEndpoint["response"]>> {
3473-
return this.fetcher("post", this.baseUrl + path, params[0]) as Promise<TEndpoint["response"]>;
3473+
return this.fetcher("post", this.baseUrl + path, params[0]) as Promise<z.infer<TEndpoint["response"]>>;
34743474
}
34753475
// </ApiClient.post>
34763476

@@ -3479,7 +3479,7 @@ export class ApiClient {
34793479
path: Path,
34803480
...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>
34813481
): Promise<z.infer<TEndpoint["response"]>> {
3482-
return this.fetcher("delete", this.baseUrl + path, params[0]) as Promise<TEndpoint["response"]>;
3482+
return this.fetcher("delete", this.baseUrl + path, params[0]) as Promise<z.infer<TEndpoint["response"]>>;
34833483
}
34843484
// </ApiClient.delete>
34853485

@@ -3488,7 +3488,7 @@ export class ApiClient {
34883488
path: Path,
34893489
...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>
34903490
): Promise<z.infer<TEndpoint["response"]>> {
3491-
return this.fetcher("put", this.baseUrl + path, params[0]) as Promise<TEndpoint["response"]>;
3491+
return this.fetcher("put", this.baseUrl + path, params[0]) as Promise<z.infer<TEndpoint["response"]>>;
34923492
}
34933493
// </ApiClient.put>
34943494

@@ -3497,7 +3497,7 @@ export class ApiClient {
34973497
path: Path,
34983498
...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>
34993499
): Promise<z.infer<TEndpoint["response"]>> {
3500-
return this.fetcher("head", this.baseUrl + path, params[0]) as Promise<TEndpoint["response"]>;
3500+
return this.fetcher("head", this.baseUrl + path, params[0]) as Promise<z.infer<TEndpoint["response"]>>;
35013501
}
35023502
// </ApiClient.head>
35033503
}

packages/typed-openapi/tests/snapshots/petstore.zod.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ export class ApiClient {
389389
path: Path,
390390
...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>
391391
): Promise<z.infer<TEndpoint["response"]>> {
392-
return this.fetcher("put", this.baseUrl + path, params[0]) as Promise<TEndpoint["response"]>;
392+
return this.fetcher("put", this.baseUrl + path, params[0]) as Promise<z.infer<TEndpoint["response"]>>;
393393
}
394394
// </ApiClient.put>
395395

@@ -398,7 +398,7 @@ export class ApiClient {
398398
path: Path,
399399
...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>
400400
): Promise<z.infer<TEndpoint["response"]>> {
401-
return this.fetcher("post", this.baseUrl + path, params[0]) as Promise<TEndpoint["response"]>;
401+
return this.fetcher("post", this.baseUrl + path, params[0]) as Promise<z.infer<TEndpoint["response"]>>;
402402
}
403403
// </ApiClient.post>
404404

@@ -407,7 +407,7 @@ export class ApiClient {
407407
path: Path,
408408
...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>
409409
): Promise<z.infer<TEndpoint["response"]>> {
410-
return this.fetcher("get", this.baseUrl + path, params[0]) as Promise<TEndpoint["response"]>;
410+
return this.fetcher("get", this.baseUrl + path, params[0]) as Promise<z.infer<TEndpoint["response"]>>;
411411
}
412412
// </ApiClient.get>
413413

@@ -416,7 +416,7 @@ export class ApiClient {
416416
path: Path,
417417
...params: MaybeOptionalArg<z.infer<TEndpoint["parameters"]>>
418418
): Promise<z.infer<TEndpoint["response"]>> {
419-
return this.fetcher("delete", this.baseUrl + path, params[0]) as Promise<TEndpoint["response"]>;
419+
return this.fetcher("delete", this.baseUrl + path, params[0]) as Promise<z.infer<TEndpoint["response"]>>;
420420
}
421421
// </ApiClient.delete>
422422
}

0 commit comments

Comments
 (0)