Union as endpoint output #2964
-
|
I've been looking for a similar discussion but haven't found any. Sorry if there's some already. I need to return 304 response from an endpoint in case nothing changed, otherwise a regular object response. I can handle the logic in ResultHandler, but I'm not sure what to return from the endpoint as output. It forces object return value which is fine but it doesn't let me return e.g. empty object and non-empty object.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
|
@jakub-msqt , Consider either: factory.build({
output: z.object({
hasNoChanges: z.literal(true),
}).or(z.object(fields)),
});OR factory.build({
output: z.object(fields).partial(), // <— makes all props optional
});and then handle it accordingly in a Your
I'm not sure I get this. How exactly it does not let you? I didn't have any issues with your code sample.
|
Beta Was this translation helpful? Give feedback.


@jakub-msqt , Consider either:
OR
and then handle it accordingly in a
ResultHandler.First variant might be easier to handle thanx to explicit
hasNoChangesinoutput.Your
z.union()is also fine.I'm not sure I get this. How exactly it does not let you? I didn't have any issues with your code sample.