Skip to content

Commit

Permalink
validation hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
DecDuck committed Mar 29, 2024
1 parent 84113f5 commit 8f71bb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pages/projects/[projectid]/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ const schemaValidation = computed(() =>
const importSchemaUrl = ref();
function importSchema() {
if (project.value.schemas.includes(importSchemaUrl.value)) {
importSchemaUrl.value = "";
return;
}
project.value.schemas.push(importSchemaUrl.value);
importSchemaUrl.value = "";
}
Expand Down
8 changes: 6 additions & 2 deletions scripts/utils/schemaValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ function isValid(schema: Partial<NotObjectSchema>): boolean {
if (!validSchemaTypes.includes(schema.type)) {
return false;
}
if (schema.type === 'array' && (schema.items === undefined || schema.items.type === undefined)) {
return false;
}
return true;
}

Expand All @@ -25,8 +28,9 @@ export function validateSchema(schema: Partial<ObjectSchema>, path?: string): [n

const entries = Object.entries(schema.properties);
entries.forEach((entry) => {
const newPath = path ? `${path}.${entry[0]}` : entry[0]
if (entry[1].type == 'object') {
const [s, m] = validateSchema(entry[1], path ? `${path}.${entry[0]}` : entry[0]);
const [s, m] = validateSchema(entry[1], newPath);
successful += s;
max += m;
return;
Expand All @@ -35,7 +39,7 @@ export function validateSchema(schema: Partial<ObjectSchema>, path?: string): [n
if (isValid(entry[1])) {
successful++;
} else {
console.log(`${path ?? '.'} is invalid`);
console.log(`${newPath} is invalid`);
}
})

Expand Down

0 comments on commit 8f71bb5

Please sign in to comment.