|
| 1 | +import { TOOL_ROUTES } from "@voltagent/server-core"; |
1 | 2 | import { cors } from "hono/cors"; |
2 | 3 | import { describe, expect, it } from "vitest"; |
| 4 | +import { z as zodV4 } from "zod/v4"; |
3 | 5 | import { createApp } from "./app-factory"; |
| 6 | +import { OpenApiGeneratorV31 } from "./vendor/zod-to-openapi/v4"; |
4 | 7 |
|
5 | 8 | const createDeps = () => |
6 | 9 | ({ |
@@ -270,6 +273,17 @@ describe("app-factory CORS configuration", () => { |
270 | 273 | expect(defaultRes.headers.get("access-control-allow-credentials")).toBe("true"); |
271 | 274 | }); |
272 | 275 |
|
| 276 | + it("should generate OpenAPI docs for built-in tool routes", async () => { |
| 277 | + const { app } = await createApp(createDeps(), {}); |
| 278 | + |
| 279 | + const res = await app.request("/doc"); |
| 280 | + const doc = await res.json(); |
| 281 | + |
| 282 | + expect(res.status).toBe(200); |
| 283 | + expect(doc.paths[TOOL_ROUTES.listTools.path].get).toBeDefined(); |
| 284 | + expect(doc.paths[TOOL_ROUTES.executeTool.path.replace(":name", "{name}")].post).toBeDefined(); |
| 285 | + }); |
| 286 | + |
273 | 287 | it("should keep custom routes public in opt-in mode (default)", async () => { |
274 | 288 | const mockAuthProvider = { |
275 | 289 | verifyToken: async (token: string) => { |
@@ -326,3 +340,41 @@ describe("app-factory CORS configuration", () => { |
326 | 340 | expect(executionOrder).toEqual(["auth-middleware", "custom-route"]); |
327 | 341 | }); |
328 | 342 | }); |
| 343 | + |
| 344 | +describe("Zod v4 OpenAPI compatibility", () => { |
| 345 | + it("should generate docs for record schemas with explicit key and value types", () => { |
| 346 | + const schema = zodV4.object({ |
| 347 | + parameters: zodV4.record(zodV4.string(), zodV4.any()).optional(), |
| 348 | + context: zodV4.record(zodV4.string(), zodV4.any()).optional().default({}), |
| 349 | + }); |
| 350 | + const route = { |
| 351 | + method: "post", |
| 352 | + path: "/tools/{name}/execute", |
| 353 | + request: { |
| 354 | + body: { |
| 355 | + content: { |
| 356 | + "application/json": { |
| 357 | + schema, |
| 358 | + }, |
| 359 | + }, |
| 360 | + }, |
| 361 | + }, |
| 362 | + responses: { |
| 363 | + 200: { |
| 364 | + description: "Successful response", |
| 365 | + }, |
| 366 | + }, |
| 367 | + }; |
| 368 | + |
| 369 | + const doc = new OpenApiGeneratorV31([{ type: "route", route }]).generateDocument({ |
| 370 | + openapi: "3.1.0", |
| 371 | + info: { title: "Zod v4 regression", version: "1.0.0" }, |
| 372 | + }); |
| 373 | + |
| 374 | + const requestSchema = |
| 375 | + doc.paths["/tools/{name}/execute"].post.requestBody.content["application/json"].schema; |
| 376 | + |
| 377 | + expect(requestSchema.properties.parameters.additionalProperties).toEqual({}); |
| 378 | + expect(requestSchema.properties.context.additionalProperties).toEqual({}); |
| 379 | + }); |
| 380 | +}); |
0 commit comments