Skip to content

Commit c05a765

Browse files
authored
Don't set contentType for zod void/undefined types (#578)
With this commit, it is possible to declare a serde.zod(z.void()) for no-args handlers.
1 parent 22c6738 commit c05a765

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

packages/restate-sdk-zod/src/serde_api.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@
1717

1818
import type { Serde } from "@restatedev/restate-sdk-core";
1919

20-
import type { z } from "zod";
20+
import { z, ZodVoid } from "zod";
2121
import { zodToJsonSchema } from "zod-to-json-schema";
2222

2323
export type { Serde } from "@restatedev/restate-sdk-core";
2424

2525
class ZodSerde<T extends z.ZodType> implements Serde<z.infer<T>> {
26-
contentType = "application/json";
26+
contentType? = "application/json";
2727
jsonSchema?: object | undefined;
2828

2929
constructor(private readonly schema: T) {
3030
this.jsonSchema = zodToJsonSchema(schema);
31+
if (schema instanceof ZodVoid || schema instanceof z.ZodUndefined) {
32+
this.contentType = undefined;
33+
}
3134
}
3235

3336
serialize(value: T): Uint8Array {

packages/restate-sdk/src/endpoint/components.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ function handlerInputDiscovery(handler: HandlerWrapper): d.InputPayload {
5050

5151
if (handler.inputSerde.jsonSchema) {
5252
jsonSchema = handler.inputSerde.jsonSchema;
53-
contentType =
54-
handler.accept ?? handler.inputSerde.contentType ?? "application/json";
53+
contentType = handler.accept ?? handler.inputSerde.contentType;
5554
} else if (handler.accept) {
5655
contentType = handler.accept;
5756
} else if (handler.inputSerde.contentType) {

packages/restate-sdk/src/types/rpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ export class HandlerWrapper {
455455
public readonly enableLazyState?: boolean,
456456
public readonly asTerminalError?: (error: any) => TerminalError | undefined
457457
) {
458-
this.accept = accept ? accept : inputSerde.contentType;
458+
this.accept = accept !== undefined ? accept : inputSerde.contentType;
459459
this.contentType = outputSerde.contentType;
460460
}
461461

0 commit comments

Comments
 (0)