Skip to content

Commit 5883276

Browse files
committed
fix: enhance JSON schema generation with unsupported type handling and remove zod-to-json-schema dependency
1 parent 0f5ab4d commit 5883276

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

packages/spec/scripts/build-schemas.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,20 @@ ensureDir(OUT_DIR);
9191
console.log(`Generating JSON Schemas to ${OUT_DIR}...`);
9292

9393
let count = 0;
94+
let skippedCount = 0;
9495
let errorCount = 0;
9596

97+
// Error messages for schema types that inherently cannot be represented in JSON Schema.
98+
// These are expected warnings, not build-breaking errors.
99+
const KNOWN_UNSUPPORTED_PATTERNS = [
100+
'cannot be represented in JSON Schema',
101+
];
102+
103+
function isKnownUnsupported(error: unknown): boolean {
104+
const msg = error instanceof Error ? error.message : String(error);
105+
return KNOWN_UNSUPPORTED_PATTERNS.some((p) => msg.includes(p));
106+
}
107+
96108
// Protocol now exports namespaces (Data, UI, System, AI, API)
97109
// We need to iterate through each namespace
98110
for (const [namespaceName, namespaceExports] of Object.entries(Protocol)) {
@@ -126,21 +138,33 @@ for (const [namespaceName, namespaceExports] of Object.entries(Protocol)) {
126138
const filePath = path.join(categoryDir, fileName);
127139

128140
writeFileWithRetry(filePath, JSON.stringify(jsonSchema, null, 2));
129-
console.log(`✓ ${namespaceName.toLowerCase()}/${fileName}`);
141+
console.log(` ${namespaceName.toLowerCase()}/${fileName}`);
130142
count++;
131143
} catch (error) {
132-
console.error(`Failed to generate schema for ${namespaceName}.${key}:`, error);
133-
errorCount++;
144+
if (isKnownUnsupported(error)) {
145+
// Functions, transforms, Date types etc. have no JSON Schema representation — skip gracefully
146+
const msg = error instanceof Error ? error.message : String(error);
147+
console.warn(` ⊘ ${namespaceName}.${key}: ${msg} (skipped)`);
148+
skippedCount++;
149+
} else {
150+
console.error(` ✗ Failed to generate schema for ${namespaceName}.${key}:`, error);
151+
errorCount++;
152+
}
134153
}
135154
}
136155
}
137156
}
138157
}
139158

159+
console.log(`\n─── Summary ───`);
160+
console.log(` Generated: ${count}`);
161+
if (skippedCount > 0) {
162+
console.log(` Skipped: ${skippedCount} (unsupported types: function, transform, date)`);
163+
}
164+
140165
if (errorCount > 0) {
141-
console.error(`\n❌ Completed with ${errorCount} error(s). ${count} schemas generated successfully.`);
142-
console.error(`\nNote: Partial schema generation occurred. Some schemas may be missing.`);
143-
console.error(`This typically indicates a Zod schema definition error or file system issue.`);
166+
console.error(` Errors: ${errorCount}`);
167+
console.error(`\n❌ Build failed with ${errorCount} unexpected error(s).`);
144168
process.exit(1);
145169
}
146170

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)