Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,13 @@ function openAPIV3ParamToZodFormSchema(
}

if (itemSchema) {
return isRequired
const arraySchema = isRequired
? z.array(itemSchema).min(1, { message: "Required" })
: z.array(itemSchema).optional();
: z.array(itemSchema);
const arrayOrSingleItemSchema = z.union([arraySchema, itemSchema]);
return isRequired
? arrayOrSingleItemSchema
: arrayOrSingleItemSchema.optional();
Comment on lines +818 to +824
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix validation inconsistency for required array parameters.

The union schema approach correctly solves the issue of accepting both single values and arrays. However, there's a validation inconsistency:

  • Required arrays validate with .min(1, { message: "Required" })
  • Required single items use the base itemSchema without additional validation
  • Other required parameter types in this function apply .min(1) validation (see lines 786-788, 795-797, 834-836)

This means a single empty string would pass validation while an empty array would fail.

Apply this fix to ensure consistent validation:

        if (itemSchema) {
+         let validatedItemSchema = itemSchema;
+         if (isRequired) {
+           if (schema.items.type === "string") {
+             validatedItemSchema = itemSchema.min(1, { message: "Required" });
+           } else if (schema.items.type === "number" || schema.items.type === "integer") {
+             validatedItemSchema = itemSchema.min(1, { message: "Required" });
+           }
+         }
+
          const arraySchema = isRequired
-           ? z.array(itemSchema).min(1, { message: "Required" })
-           : z.array(itemSchema);
-         const arrayOrSingleItemSchema = z.union([arraySchema, itemSchema]);
+           ? z.array(validatedItemSchema).min(1, { message: "Required" })
+           : z.array(itemSchema);
+         const arrayOrSingleItemSchema = z.union([arraySchema, validatedItemSchema]);
          return isRequired
            ? arrayOrSingleItemSchema
            : arrayOrSingleItemSchema.optional();
        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const arraySchema = isRequired
? z.array(itemSchema).min(1, { message: "Required" })
: z.array(itemSchema).optional();
: z.array(itemSchema);
const arrayOrSingleItemSchema = z.union([arraySchema, itemSchema]);
return isRequired
? arrayOrSingleItemSchema
: arrayOrSingleItemSchema.optional();
if (itemSchema) {
let validatedItemSchema = itemSchema;
if (isRequired) {
if (schema.items.type === "string") {
validatedItemSchema = itemSchema.min(1, { message: "Required" });
} else if (schema.items.type === "number" || schema.items.type === "integer") {
validatedItemSchema = itemSchema.min(1, { message: "Required" });
}
}
const arraySchema = isRequired
? z.array(validatedItemSchema).min(1, { message: "Required" })
: z.array(itemSchema);
const arrayOrSingleItemSchema = z.union([arraySchema, validatedItemSchema]);
return isRequired
? arrayOrSingleItemSchema
: arrayOrSingleItemSchema.optional();
}
🤖 Prompt for AI Agents
In
apps/playground-web/src/app/insight/[blueprint_slug]/blueprint-playground.client.tsx
around lines 818 to 824, the validation for required single items lacks a
minimum length check, causing inconsistency with required arrays that enforce a
minimum of one item. To fix this, apply a `.min(1, { message: "Required" })`
validation to the single item schema within the union when isRequired is true,
ensuring both single items and arrays enforce the same minimum presence
requirement.

}
}
break;
Expand Down
Loading