From 5253f327c546183ebc6acda48292cd0f8d8baa19 Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Fri, 2 Aug 2024 12:58:43 +0200 Subject: [PATCH] fix(frontend): Add support for array of objects in th UI (#4170) --- .../lib/components/ArrayTypeNarrowing.svelte | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/components/ArrayTypeNarrowing.svelte b/frontend/src/lib/components/ArrayTypeNarrowing.svelte index fe4bbc55b8..288a5be481 100644 --- a/frontend/src/lib/components/ArrayTypeNarrowing.svelte +++ b/frontend/src/lib/components/ArrayTypeNarrowing.svelte @@ -6,6 +6,8 @@ import ResourceTypePicker from './ResourceTypePicker.svelte' import Badge from './common/badge/Badge.svelte' import Alert from './common/alert/Alert.svelte' + import EditableSchemaDrawer from './schema/EditableSchemaDrawer.svelte' + import type { SchemaProperty } from '$lib/common' export let canEditResourceType: boolean = false export let itemsType: @@ -14,6 +16,7 @@ contentEncoding?: 'base64' enum?: string[] resourceType?: string + properties?: { [name: string]: SchemaProperty } } | undefined @@ -23,6 +26,20 @@ : Array.isArray(itemsType?.enum) ? 'enum' : 'string' + + let schema = { + properties: itemsType?.properties || {}, + order: Object.keys(itemsType?.properties || {}), + required: Object.values(itemsType?.properties || {}).map((p) => p.required) + } + + function updateItemsType() { + itemsType = { + ...itemsType, + properties: schema.properties, + type: 'object' + } + } {#if canEditResourceType} @@ -37,7 +54,7 @@ } else if (selected == 'number') { itemsType = { type: 'number' } } else if (selected == 'object') { - itemsType = { type: 'object' } + itemsType = { ...itemsType, type: 'object' } } else if (selected == 'bytes') { itemsType = { type: 'string', contentEncoding: 'base64' } } else if (selected == 'resource') { @@ -131,3 +148,12 @@ {/if} + +{#if selected === 'object'} + { + updateItemsType() + }} + /> +{/if}