@@ -22,10 +22,19 @@ import { paramPlaceholder, useParamStore } from "src/queries/useParamStore";
2222
2323import type { FlexibleFormElementProps } from "." ;
2424
25+ const matchesSchemaType = ( parsed : unknown , types : Array < string | undefined > ) : boolean => {
26+ const valueType = Array . isArray ( parsed ) ? "array" : parsed === null ? "null" : typeof parsed ;
27+
28+ // "integer" is a JSON Schema distinction; both map to JS "number"
29+ return types . some ( ( type ) => type === valueType || ( type === "integer" && valueType === "number" ) ) ;
30+ } ;
31+
2532export const FieldMultiType = ( { name, namespace = "default" , onUpdate } : FlexibleFormElementProps ) => {
2633 const { disabled, paramsDict, setParamsDict } = useParamStore ( namespace ) ;
2734 const param = paramsDict [ name ] ?? paramPlaceholder ;
2835
36+ const schemaTypes = Array . isArray ( param . schema . type ) ? param . schema . type : [ param . schema . type ] ;
37+
2938 // Display objects as pretty-printed JSON, plain strings as-is.
3039 const displayValue =
3140 param . value !== null && typeof param . value === "object"
@@ -39,7 +48,11 @@ export const FieldMultiType = ({ name, namespace = "default", onUpdate }: Flexib
3948 paramsDict [ name ] . value = null ;
4049 } else {
4150 try {
42- paramsDict [ name ] . value = JSON . parse ( value ) as JSON ;
51+ const parsed = JSON . parse ( value ) as JSON ;
52+
53+ // Only store the parsed value if its type is valid per the schema;
54+ // otherwise fall back to the raw string (e.g. "45" stays a string for type=["string","object"]).
55+ paramsDict [ name ] . value = matchesSchemaType ( parsed , schemaTypes ) ? parsed : value ;
4356 } catch {
4457 paramsDict [ name ] . value = value ;
4558 }
0 commit comments