Skip to content

Commit d835237

Browse files
authored
test: added example for transformation (#170)
1 parent a533810 commit d835237

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/__tests__/valibot.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,47 @@ describe("valibot", () => {
7373

7474
expect(specs).toMatchSnapshot();
7575
});
76+
77+
it("with transformation", async () => {
78+
const app = new Hono().get(
79+
"/",
80+
describeRoute({
81+
tags: ["test"],
82+
summary: "Test route",
83+
description: "This is a test route",
84+
responses: {
85+
200: {
86+
description: "Success",
87+
content: {
88+
"application/json": {
89+
schema: resolver(v.string()),
90+
},
91+
},
92+
},
93+
},
94+
}),
95+
validator(
96+
"query",
97+
v.object({
98+
names: v.pipe(
99+
v.string(),
100+
v.transform((val) => val.split("|")),
101+
v.array(v.string()),
102+
),
103+
}),
104+
undefined,
105+
{
106+
typeMode: "output",
107+
},
108+
),
109+
async (c) => {
110+
const { names } = await c.req.valid("query");
111+
return c.json({ message: `Hello ${names.join(", ")}!` });
112+
},
113+
);
114+
115+
const specs = await generateSpecs(app);
116+
117+
expect(specs).toMatchSnapshot();
118+
});
76119
});

0 commit comments

Comments
 (0)