Skip to content

Commit

Permalink
fix the version
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Nov 6, 2023
1 parent ebd59dd commit d0d5bd2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions src/json-hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
15 changes: 8 additions & 7 deletions src/json-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>${
error?.data?.expected && Array.isArray(error?.data?.expected)
? joinWithOr(error?.data?.expected)
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit d0d5bd2

Please sign in to comment.