From d0d5bd2ea0c3a63fd936acc5c97f9160ffb1a69b Mon Sep 17 00:00:00 2001 From: Rikki Schulte Date: Mon, 6 Nov 2023 23:30:56 +0100 Subject: [PATCH] fix the version --- package.json | 2 +- src/json-hover.ts | 3 --- src/json-validation.ts | 15 ++++++++------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 0248fba..cc46726 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@types/json-schema": "^7.0.12", "@types/node": "^20.4.2", "json-schema": "^0.4.0", - "json-schema-library": "^9.0.0" + "json-schema-library": "^9.1.2" }, "optionalDependencies": { "@codemirror/lang-json": "^6.0.1", diff --git a/src/json-hover.ts b/src/json-hover.ts index e52be49..e19230c 100644 --- a/src/json-hover.ts +++ b/src/json-hover.ts @@ -94,8 +94,6 @@ export class JSONHover { withSchemaWarning: true, }); if (isJsonError(subSchema)) { - console.log("subschema", subSchema.data); - if (subSchema?.data.schema["$ref"]) { subSchema = this.schema.resolveRef(subSchema); } else { @@ -139,7 +137,6 @@ export class JSONHover { let message = null; const { schema } = data; - console.log(schema, data); if (schema.oneOf) { typeInfo = formatComplexType(schema, "oneOf", draft); } diff --git a/src/json-validation.ts b/src/json-validation.ts index a2f7028..61f6ac6 100644 --- a/src/json-validation.ts +++ b/src/json-validation.ts @@ -65,15 +65,15 @@ export class JSONValidation { // rewrite the error message to be more human readable private rewriteError = (error: JsonError): string => { - if (error.code === "one-of-error") { - console.log("raw", error?.data?.received); + const errorData = error?.data; + const errors = errorData?.errors as string[]; + if (error.code === "one-of-error" && errors?.length) { return `Expected one of ${joinWithOr( - error?.data?.errors, + errors as string[], (data) => data.data.expected )}`; } if (error.code === "type-error") { - console.log("raw", error?.data?.received); return `Expected ${ error?.data?.expected && Array.isArray(error?.data?.expected) ? joinWithOr(error?.data?.expected) @@ -108,19 +108,20 @@ export class JSONValidation { if (!errors.length) return []; // reduce() because we want to filter out errors that don't have a pointer return errors.reduce((acc, error) => { - console.log(this.rewriteError(error)); const errorPath = getErrorPath(error); const pointer = json.pointers.get(errorPath) as JSONPointerData; + if (pointer) { // if the error is a property error, use the key position const isPropertyError = error.name === "NoAdditionalPropertiesError"; + const errorString = this.rewriteError(error); acc.push({ from: isPropertyError ? pointer.keyFrom : pointer.valueFrom, to: isPropertyError ? pointer.keyTo : pointer.valueTo, - message: this.rewriteError(error), + message: errorString, renderMessage: () => { const dom = el("div", {}); - dom.innerHTML = this.rewriteError(error); + dom.innerHTML = errorString; return dom; }, severity: "error",