Skip to content

Commit 709cacb

Browse files
ochafikclaude
andcommitted
feat: generate Zod schemas from TypeScript types using ts-to-zod library
This refactors the type generation approach to use the ts-to-zod library for converting TypeScript types to Zod schemas, replacing the previous manual schema generation. Key changes: - Add scripts/generate-schemas.ts using ts-to-zod as a library with: - Custom pre-processing to inject SDK-specific features (Base64 validation, description JSDoc tags, RELATED_TASK_META_KEY) - Post-processing transforms for strict() mode, discriminatedUnions, enums - AST-based schema post-processing with ts-morph for robust transformations - Generate src/generated/sdk.types.ts (pre-processed TypeScript types) - Generate src/generated/sdk.schemas.ts (Zod schemas with SDK conventions) - Refactor src/types.ts to re-export most schemas from generated code - Convert Request/Notification/Result from intersection to union types for better type narrowing in switch statements - Add union types: McpRequest, McpNotification, McpResult for type guards - Fix test files for union type compatibility and new schema structures - Add comprehensive schema comparison tests The generated schemas maintain full compatibility with the existing API while improving type safety and reducing manual maintenance burden. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 67d79d4 commit 709cacb

29 files changed

+9474
-3549
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
],
6969
"scripts": {
7070
"fetch:spec-types": "tsx scripts/fetch-spec-types.ts",
71+
"generate:schemas": "tsx scripts/generate-schemas.ts && prettier --write \"src/generated/**/*\"",
7172
"typecheck": "tsgo --noEmit",
7273
"build": "npm run build:esm && npm run build:cjs",
7374
"build:esm": "mkdir -p dist/esm && echo '{\"type\": \"module\"}' > dist/esm/package.json && tsc -p tsconfig.prod.json",
@@ -132,6 +133,8 @@
132133
"eslint-plugin-n": "^17.23.1",
133134
"prettier": "3.6.2",
134135
"supertest": "^7.0.0",
136+
"ts-morph": "^27.0.2",
137+
"ts-to-zod": "^5.1.0",
135138
"tsx": "^4.16.5",
136139
"typescript": "^5.5.4",
137140
"typescript-eslint": "^8.48.1",

0 commit comments

Comments
 (0)