@@ -186,13 +186,25 @@ const SchemaInspector = ({
186186
187187 < FormField label = "Type" description = "JSON Schema type for this attribute" >
188188 < Select
189- selectedOption = { TYPE_OPTIONS . find ( ( opt ) => opt . value === selectedAttribute . type ) || null }
190- onChange = { ( { detail } ) => onUpdate ( { type : detail . selectedOption . value } ) }
189+ selectedOption = {
190+ TYPE_OPTIONS . find ( ( opt ) => opt . value === selectedAttribute . type ) ||
191+ // If no type but has $ref, assume it's an object reference
192+ ( selectedAttribute . $ref ? TYPE_OPTIONS . find ( ( opt ) => opt . value === 'object' ) : null ) ||
193+ null
194+ }
195+ onChange = { ( { detail } ) => {
196+ // When changing type, remove $ref if it exists (it's incompatible with inline type)
197+ const updates = { type : detail . selectedOption . value } ;
198+ if ( selectedAttribute . $ref ) {
199+ updates . $ref = undefined ;
200+ }
201+ onUpdate ( updates ) ;
202+ } }
191203 options = { TYPE_OPTIONS }
192204 />
193205 </ FormField >
194206
195- { selectedAttribute . type === 'object' && availableClasses && availableClasses . length > 0 && (
207+ { ( selectedAttribute . type === 'object' || selectedAttribute . $ref ) && availableClasses && availableClasses . length > 0 && (
196208 < >
197209 < FormField
198210 label = "Reference Existing Class (Optional)"
@@ -211,14 +223,23 @@ const SchemaInspector = ({
211223 onChange = { ( { detail } ) => {
212224 if ( detail . selectedOption . value ) {
213225 const updates = { ...selectedAttribute , $ref : detail . selectedOption . value } ;
226+ // Remove inline object properties as they conflict with $ref
214227 delete updates . properties ;
215228 delete updates . required ;
216229 delete updates . minProperties ;
217230 delete updates . maxProperties ;
218231 delete updates . additionalProperties ;
232+ // Note: Keep type as 'object' for UI purposes, but it won't be exported in the final schema
233+ if ( ! updates . type ) {
234+ updates . type = 'object' ;
235+ }
219236 onUpdate ( updates ) ;
220237 } else {
221238 const updates = { ...selectedAttribute , $ref : undefined } ;
239+ // Restore type to object when removing $ref
240+ if ( ! updates . type ) {
241+ updates . type = 'object' ;
242+ }
222243 onUpdate ( updates ) ;
223244 }
224245 } }
0 commit comments