Skip to content

Commit f5b8fb8

Browse files
committed
Fix Object tags in Document Schema
1 parent 9dd89dc commit f5b8fb8

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

src/ui/src/components/configuration-layout/ConfigurationLayout.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,14 @@ const ConfigurationLayout = () => {
776776
const builtObject = buildObjectFromPaths(differences);
777777
console.log('DEBUG: Built object from paths:', builtObject);
778778

779-
// CRITICAL: If there are no differences, don't send update to backend
779+
// CRITICAL: Always include the current document schema (classes) if it exists
780+
// This prevents the schema from being lost when saving other configuration changes
781+
if (formValues.classes && Array.isArray(formValues.classes) && formValues.classes.length > 0) {
782+
builtObject.classes = formValues.classes;
783+
console.log('DEBUG: Including document schema (classes) in save:', formValues.classes);
784+
}
785+
786+
// CRITICAL: If there are no differences AND no schema, don't send update to backend
780787
// This prevents unnecessary API calls and potential data issues
781788
if (Object.keys(builtObject).length === 0) {
782789
console.log('No changes detected, skipping save');

src/ui/src/components/json-schema-builder/SchemaInspector.jsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}}

src/ui/src/components/json-schema-builder/utils/badgeHelpers.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ export const getTypeColor = (type) => {
2525
export const getTypeBadgeText = (attribute) => {
2626
if (!attribute) return null;
2727

28-
// Object with reference: show as "object[ClassName]"
29-
if (attribute.type === 'object' && attribute.$ref) {
28+
// Object with reference: show as "ClassName" (without object prefix)
29+
// Note: When an attribute has a $ref, it typically doesn't have a type field
30+
if (attribute.$ref) {
3031
const className = attribute.$ref.replace('#/$defs/', '');
31-
return { text: `object[${className}]`, color: getTypeColor('object'), className };
32+
return { text: `${className}`, color: getTypeColor('object'), className };
3233
}
3334

3435
// Array with reference: show as "array[ClassName]"

0 commit comments

Comments
 (0)