Skip to content

add schema inference feature to trigger config#53

Closed
nmcgrady wants to merge 1 commit intomainfrom
nmcgrady/infer-schema
Closed

add schema inference feature to trigger config#53
nmcgrady wants to merge 1 commit intomainfrom
nmcgrady/infer-schema

Conversation

@nmcgrady
Copy link

This PR adds a feature for inferring a response schema based on a mock payload.

Just paste an example payload from your source and select "Infer Schema" and it will automatically add all the values.

@vercel
Copy link
Contributor

vercel bot commented Nov 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
workflow-builder Ready Ready Preview Comment Nov 27, 2025 7:20am

};

if (typeof arrayStructure.itemType === "string") {
field.itemType = arrayStructure.itemType as ValidItemType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
field.itemType = arrayStructure.itemType as ValidItemType;
// Nested arrays case: itemType is "array"
// Since SchemaField doesn't support itemType: "array",
// represent nested arrays as itemType: "object" with fields
if (arrayStructure.itemType === "array") {
field.itemType = "object";
field.fields = []; // Empty fields for array of arrays
} else {
// Ensure only valid item types are assigned
field.itemType = arrayStructure.itemType as ValidItemType;
}

The schema inference can produce invalid SchemaField objects with itemType: "array" when processing nested arrays, but SchemaField only allows itemType to be "string" | "number" | "boolean" | "object".

View Details

Analysis

Schema inference creates invalid SchemaField with itemType: "array" for nested arrays

What fails: inferSchemaFromJSON() in components/workflow/utils/json-parser.ts produces SchemaField objects with itemType: "array", which violates the type contract defined in schema-builder.tsx (line 20) where itemType only allows "string" | "number" | "boolean" | "object".

How to reproduce:

// Call inferSchemaFromJSON with nested arrays
const schema = inferSchemaFromJSON('{"data": [[1, 2], [3, 4]]}');

// Inspect the result
console.log(schema[0].itemType); // Outputs: "array" (INVALID)

What happens: The function assigns itemType: "array" (a string value) through an unsafe as ValidItemType cast on line 101, bypassing TypeScript's type safety. This causes the schema to violate its type contract, and downstream code like template-autocomplete.tsx (line 55) generates invalid type labels like "array[]" instead of valid types.

Expected behavior: For nested arrays, the schema should use valid itemType values. The fix represents nested arrays as itemType: "object" with empty fields, which maintains type safety while properly indicating that array items are complex structures.

Fix implemented: Added a check in createArrayField() to detect when arrayStructure.itemType === "array" and handle it by setting itemType: "object" with an empty fields array, ensuring all SchemaField objects comply with the type contract.

@nmcgrady nmcgrady marked this pull request as draft November 27, 2025 07:45
@nmcgrady nmcgrady closed this Dec 2, 2025
@nmcgrady
Copy link
Author

nmcgrady commented Dec 2, 2025

moved to a new PR from my personal account

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant