Skip to content

Commit e524e20

Browse files
committed
feat: 支持运行时从zodValidator中提取schema
1 parent abefea6 commit e524e20

14 files changed

+717
-443
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@
7777
"@types/koa-static": "^4.0.4",
7878
"deepmerge": "^4.3.1",
7979
"koa-static": "^5.0.0",
80+
"micromatch": "^4.0.8",
8081
"mime-types": "^3.0.1",
81-
"minimatch": "^10.0.3",
8282
"radashi": "^12.6.0",
8383
"supertest": "^7.1.1",
8484
"swagger-ui-dist": "^5.25.3",
@@ -90,6 +90,7 @@
9090
"devDependencies": {
9191
"@biomejs/biome": "^2.0.6",
9292
"@oxc-node/core": "^0.0.29",
93+
"@types/micromatch": "^4.0.9",
9394
"@types/mime-types": "^3.0.1",
9495
"@types/node": "^24.0.7",
9596
"@types/supertest": "^6.0.3",

pnpm-lock.yaml

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

src/analyzers/ExpressFrameworkAnalyzer.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { UpdateUserDto, UserIdDto } from "@tests/fixtures/schema";
12
import { createParseContext, createProject } from "@tests/utils";
23
import type { Node } from "ts-morph";
34
import { SyntaxKind } from "typescript";
45
import { beforeEach, describe, expect, it } from "vitest";
6+
import { z } from "zod/v4";
57
import { CodeAnalyzer } from "@/analyzers/CodeAnalyzer";
8+
import { SchemaRegistry } from "@/registry/SchemaRegistry";
69
import type { OperationData, ParseContext } from "@/types/parser";
710
import { ExpressFrameworkAnalyzer } from "./ExpressFrameworkAnalyzer";
811

@@ -19,6 +22,7 @@ class CustomTestAnalyzer extends CodeAnalyzer {
1922
describe("ExpressFrameworkAnalyzer", () => {
2023
let analyzer: ExpressFrameworkAnalyzer;
2124
let context: ParseContext;
25+
const registry = SchemaRegistry.getInstance();
2226

2327
beforeEach(() => {
2428
context = createParseContext();
@@ -191,6 +195,9 @@ describe("ExpressFrameworkAnalyzer", () => {
191195
const node = sourceFile
192196
.getFirstChildOrThrow()
193197
.getLastChildByKindOrThrow(SyntaxKind.ExpressionStatement);
198+
const location = `${sourceFile.getFilePath()}:${node.getStartLineNumber()}`;
199+
registry.register(location, { params: UserIdDto, body: UpdateUserDto });
200+
194201
const analyzer = new ExpressFrameworkAnalyzer(context);
195202
const result = await analyzer.analyze(node);
196203

@@ -217,6 +224,7 @@ describe("ExpressFrameworkAnalyzer", () => {
217224
},
218225
},
219226
});
227+
expect(context.schemas.get("UpdateUserDto")).toEqual(z.toJSONSchema(UpdateUserDto));
220228
});
221229

222230
it("应该能够使用自定义 Express 代码分析器", async () => {

0 commit comments

Comments
 (0)