From 2a4724d482eeba641307cd292606a46fb3297f06 Mon Sep 17 00:00:00 2001 From: hugocasa Date: Mon, 9 Nov 2026 17:11:24 +0100 Subject: [PATCH] fix: show resource properties missing from the resource type schema (#12265) * fix: show resource properties missing from the resource type schema The schema form only renders the type's properties, so a property removed from the resource type stayed in the stored value, invisible, and still reached scripts (a $var: in it fails the job once the variable is gone). The resource editor now lists such properties with an action to remove them, and the resource type editor warns when a save drops properties. Co-Authored-By: Claude Opus 5.5 * fix: render leftover resource properties as fields instead of an alert Each key the schema lacks gets its own untyped (JSON) field with a warning and a remove button, so its value can be read and edited in place. Co-Authored-By: Claude Opus 5.5 * fix: ignore validity of fields no longer in the schema form A field removed while invalid kept its false check, leaving the form invalid (and Save disabled) with nothing on screen to fix. Co-Authored-By: Claude Opus 5.5 * fix: flag leftover resource properties with a hover warning by the name The explanation moves from an always-visible description into a warning icon next to the field name (SchemaForm schemaFieldWarnings). The resource type editor's alert shrinks to one line without the property names. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- frontend/src/lib/components/ArgInput.svelte | 7 +- .../src/lib/components/ResourceForm.svelte | 68 ++++++++++++++++++- frontend/src/lib/components/SchemaForm.svelte | 11 ++- .../components/resources/ResourcesList.svelte | 13 ++++ 4 files changed, 92 insertions(+), 7 deletions(-) diff --git a/frontend/src/lib/components/ArgInput.svelte b/frontend/src/lib/components/ArgInput.svelte index ce64d7d231..bfc3c81cc0 100644 --- a/frontend/src/lib/components/ArgInput.svelte +++ b/frontend/src/lib/components/ArgInput.svelte @@ -12,7 +12,7 @@ getSchemaFromProperties, type DynamicInput as DynamicInputTypes } from '$lib/utils' - import { DollarSign, Plus, X, Check, Loader2, ExternalLink } from 'lucide-svelte' + import { DollarSign, Plus, X, Check, Loader2, ExternalLink, AlertTriangle } from 'lucide-svelte' import { createEventDispatcher, onDestroy, onMount, tick, untrack } from 'svelte' import { fade } from 'svelte/transition' import { Alert, Button, SecondsInput } from './common' @@ -93,6 +93,8 @@ disablePortal?: boolean showSchemaExplorer?: boolean simpleTooltip?: string | undefined + /** Show `simpleTooltip` behind a warning icon rather than an info icon. */ + simpleTooltipWarning?: boolean customErrorMessage?: string | undefined onlyMaskPassword?: boolean nullable?: boolean @@ -165,6 +167,7 @@ disablePortal = false, showSchemaExplorer = false, simpleTooltip = undefined, + simpleTooltipWarning = false, customErrorMessage = undefined, onlyMaskPassword = false, nullable = false, @@ -671,6 +674,8 @@ {contentEncoding} {format} {simpleTooltip} + SimpleTooltipIcon={simpleTooltipWarning ? AlertTriangle : undefined} + simpleTooltipIconClass={simpleTooltipWarning ? 'text-yellow-500' : undefined} {lightHeader} {displayType} labelClass={twMerge(lightHeaderFont ? '!font-normal text-primary' : '', css?.label?.class)} diff --git a/frontend/src/lib/components/ResourceForm.svelte b/frontend/src/lib/components/ResourceForm.svelte index c2404df0c0..78c71d00d9 100644 --- a/frontend/src/lib/components/ResourceForm.svelte +++ b/frontend/src/lib/components/ResourceForm.svelte @@ -5,7 +5,8 @@ import { onDestroy, untrack } from 'svelte' import { setEditorUnparseable } from './pendingEditorFlush' import { emptyString, isOwner, urlize } from '$lib/utils' - import { Alert, Skeleton } from './common' + import { Alert, Button, Skeleton } from './common' + import { Trash2 } from 'lucide-svelte' import Path from './Path.svelte' import LabelsInput from './LabelsInput.svelte' import { type UserExt } from '$lib/stores' @@ -123,6 +124,53 @@ if (showReference) isValid = true }) + // Keys the schema form cannot render (e.g. a property later removed from the resource type) + // still ship with the value, and a `$var:` among them fails the job once the variable is gone. + let orphanKeys = $derived.by(() => { + const props = resourceSchema?.properties + if ( + !props || + showReference || + rawMode || + loadingSchema || + resourceTypeInfo?.is_fileset || + resourceTypeInfo?.format_extension || + !args || + typeof args !== 'object' || + Array.isArray(args) + ) { + return [] + } + return Object.keys(args).filter((k) => !(k in props)) + }) + + // Rendered untyped, which the form shows as a JSON input, so any stored value fits. + let formSchema = $derived( + orphanKeys.length > 0 && resourceSchema + ? { + ...resourceSchema, + properties: { + ...resourceSchema.properties, + ...Object.fromEntries(orphanKeys.map((k) => [k, {}])) + } + } + : resourceSchema + ) + + let orphanWarnings = $derived( + Object.fromEntries( + orphanKeys.map((k) => [ + k, + 'Not in the resource type schema, but still passed to scripts using this resource. Remove it if it is no longer used.' + ]) + ) + ) + + function removeOrphanKey(key: string) { + const { [key]: _, ...rest } = args + args = rest + } + // This field is a bare SimpleEditor parsed here, so it never passes through JsonEditor — // it has to register itself, or a caller persisting what is on screen would save the // last value that parsed and leave without the text in front of the user. @@ -357,11 +405,25 @@ noDelete disabled={!can_write} compact - schema={resourceSchema} + schema={formSchema} bind:args bind:isValid + schemaFieldWarnings={orphanWarnings} {workspace} - /> + > + {#snippet actions({ item })} + {#if can_write && orphanKeys.includes(item.value)} +