diff --git a/sites/main-site/src/components/schema/SchemaListingElement.svelte b/sites/main-site/src/components/schema/SchemaListingElement.svelte
index 7e4d4e26d0..7bf34bf8f1 100644
--- a/sites/main-site/src/components/schema/SchemaListingElement.svelte
+++ b/sites/main-site/src/components/schema/SchemaListingElement.svelte
@@ -26,14 +26,14 @@
class:collapse={property.hidden}
class:show={$showHidden}
>
-
+
diff --git a/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListing.svelte b/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListing.svelte
index c9e0f6fedb..171f975204 100644
--- a/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListing.svelte
+++ b/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListing.svelte
@@ -52,58 +52,85 @@
// Handle the error, maybe show an error message to the user
}
});
+ const removeGroup = (name) => {
+ let result = confirm('Are you sure you want to remove this group?');
+ if (!result) return;
+ delete schema?.definitions[name];
+ schema = { ...schema };
+ };
-
-
+
+
+
+ {
+ collapseGroups = !collapseGroups;
+ }}>Collapse Groups
+
{
- collapseGroups = !collapseGroups;
- }}>Collapse Groups Finish
-
-
{
- postSchema('web_builder_edited');
- }}>Finish
-
+
-
- {#if status === 'loading'}
-
Loading schema...
- {:else if status === 'loaded'}
-
- {#each Object.keys(schema[defName]) as key (key)}
-
- {/each}
-
+
+
+
+ {#if status === 'loading'}
+
Loading schema...
+ {:else if status === 'loaded'}
+
+ {#each Object.keys(schema[defName]) as key (key)}
+
+ removeGroup(key)}
+ >
+
+
+
+ {/each}
+
+
+ {:else if (status = 'saved')}
+
Schema saved! See terminal log for more details.
+ {/if}
+
- {:else if (status = 'saved')}
-
Schema saved! See terminal log for more details.
- {/if}
-
-
-
- nf-params.json
-
-
+
+
+ nf-params.json
+
+
{JSON.stringify(schema, null, 2)}
-
+
+
+
+
+
diff --git a/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListingElement.svelte b/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListingElement.svelte
index f6466bc181..1c8f142deb 100644
--- a/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListingElement.svelte
+++ b/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListingElement.svelte
@@ -9,99 +9,320 @@
$: schemaEntry = schema[name];
const updateSchema = (event, propName: string) => {
- schema[name][propName] = event.target.value;
+ let value = event.target.value;
+ if (propName === 'enum') {
+ value = value.split(',').map((item) => item.trim());
+ }
+ schema[name][propName] = value;
+ if (schemaEntry.pattern && (propName === 'default' || propName === 'enum')) {
+ checkPattern(propName);
+ }
+ if (
+ schemaEntry.multipleOf &&
+ (propName === 'default' || propName === 'minimum' || propName === 'maximum' || propName === 'multipleOf')
+ ) {
+ checkMultipleOf();
+ }
};
-
const schemaTypes = ['string', 'number', 'integer', 'boolean'];
+ let validation: {} = {};
+ const checkPattern = (key) => {
+ // check if default value and enum values match the pattern
+ if (schemaEntry.pattern) {
+ if (key === 'default' && schemaEntry.default) {
+ if (!schemaEntry.default.match(schemaEntry.pattern)) {
+ validation['default'] = false;
+ } else {
+ validation['default'] = true;
+ }
+ } else if (key === 'enum' && schemaEntry.enum) {
+ for (let i = 0; i < schemaEntry.enum.length; i++) {
+ if (!schemaEntry.enum[i].match(schemaEntry.pattern)) {
+ validation['enum'] = false;
+ break;
+ }
+ }
+ validation['enum'] = true;
+ }
+ }
+ };
+ const checkMultipleOf = () => {
+ if (schemaEntry.multipleOf) {
+ // check if default, minimum and maximum are multiples of multipleOf
+ if (schemaEntry.default) {
+ if (schemaEntry.default % schemaEntry.multipleOf !== 0) {
+ validation['default'] = false;
+ } else {
+ validation['default'] = true;
+ }
+ }
+ if (schemaEntry.minimum) {
+ if (schemaEntry.minimum % schemaEntry.multipleOf !== 0) {
+ validation['minimum'] = false;
+ } else {
+ validation['minimum'] = true;
+ }
+ }
+ if (schemaEntry.maximum) {
+ if (schemaEntry.maximum % schemaEntry.multipleOf !== 0) {
+ validation['maximum'] = false;
+ } else {
+ validation['maximum'] = true;
+ }
+ }
+ }
+ };
-
-
+
+
+
+
+
+
+
+
+
+
+
+ updateSchema(e, 'type')}
+ >
+ {#each schemaTypes as type}
+ {type}
+ {/each}
+
+ type
+
+
+
+
+ updateSchema(e, 'required')}
+ />
+ required
+
+
+
+ updateSchema(e, 'hidden')}
+ />
+ hidden
+
+
-
-
-
-
-
+
-
-
-
diff --git a/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListingGroup.svelte b/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListingGroup.svelte
index 09a7f84f2b..d6d3d9dc56 100644
--- a/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListingGroup.svelte
+++ b/sites/main-site/src/components/schema/schema-builder/SchemaBuilderListingGroup.svelte
@@ -9,6 +9,8 @@
showHidden.set(true);
$: group = schema.definitions[name];
+
+ let fieldAdded = false;
const updateSchemaKey = (e, oldKey) => {
// handle edge cases
const newKey = e.target.value;
@@ -28,29 +30,87 @@
}
schema.definitions[name].properties = newSchema;
};
+ const addField = () => {
+ let newName = 'new_field';
+ // check if field already exists and add number if it does (or add 1 to the number if also a number already exists)
+ let i = 1;
+ while (newName in schema.definitions[name].properties) {
+ if (i === 1) {
+ newName = `${newName}_${i}`;
+ } else {
+ newName = newName.replace(/_\d+$/, `_${i}`);
+ }
+ i++;
+ }
+
+ schema.definitions[name].properties = {
+ [newName]: {
+ type: 'string',
+ description: 'New Field',
+ },
+ ...schema.definitions[name].properties,
+ };
+ fieldAdded = true;
+ // reset fieldAdded after 1 second
+ setTimeout(() => {
+ fieldAdded = false;
+ }, 1000);
+ };
+
+ const removeField = (property) => {
+ let result = confirm('Are you sure you want to remove this field?');
+ if (!result) return;
+ delete schema.definitions[name].properties[property];
+ schema.definitions[name].properties = { ...schema.definitions[name].properties };
+ };
-
-
{name}
+
+
+
{name}
+
+
+ {#if fieldAdded}
+ Field Added
+ {:else}
+ Add Field
+ {/if}
+
+
{#if group.description}
{group.description}
{/if}
{#each Object.keys(group.properties) as key (key)}
-
-
-
diff --git a/sites/main-site/src/components/schema/schema-builder/SchemaBuilderToolbar.svelte b/sites/main-site/src/components/schema/schema-builder/SchemaBuilderToolbar.svelte
index 97867cc4a8..4be5149f66 100644
--- a/sites/main-site/src/components/schema/schema-builder/SchemaBuilderToolbar.svelte
+++ b/sites/main-site/src/components/schema/schema-builder/SchemaBuilderToolbar.svelte
@@ -1,27 +1,6 @@
-
- Add Field
- Add Group
-
-
diff --git a/sites/schema/src/pages/schema_builder.astro b/sites/schema/src/pages/schema_builder.astro
index 16e3769b53..a83fad158c 100644
--- a/sites/schema/src/pages/schema_builder.astro
+++ b/sites/schema/src/pages/schema_builder.astro
@@ -3,8 +3,15 @@ import PageLayout from '@layouts/PageLayout.astro';
import SchemaBuilderListing from '@components/schema/schema-builder/SchemaBuilderListing.svelte';
---
-
-
+
+
+
+