From cd89eb4c88074f57078ba7b415467d4d31309f85 Mon Sep 17 00:00:00 2001 From: Vishesh 'ironeagle' Bangotra Date: Sat, 13 Jun 2026 13:14:47 +0530 Subject: [PATCH] fix: add keys to ObjectField children and guard relation data in getFieldOptions --- .../components/fields/ObjectField.tsx | 34 +++++++++++-------- react-openapi/utils/options.ts | 2 +- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/react-openapi/components/fields/ObjectField.tsx b/react-openapi/components/fields/ObjectField.tsx index 19b7dc1..0d0789e 100644 --- a/react-openapi/components/fields/ObjectField.tsx +++ b/react-openapi/components/fields/ObjectField.tsx @@ -1,3 +1,4 @@ +import * as React from 'react'; import { Box, Typography } from '@mui/material'; import { FieldComponentProps } from '../../types/overrides'; @@ -15,21 +16,26 @@ export default function ObjectField({ name, field, value, onChange, disabled, ba {Object.entries(field.schema).map(([subKey, subField]) => - renderField({ - name: `${name}.${subKey}`, - field: subField, - value: value?.[subKey], - onChange: (newVal: any) => { - const updated = { ...(value || {}), [subKey]: newVal }; - onChange(updated); - }, - disabled, - baseUrl, - uploadFile, - uploading, - relationDataMap, - }) + React.cloneElement( + renderField({ + name: `${name}.${subKey}`, + field: subField, + value: value?.[subKey], + onChange: (newVal: any) => { + const updated = { ...(value || {}), [subKey]: newVal }; + onChange(updated); + }, + disabled, + baseUrl, + uploadFile, + uploading, + relationDataMap, + }) as React.ReactElement, + { key: subKey } + ) )} + + ); diff --git a/react-openapi/utils/options.ts b/react-openapi/utils/options.ts index a015486..2188492 100644 --- a/react-openapi/utils/options.ts +++ b/react-openapi/utils/options.ts @@ -16,7 +16,7 @@ export function getFieldOptions(field: ResourceField, relationData?: any[]): Sel } if (field.relation) { - const data = relationData ?? []; + const data = Array.isArray(relationData) ? relationData : []; const enumOption = field.enumOption; if (!enumOption) { throw new Error(