Skip to content

Commit 47997ea

Browse files
tests: added a new valibot test for examples
1 parent cb1e12c commit 47997ea

File tree

4 files changed

+93
-30
lines changed

4 files changed

+93
-30
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"devDependencies": {
6767
"@biomejs/biome": "^2.0.6",
6868
"@standard-schema/spec": "^1.0.0",
69-
"@valibot/to-json-schema": "^1.3.0",
69+
"@valibot/to-json-schema": "^1.5.0",
7070
"arktype": "^2.1.22",
7171
"effect": "^3.17.13",
7272
"husky": "^9.1.7",
@@ -77,7 +77,7 @@
7777
"typebox": "^1.0.17",
7878
"typescript": "^5.8.3",
7979
"sury": "^10.0.0",
80-
"valibot": "^1.1.0",
80+
"valibot": "^1.2.0",
8181
"vitest": "^3.2.4",
8282
"zod": "^3.23.8",
8383
"zod-openapi": "^4"

pnpm-lock.yaml

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__tests__/__snapshots__/valibot.test.ts.snap

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,42 @@ exports[`valibot > basic 1`] = `
6262
}
6363
`;
6464

65+
exports[`valibot > with examples 1`] = `
66+
{
67+
"components": {},
68+
"info": {
69+
"description": "Development documentation",
70+
"title": "Hono Documentation",
71+
"version": "0.0.0",
72+
},
73+
"openapi": "3.1.0",
74+
"paths": {
75+
"/": {
76+
"get": {
77+
"operationId": "getIndex",
78+
"responses": {
79+
"200": {
80+
"content": {
81+
"application/json": {
82+
"schema": {
83+
"examples": [
84+
"hello world",
85+
"example text",
86+
],
87+
"type": "string",
88+
},
89+
},
90+
},
91+
"description": "Success",
92+
},
93+
},
94+
},
95+
},
96+
},
97+
"tags": undefined,
98+
}
99+
`;
100+
65101
exports[`valibot > with metadata 1`] = `
66102
{
67103
"components": {

src/__tests__/valibot.test.ts

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("valibot", () => {
2020
schema: resolver(
2121
v.object({
2222
message: v.string(),
23-
}),
23+
})
2424
),
2525
},
2626
},
@@ -30,7 +30,7 @@ describe("valibot", () => {
3030
validator("json", v.object({ message: v.string() })),
3131
async (c) => {
3232
return c.json({ message: "Hello, world!" });
33-
},
33+
}
3434
);
3535

3636
const specs = await generateSpecs(app);
@@ -55,8 +55,8 @@ describe("valibot", () => {
5555
v.object({
5656
message: v.string(),
5757
}),
58-
v.metadata({ ref: "SuccessResponse" }),
59-
),
58+
v.metadata({ ref: "SuccessResponse" })
59+
)
6060
),
6161
},
6262
},
@@ -66,7 +66,7 @@ describe("valibot", () => {
6666
validator("json", v.object({ message: v.string() })),
6767
async (c) => {
6868
return c.json({ message: "Hello, world!" });
69-
},
69+
}
7070
);
7171

7272
const specs = await generateSpecs(app);
@@ -98,22 +98,49 @@ describe("valibot", () => {
9898
names: v.pipe(
9999
v.string(),
100100
v.transform((val) => val.split("|")),
101-
v.array(v.string()),
101+
v.array(v.string())
102102
),
103103
}),
104104
undefined,
105105
{
106106
options: { typeMode: "output" },
107-
},
107+
}
108108
),
109109
(c) => {
110110
const { names } = c.req.valid("query");
111111
return c.json({ message: `Hello ${names.join(", ")}!` });
112-
},
112+
}
113113
);
114114

115115
const specs = await generateSpecs(app);
116116

117117
expect(specs).toMatchSnapshot();
118118
});
119+
120+
it("with examples", async () => {
121+
const app = new Hono().get(
122+
"/",
123+
describeRoute({
124+
responses: {
125+
200: {
126+
description: "Success",
127+
content: {
128+
"application/json": {
129+
schema: resolver(
130+
v.pipe(
131+
v.string(),
132+
v.examples(["hello world", "example text"])
133+
)
134+
),
135+
},
136+
},
137+
},
138+
},
139+
}),
140+
(c) => c.json("hello")
141+
);
142+
143+
const specs = await generateSpecs(app);
144+
expect(specs).toMatchSnapshot();
145+
});
119146
});

0 commit comments

Comments
 (0)