Skip to content

Commit

Permalink
[Docs] Extract comfy workflow zod schema as json schema (#2206)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Jan 9, 2025
1 parent b86e3f7 commit 1d02cd3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ browser_tests/*/*-win32.png

dist.zip

/temp/
/temp/

# Generated JSON Schemas
/schemas/
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"locale": "lobe-i18n locale",
"collect-i18n": "playwright test --config=playwright.i18n.config.ts"
"collect-i18n": "playwright test --config=playwright.i18n.config.ts",
"json-schema": "tsx scripts/generate-json-schema.ts"
},
"devDependencies": {
"@babel/core": "^7.24.7",
Expand Down
35 changes: 35 additions & 0 deletions scripts/generate-json-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import fs from 'fs'
import path from 'path'
import { zodToJsonSchema } from 'zod-to-json-schema'

import { zComfyWorkflow, zComfyWorkflow1 } from '../src/types/comfyWorkflow'

// 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'
})

// 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)
)

console.log('JSON Schemas generated successfully!')
2 changes: 1 addition & 1 deletion src/types/comfyWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export const zComfyWorkflow = z
.passthrough()

/** Schema version 1 */
const zComfyWorkflow1 = z
export const zComfyWorkflow1 = z
.object({
version: z.literal(1),
config: zConfig.optional().nullable(),
Expand Down

0 comments on commit 1d02cd3

Please sign in to comment.