From af1a3ba570a9a2645abe4d1907c562a9e0f9019c Mon Sep 17 00:00:00 2001 From: Sylvain Utard Date: Wed, 19 Mar 2025 11:50:25 +0100 Subject: [PATCH] Add enum support This adds support for [enum](https://json-schema.org/understanding-json-schema/reference/enum) on `string` property. --- client/src/components/DynamicJsonForm.tsx | 1 + client/src/components/StringInput.tsx | 51 +++++++++++++++++++++++ client/src/components/ToolsTab.tsx | 26 ++++++------ 3 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 client/src/components/StringInput.tsx diff --git a/client/src/components/DynamicJsonForm.tsx b/client/src/components/DynamicJsonForm.tsx index a15b57ec5..99a25fc5b 100644 --- a/client/src/components/DynamicJsonForm.tsx +++ b/client/src/components/DynamicJsonForm.tsx @@ -17,6 +17,7 @@ export type JsonSchemaType = { description?: string; properties?: Record; items?: JsonSchemaType; + enum?: string[]; }; type JsonObject = { [key: string]: JsonValue }; diff --git a/client/src/components/StringInput.tsx b/client/src/components/StringInput.tsx new file mode 100644 index 000000000..7ab87553e --- /dev/null +++ b/client/src/components/StringInput.tsx @@ -0,0 +1,51 @@ +import { Textarea } from "@/components/ui/textarea"; +import { JsonSchemaType } from "./DynamicJsonForm"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "./ui/select"; + +interface Props { + id: string; + name: string; + property: JsonSchemaType; + value: string; + onChange: (value: string) => void; +} + +export const StringInput = ({ id, name, property, value, onChange }: Props) => { + if (property.enum?.length) { + return ( + + ); + } + + return ( +