Generate json schema for node def (#2862)

This commit is contained in:
Chenlei Hu
2025-03-04 17:40:26 -05:00
committed by GitHub
parent d0ce2d2597
commit 680268bb29
3 changed files with 29 additions and 4 deletions

View File

@@ -2,7 +2,12 @@ import fs from 'fs'
import path from 'path'
import { zodToJsonSchema } from 'zod-to-json-schema'
import { zComfyWorkflow, zComfyWorkflow1 } from '../src/types/comfyWorkflow'
import {
zComfyWorkflow,
zComfyWorkflow1
} from '../src/schemas/comfyWorkflowSchema'
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, {
@@ -15,6 +20,16 @@ const workflow1Schema = zodToJsonSchema(zComfyWorkflow1, {
$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)) {
@@ -32,4 +47,14 @@ fs.writeFileSync(
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.log('JSON Schemas generated successfully!')