mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 10:59:53 +00:00
Generate json schema for node def (#2862)
This commit is contained in:
@@ -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!')
|
||||
|
||||
@@ -65,7 +65,7 @@ const zOutputSpec = z.object({
|
||||
})
|
||||
|
||||
// Main node definition schema
|
||||
const zNodeDef = z.object({
|
||||
export const zComfyNodeDef = z.object({
|
||||
inputs: z.record(zInputSpec),
|
||||
outputs: z.array(zOutputSpec),
|
||||
hidden: z.record(z.any()).optional(),
|
||||
@@ -90,7 +90,7 @@ export type CustomInputSpec = z.infer<typeof zCustomInputSpec>
|
||||
|
||||
export type InputSpec = z.infer<typeof zInputSpec>
|
||||
export type OutputSpec = z.infer<typeof zOutputSpec>
|
||||
export type ComfyNodeDef = z.infer<typeof zNodeDef>
|
||||
export type ComfyNodeDef = z.infer<typeof zComfyNodeDef>
|
||||
|
||||
export const isIntInputSpec = (
|
||||
inputSpec: InputSpec
|
||||
|
||||
@@ -203,7 +203,7 @@ const zComfyOutputTypesSpec = z.array(
|
||||
z.union([zComfyNodeDataType, zComfyComboOutput])
|
||||
)
|
||||
|
||||
const zComfyNodeDef = z.object({
|
||||
export const zComfyNodeDef = z.object({
|
||||
input: zComfyInputsSpec.optional(),
|
||||
output: zComfyOutputTypesSpec.optional(),
|
||||
output_is_list: z.array(z.boolean()).optional(),
|
||||
|
||||
Reference in New Issue
Block a user