add schema inference feature to trigger config#53
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| }; | ||
|
|
||
| if (typeof arrayStructure.itemType === "string") { | ||
| field.itemType = arrayStructure.itemType as ValidItemType; |
There was a problem hiding this comment.
| 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.
|
moved to a new PR from my personal account |
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.