Skip to content

Commit 0a70924

Browse files
authored
feat: add proper support for JSON Schemas on workflows (#11)
1 parent 14ab0fd commit 0a70924

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ workflow
6060
} else if (options.data && options.file) {
6161
throw new Error('Please provide either -d or -f, not both')
6262
} else if (options.data) {
63-
data = options.data
63+
try {
64+
data = JSON.parse(options.data)
65+
} catch (error) {
66+
throw new Error(`Failed to parse provided JSON data: ${error instanceof Error ? error.message : 'Unknown error'}`)
67+
}
6468
} else if (options.file) {
6569
try {
6670
const fileContent = fs.readFileSync(options.file, 'utf-8')
@@ -70,12 +74,13 @@ workflow
7074
}
7175
}
7276

77+
if (!workflow.schema && workflow.isRequiredAdditionalData) {
78+
throw new Error('Workflow does not have a JSON schema. This is an API error')
79+
}
80+
7381
// If data is provided, validate against JSON Schema
74-
if (data) {
75-
const schema = workflow.schema
76-
if (!schema) {
77-
throw new Error('Workflow does not have a JSON schema')
78-
}
82+
if (data && workflow.schema) {
83+
const schema = JSON.parse(workflow.schema)
7984
const result = await validateData(data, schema)
8085
if (!result.success) {
8186
throw new Error(`Data validation failed: ${result.messages[0]}`)

0 commit comments

Comments
 (0)