Skip to content

Commit 9c79016

Browse files
ochafikclaude
andcommitted
feat: add schema export script for reviewer verification
- Add scripts/export-schemas-to-json.ts to export all Zod schemas as JSON Schema - Add npm run export:schemas command - Add missing TaskAugmentedRequestParamsSchema to re-exports Reviewers can verify schema compatibility: git checkout main && npm run export:schemas > main.json git checkout pr-branch && npm run export:schemas > pr.json diff main.json pr.json 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 9c477f8 commit 9c79016

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"scripts": {
7070
"fetch:spec-types": "tsx scripts/fetch-spec-types.ts",
7171
"generate:schemas": "tsx scripts/generate-schemas.ts && prettier --write \"src/generated/**/*\"",
72+
"export:schemas": "npm run build && tsx scripts/export-schemas-to-json.ts",
7273
"typecheck": "tsgo --noEmit",
7374
"build": "npm run build:esm && npm run build:cjs",
7475
"build:esm": "mkdir -p dist/esm && echo '{\"type\": \"module\"}' > dist/esm/package.json && tsc -p tsconfig.prod.json",

scripts/export-schemas-to-json.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env npx tsx
2+
/**
3+
* Export all Zod schemas to JSON Schema format for comparison.
4+
*
5+
* This script is useful for verifying that schema changes don't break compatibility.
6+
*
7+
* Usage:
8+
* # On main branch
9+
* npx tsx scripts/export-schemas-to-json.ts > main-schemas.json
10+
*
11+
* # On PR branch
12+
* npx tsx scripts/export-schemas-to-json.ts > pr-schemas.json
13+
*
14+
* # Compare
15+
* diff main-schemas.json pr-schemas.json
16+
*/
17+
18+
import { toJSONSchema } from 'zod/v4-mini';
19+
import type { $ZodType } from 'zod/v4/core';
20+
import * as types from '../dist/esm/types.js';
21+
22+
// Get all exports that end with "Schema" and are Zod schemas
23+
const schemaExports: Record<string, unknown> = {};
24+
25+
for (const [name, value] of Object.entries(types)) {
26+
if (name.endsWith('Schema') && value && typeof value === 'object' && '_zod' in value) {
27+
try {
28+
// Convert to JSON Schema using Zod v4's built-in converter
29+
const jsonSchema = toJSONSchema(value as $ZodType, {
30+
target: 'draft-7',
31+
});
32+
schemaExports[name] = jsonSchema;
33+
} catch (e) {
34+
// Some schemas might not convert cleanly, note them
35+
schemaExports[name] = { error: `Failed to convert: ${e}` };
36+
}
37+
}
38+
}
39+
40+
// Sort by name for deterministic output
41+
const sortedSchemas: Record<string, unknown> = {};
42+
for (const name of Object.keys(schemaExports).sort()) {
43+
sortedSchemas[name] = schemaExports[name];
44+
}
45+
46+
// Output as pretty-printed JSON
47+
console.log(JSON.stringify(sortedSchemas, null, 2));

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export {
266266
RequestSchema,
267267
NotificationSchema,
268268
ResultSchema,
269+
TaskAugmentedRequestParamsSchema,
269270
PaginatedResultSchema,
270271
PaginatedRequestSchema,
271272
PingRequestSchema,

0 commit comments

Comments
 (0)