Skip to content

Commit 4899b3c

Browse files
committed
Added validation for invalid JSON Schema in sandbox pages
1 parent da6e21c commit 4899b3c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/routes/sandbox/jsonschema/+page.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import JSchema from '$lib/components/v2/workflow/JSchema.svelte';
66
import { tick } from 'svelte';
77
import example from './example.json';
8+
import { SchemaValidator } from '$lib/common/jschema_validation';
89
910
let schema = undefined;
1011
let schemaData = {};
@@ -33,6 +34,11 @@
3334
schema = undefined;
3435
jsonSchemaError = 'Invalid JSON';
3536
}
37+
const validator = new SchemaValidator();
38+
if (!validator.loadSchema(schema)) {
39+
schema = undefined;
40+
jsonSchemaError = 'Invalid JSON Schema';
41+
}
3642
}
3743
3844
function handleDataStringChanged() {

src/routes/sandbox/version/+page.svelte

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
import { deepCopy } from '$lib/common/component_utilities';
33
import { displayStandardErrorAlert } from '$lib/common/errors';
4+
import { SchemaValidator } from '$lib/common/jschema_validation';
45
import { stripNullAndEmptyObjectsAndArrays } from '$lib/components/common/jschema/schema_management';
56
import JSchema from '$lib/components/v2/workflow/JSchema.svelte';
67
import VersionUpdateFixArgs from '$lib/components/v2/workflow/VersionUpdateFixArgs.svelte';
@@ -44,6 +45,11 @@
4445
oldSchema = undefined;
4546
oldJsonSchemaError = 'Invalid JSON';
4647
}
48+
const validator = new SchemaValidator();
49+
if (!validator.loadSchema(oldSchema)) {
50+
oldSchema = undefined;
51+
oldJsonSchemaError = 'Invalid JSON Schema';
52+
}
4753
}
4854
4955
function handleOldDataStringChanged() {
@@ -76,6 +82,11 @@
7682
newSchema = undefined;
7783
newJsonSchemaError = 'Invalid JSON';
7884
}
85+
const validator = new SchemaValidator();
86+
if (!validator.loadSchema(newSchema)) {
87+
newSchema = undefined;
88+
newJsonSchemaError = 'Invalid JSON Schema';
89+
}
7990
}
8091
8192
/** @type {import('$lib/components/common/StandardErrorAlert.svelte').default|undefined} */

0 commit comments

Comments
 (0)