Skip to content

Commit a1d8373

Browse files
committed
insight playground - allow array items to be single item (#7373)
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 <!-- start pr-codex --> --- ## 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}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced form input flexibility to accept either a single item or an array of items for array-typed parameters. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 3dbf9e1 commit a1d8373

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

apps/playground-web/src/app/insight/[blueprint_slug]/blueprint-playground.client.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,13 @@ function openAPIV3ParamToZodFormSchema(
815815
}
816816

817817
if (itemSchema) {
818-
return isRequired
818+
const arraySchema = isRequired
819819
? z.array(itemSchema).min(1, { message: "Required" })
820-
: z.array(itemSchema).optional();
820+
: z.array(itemSchema);
821+
const arrayOrSingleItemSchema = z.union([arraySchema, itemSchema]);
822+
return isRequired
823+
? arrayOrSingleItemSchema
824+
: arrayOrSingleItemSchema.optional();
821825
}
822826
}
823827
break;

0 commit comments

Comments
 (0)