Files
ComfyUI_frontend/scripts/generate-json-schema.ts
Glary-Bot 72ac6773a1 feat(validation): split topology validation from link repair into publishable nx package
Extract workflow zod schemas, link topology validator, and link repair
into a new `@comfyorg/workflow-validation` package under `packages/`.
The package has zero litegraph coupling — it operates on plain
serialised JSON shapes — so it can be consumed by Node.js CI scripts
and a future backend validator.

Behaviour changes:

- Replace the four `'Error. Expected node to match patched data.'`
  invariant throws in the link fixer with `LinkRepairAbortedError`,
  which carries a structured `TopologyError` describing the offending
  `[linkId, src, srcSlot, tgt, tgtSlot]`.
- Add a pure `validateLinkTopology(graph)` that walks the link table
  and reports out-of-bounds slots, missing nodes, and endpoint
  mismatches as a structured `TopologyError[]`. This catches the
  seedance-style breakage (links targeting slots that don't exist on
  the node) which the schema cannot detect.
- Surface topology errors via toast when `Comfy.Validation.Workflows`
  is enabled, instead of swallowing them with `console.error`.
  Unrepairable workflows raise an `error` toast with structured
  details and `useWorkflowValidation` returns `null` so the caller
  falls back to the original graph.

Migration is via tsconfig + vite path aliases mirroring the existing
`@/utils/formatUtil` precedent, so the 76 importers of
`workflowSchema` and the lone importer of `linkFixer` continue to
compile without changes.

Adds `release-npm-workflow-validation.yaml`, a `workflow_dispatch`
publisher mirroring the existing `release-npm-types` pattern, so a
follow-up PR on Comfy-Org/workflow_templates can pin the published
package for per-template topology CI.
2026-05-02 04:41:56 +00:00

58 lines
1.5 KiB
TypeScript

import fs from 'fs'
import path from 'path'
import { zodToJsonSchema } from 'zod-to-json-schema'
import { zComfyWorkflow, zComfyWorkflow1 } from '@comfyorg/workflow-validation'
import { zComfyNodeDef as zComfyNodeDefV2 } from '../src/schemas/nodeDef/nodeDefSchemaV2'
import { zComfyNodeDef as zComfyNodeDefV1 } from '../src/schemas/nodeDefSchema'
// Convert both workflow schemas to JSON Schema
const workflow04Schema = zodToJsonSchema(zComfyWorkflow, {
name: 'ComfyWorkflow0_4',
$refStrategy: 'none'
})
const workflow1Schema = zodToJsonSchema(zComfyWorkflow1, {
name: 'ComfyWorkflow1_0',
$refStrategy: 'none'
})
const nodeDefV1Schema = zodToJsonSchema(zComfyNodeDefV1, {
name: 'ComfyNodeDefV1',
$refStrategy: 'none'
})
const nodeDefV2Schema = zodToJsonSchema(zComfyNodeDefV2, {
name: 'ComfyNodeDefV2',
$refStrategy: 'none'
})
// Create output directory if it doesn't exist
const outputDir = './schemas'
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true })
}
// Write schemas to files
fs.writeFileSync(
path.join(outputDir, 'workflow-0_4.json'),
JSON.stringify(workflow04Schema, null, 2)
)
fs.writeFileSync(
path.join(outputDir, 'workflow-1_0.json'),
JSON.stringify(workflow1Schema, null, 2)
)
fs.writeFileSync(
path.join(outputDir, 'node-def-v1.json'),
JSON.stringify(nodeDefV1Schema, null, 2)
)
fs.writeFileSync(
path.join(outputDir, 'node-def-v2.json'),
JSON.stringify(nodeDefV2Schema, null, 2)
)
console.warn('JSON Schemas generated successfully!')