Should transforms on output schemas also be applied to examples? #694
Replies: 5 comments 3 replies
-
I'm not sure... I thought that something like that was already implemented in OpenApi helpers... I need to check why it doesn't work well in this case |
Beta Was this translation helpful? Give feedback.
-
Yeah, there is method |
Beta Was this translation helpful? Give feedback.
-
@shroudedcode , I don't see in your original message the way you specify the example. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the code sample, @shroudedcode . test("Discussion #694: should apply transformation to dateOut in case of output", () => {
const schema = withMeta(
z.object({
start_date: z
.dateOut()
.describe(
"The date this absence starts in the `yyyy-MM-dd` format."
)
.transform((str) => str.slice(0, "yyyy-MM-dd".length)),
})
).example({
start_date: new Date("2022-08-04"),
});
expect(getExamples(schema, true)).toEqual([{ start_date: "2022-08-04" }]); // passed
}); |
Beta Was this translation helpful? Give feedback.
-
@shroudedcode , I created a PR with a complete endpoint test: All tests passed. I'm not sure why you're experiencing the issue. Perhaps there is something else involved and requires more detailed investigation. Are you using the Please let me know. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We've got an output field like this on one of our endpoints:
We need to return this as a plain date because it has to be clear to API consumers that this field contains no time (or timezone) information whatsoever.
Because the "backing" data structure is sadly still a regular
Date
object, the example object also contains a regular date:When calling this endpoint the date is correctly returned in its "truncated" form:
The example object in our docs, however, still shows the full date string:
That's why I'm wondering: Should transforms on output schemas also be applied to examples? 🤔
Beta Was this translation helpful? Give feedback.
All reactions