From a1d837344676fab585b49f0a36980949858bdaed Mon Sep 17 00:00:00 2001 From: iuwqyir Date: Wed, 18 Jun 2025 21:21:48 +0000 Subject: [PATCH] insight playground - allow array items to be single item (#7373) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes validation for query params that can be single or multiple value. E.g. `?contract_address=0x...&contract_address=0x..` and `?contract_address=0x..` are both valid queries. Doing just 1 value as in the second variant did not pass validation previously, but now does --- ## PR-Codex overview This PR modifies the schema validation logic in the `blueprint-playground.client.tsx` file to handle required and optional array or single item schemas more effectively. ### Detailed summary - Updated the return value to use `arrayOrSingleItemSchema` for both required and optional cases. - Introduced `arraySchema` to define the structure of required arrays. - Created `arrayOrSingleItemSchema` to combine array and single item schemas. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit - **New Features** - Enhanced form input flexibility to accept either a single item or an array of items for array-typed parameters. --- .../[blueprint_slug]/blueprint-playground.client.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/playground-web/src/app/insight/[blueprint_slug]/blueprint-playground.client.tsx b/apps/playground-web/src/app/insight/[blueprint_slug]/blueprint-playground.client.tsx index 67b82a353e4..7555eec0980 100644 --- a/apps/playground-web/src/app/insight/[blueprint_slug]/blueprint-playground.client.tsx +++ b/apps/playground-web/src/app/insight/[blueprint_slug]/blueprint-playground.client.tsx @@ -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(); } } break;