Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion schemas/output.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Output:
description: The output format, render range and type of media to generate.
description: >-
The output format, render range and type of media to generate.
For all formats except `mp3`, either `resolution` or `size` (with both `width` and `height`) must be specified.
properties:
format:
description: >-
Expand All @@ -24,6 +26,7 @@
resolution:
description: >-
The preset output resolution of the video or image. For custom sizes use the `size` property.
Either `resolution` or `size` (with both `width` and `height`) must be specified for all formats except `mp3`.
<ul>
<li>`preview` - 512px x 288px @ 15fps</li>
<li>`mobile` - 640px x 360px @ 25fps</li>
Expand Down
33 changes: 33 additions & 0 deletions scripts/fix-discriminator.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,40 @@ function addSrcOrPromptRefine(code, zPrefix) {
return code;
}

function addOutputDimensionsRefine(code, zPrefix) {
const schemaName = 'outputOutputSchema';
const idx = code.indexOf(schemaName + ' = ');
if (idx === -1) {
console.log("⚠ output dimensions refine: could not find " + schemaName + " (" + zPrefix + ")");
return code;
}
const strictMarker = '.strict()';
const strictIdx = code.indexOf(strictMarker, idx);
if (strictIdx === -1 || strictIdx - idx > 3000) {
console.log("⚠ output dimensions refine: no .strict() for " + schemaName + " (" + zPrefix + ")");
return code;
}
const superRefine = strictMarker + '.superRefine((val, ctx) => {\n' +
' var isMp3 = val.format === "mp3";\n' +
' if (!isMp3 && val.size != null && (val.size.width == null || val.size.height == null)) {\n' +
' ctx.addIssue({ code: ' + zPrefix + '.ZodIssueCode.custom, path: ["size"], message: "size requires both width and height" });\n' +
' return;\n' +
' }\n' +
' var hasResolution = typeof val.resolution === "string";\n' +
' var hasSize = val.size != null && val.size.width != null && val.size.height != null;\n' +
' if (!isMp3 && !hasResolution && !hasSize) {\n' +
' ctx.addIssue({ code: ' + zPrefix + '.ZodIssueCode.custom, message: \'output requires either "resolution" or "size" (with width and height)\' });\n' +
' }\n' +
'})';
code = code.substring(0, strictIdx) + superRefine + code.substring(strictIdx + strictMarker.length);
console.log("✓ Added output dimensions refine to " + schemaName + " (" + zPrefix + ")");
return code;
}

content = addStrictToObjects(content, "z");
content = addLegacyTextWrapMigrationError(content, "z");
content = addSrcOrPromptRefine(content, "z");
content = addOutputDimensionsRefine(content, "z");

fs.writeFileSync(zodGenPath, content);

Expand Down Expand Up @@ -622,6 +653,7 @@ const clipClipSchemaWithFitFilter = exports.clipClipSchema.transform((clip) => {
cjsContent = addStrictToObjects(cjsContent, "zod_1.z");
cjsContent = addLegacyTextWrapMigrationError(cjsContent, "zod_1.z");
cjsContent = addSrcOrPromptRefine(cjsContent, "zod_1.z");
cjsContent = addOutputDimensionsRefine(cjsContent, "zod_1.z");

fs.writeFileSync(zodGenCjsPath, cjsContent);
}
Expand Down Expand Up @@ -756,6 +788,7 @@ const clipClipSchemaWithFitFilter = clipClipSchema.transform((clip) => {
jsContent = addStrictToObjects(jsContent, "z");
jsContent = addLegacyTextWrapMigrationError(jsContent, "z");
jsContent = addSrcOrPromptRefine(jsContent, "z");
jsContent = addOutputDimensionsRefine(jsContent, "z");

fs.writeFileSync(zodGenJsPath, jsContent);
}
Expand Down
Loading