From 82aa7fd0486d360f63dee466b5eea30276b1efae Mon Sep 17 00:00:00 2001 From: catosaurusrex2003 Date: Sun, 6 Oct 2024 14:40:33 +0530 Subject: [PATCH 1/6] diagnostics with severity 0 displaying --- library/src/containers/Error/Error.tsx | 7 +++-- library/src/helpers/parser.ts | 41 ++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/library/src/containers/Error/Error.tsx b/library/src/containers/Error/Error.tsx index 984cc8fa2..80d1340fe 100644 --- a/library/src/containers/Error/Error.tsx +++ b/library/src/containers/Error/Error.tsx @@ -10,12 +10,13 @@ const renderErrors = (errors: ValidationError[]): React.ReactNode => { return errors .map((singleError: ValidationError, index: number) => { - if (!singleError?.title || !singleError.location) { + if (!singleError?.title) { return null; } return ( -
- {`${singleError.location.startLine}.`} +
+ {/* {`${singleError?.location?.startLine}.${singleError?.location?.startColumn}`} */} + {/* */} {singleError.title} diff --git a/library/src/helpers/parser.ts b/library/src/helpers/parser.ts index 44947ca09..cb94e40ce 100644 --- a/library/src/helpers/parser.ts +++ b/library/src/helpers/parser.ts @@ -3,7 +3,12 @@ import { OpenAPISchemaParser } from '@asyncapi/openapi-schema-parser'; import { ProtoBuffSchemaParser } from '@asyncapi/protobuf-schema-parser'; import { AvroSchemaParser } from '@asyncapi/avro-schema-parser'; -import { ErrorObject, ParserReturn, FetchingSchemaInterface } from '../types'; +import { + ErrorObject, + ParserReturn, + FetchingSchemaInterface, + ValidationError, +} from '../types'; import { VALIDATION_ERRORS_TYPE } from '../constants'; @@ -22,8 +27,38 @@ export class Parser { ): Promise { try { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - const { document } = await asyncapiParser.parse(content, parserOptions); - return { asyncapi: document }; + const parseResult = await asyncapiParser.parse(content, parserOptions); + + let error: { + title: string | undefined; + validationErrors: ValidationError[] | undefined; + } = { + title: 'There are errors in your Asyncapi document', + validationErrors: [], + }; + + if (parseResult.document === undefined) { + parseResult.diagnostics.forEach((diagnostic) => { + if (diagnostic.severity == 0) { + const tempObj = { + title: diagnostic.message, + location: { + jsonPointer: 'json pointer', + startLine: diagnostic.range.start.line, + startColumn: diagnostic.range.start.character, + startOffset: 0, + endLine: diagnostic.range.end.line, + endColumn: diagnostic.range.end.character, + endOffset: 0, + }, + }; + error.validationErrors?.push(tempObj as unknown as ValidationError); + } + }); + throw error; + } + + return { asyncapi: parseResult.document }; } catch (err) { return this.handleError(err as ErrorObject); } From d038a6e1be9b917802931473a103a39d3e898432 Mon Sep 17 00:00:00 2001 From: catosaurusrex2003 Date: Sun, 6 Oct 2024 19:47:39 +0530 Subject: [PATCH 2/6] removing left over comments --- library/src/containers/Error/Error.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/src/containers/Error/Error.tsx b/library/src/containers/Error/Error.tsx index 80d1340fe..a07223fdd 100644 --- a/library/src/containers/Error/Error.tsx +++ b/library/src/containers/Error/Error.tsx @@ -15,8 +15,6 @@ const renderErrors = (errors: ValidationError[]): React.ReactNode => { } return (
- {/* {`${singleError?.location?.startLine}.${singleError?.location?.startColumn}`} */} - {/* */} {singleError.title} From 48300550c1f767bf8901456f901df092aa08b581 Mon Sep 17 00:00:00 2001 From: catosaurusrex2003 Date: Sun, 6 Oct 2024 21:20:03 +0530 Subject: [PATCH 3/6] tailwind css now working --- library/src/containers/AsyncApi/Standalone.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/src/containers/AsyncApi/Standalone.tsx b/library/src/containers/AsyncApi/Standalone.tsx index 658aa9b4e..9c5cc3c8e 100644 --- a/library/src/containers/AsyncApi/Standalone.tsx +++ b/library/src/containers/AsyncApi/Standalone.tsx @@ -75,7 +75,13 @@ class AsyncApiComponent extends Component { if (!error) { return null; } - return concatenatedConfig.show?.errors && ; + return ( + concatenatedConfig.show?.errors && ( +
+ +
+ ) + ); } return ( From 0f41aba774b09201817f0a0d5e314392c4cf9622 Mon Sep 17 00:00:00 2001 From: catosaurusrex2003 Date: Sun, 6 Oct 2024 22:20:06 +0530 Subject: [PATCH 4/6] line of the error, but its not accurate --- library/src/containers/Error/Error.tsx | 6 +++++- library/src/helpers/parser.ts | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/library/src/containers/Error/Error.tsx b/library/src/containers/Error/Error.tsx index a07223fdd..a77bc4ff8 100644 --- a/library/src/containers/Error/Error.tsx +++ b/library/src/containers/Error/Error.tsx @@ -14,7 +14,11 @@ const renderErrors = (errors: ValidationError[]): React.ReactNode => { return null; } return ( -
+
+ {`line ${singleError?.location?.startLine}:`} {singleError.title} diff --git a/library/src/helpers/parser.ts b/library/src/helpers/parser.ts index cb94e40ce..9510d8ce8 100644 --- a/library/src/helpers/parser.ts +++ b/library/src/helpers/parser.ts @@ -40,7 +40,7 @@ export class Parser { if (parseResult.document === undefined) { parseResult.diagnostics.forEach((diagnostic) => { if (diagnostic.severity == 0) { - const tempObj = { + const tempObj:ValidationError = { title: diagnostic.message, location: { jsonPointer: 'json pointer', @@ -52,7 +52,7 @@ export class Parser { endOffset: 0, }, }; - error.validationErrors?.push(tempObj as unknown as ValidationError); + error.validationErrors?.push(tempObj); } }); throw error; From ec0c7218f4841427805c035b5be9e178a8c8016e Mon Sep 17 00:00:00 2001 From: catosaurusrex2003 Date: Sun, 6 Oct 2024 22:46:34 +0530 Subject: [PATCH 5/6] passing jsonPointer in the error --- library/src/helpers/parser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/helpers/parser.ts b/library/src/helpers/parser.ts index 9510d8ce8..6e88d7c50 100644 --- a/library/src/helpers/parser.ts +++ b/library/src/helpers/parser.ts @@ -40,10 +40,10 @@ export class Parser { if (parseResult.document === undefined) { parseResult.diagnostics.forEach((diagnostic) => { if (diagnostic.severity == 0) { - const tempObj:ValidationError = { + const tempObj: ValidationError = { title: diagnostic.message, location: { - jsonPointer: 'json pointer', + jsonPointer: '/' + diagnostic.path.join('/'), startLine: diagnostic.range.start.line, startColumn: diagnostic.range.start.character, startOffset: 0, From 6a3d38e844b7aea5f6ccbeb4b45658d7e2eb1fbd Mon Sep 17 00:00:00 2001 From: catosaurusrex2003 Date: Mon, 7 Oct 2024 13:15:19 +0530 Subject: [PATCH 6/6] line of error working reliably now --- library/package.json | 2 +- library/src/containers/Error/Error.tsx | 7 ++--- library/src/helpers/parser.ts | 6 ++-- package-lock.json | 40 +++++++++++++++----------- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/library/package.json b/library/package.json index 5ccf2943d..30c50b9dc 100644 --- a/library/package.json +++ b/library/package.json @@ -70,7 +70,7 @@ "dependencies": { "@asyncapi/avro-schema-parser": "^3.0.24", "@asyncapi/openapi-schema-parser": "^3.0.24", - "@asyncapi/parser": "^3.1.0", + "@asyncapi/parser": "^3.3.0", "@asyncapi/protobuf-schema-parser": "^3.2.14", "highlight.js": "^10.7.2", "isomorphic-dompurify": "^2.14.0", diff --git a/library/src/containers/Error/Error.tsx b/library/src/containers/Error/Error.tsx index a77bc4ff8..eba833efa 100644 --- a/library/src/containers/Error/Error.tsx +++ b/library/src/containers/Error/Error.tsx @@ -14,11 +14,8 @@ const renderErrors = (errors: ValidationError[]): React.ReactNode => { return null; } return ( -
- {`line ${singleError?.location?.startLine}:`} +
+ {`line ${singleError?.location?.startLine + singleError?.location?.startOffset}:`} {singleError.title} diff --git a/library/src/helpers/parser.ts b/library/src/helpers/parser.ts index 6e88d7c50..0ecb3cc28 100644 --- a/library/src/helpers/parser.ts +++ b/library/src/helpers/parser.ts @@ -29,7 +29,7 @@ export class Parser { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const parseResult = await asyncapiParser.parse(content, parserOptions); - let error: { + const error: { title: string | undefined; validationErrors: ValidationError[] | undefined; } = { @@ -39,6 +39,7 @@ export class Parser { if (parseResult.document === undefined) { parseResult.diagnostics.forEach((diagnostic) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison if (diagnostic.severity == 0) { const tempObj: ValidationError = { title: diagnostic.message, @@ -46,7 +47,8 @@ export class Parser { jsonPointer: '/' + diagnostic.path.join('/'), startLine: diagnostic.range.start.line, startColumn: diagnostic.range.start.character, - startOffset: 0, + // as of @asyncapi/parser 3.3.0 offset of 1 correctly shows the error line + startOffset: 1, endLine: diagnostic.range.end.line, endColumn: diagnostic.range.end.character, endOffset: 0, diff --git a/package-lock.json b/package-lock.json index 6571612ba..4766f325b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,7 +41,7 @@ "dependencies": { "@asyncapi/avro-schema-parser": "^3.0.24", "@asyncapi/openapi-schema-parser": "^3.0.24", - "@asyncapi/parser": "^3.1.0", + "@asyncapi/parser": "^3.3.0", "@asyncapi/protobuf-schema-parser": "^3.2.14", "highlight.js": "^10.7.2", "isomorphic-dompurify": "^2.14.0", @@ -190,23 +190,23 @@ } }, "node_modules/@asyncapi/parser": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-3.1.0.tgz", - "integrity": "sha512-rUd+fsPRE68o+F3gLqk7OaBj5J5VgBiLk9eJBGEXolNmKbVd45mxJm2aBpMkphQEmYHuBvxZyiNYlSCyr1D2fA==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-3.3.0.tgz", + "integrity": "sha512-IqBeDU/YxiHP/ySPYR5ayT/EE2ad9V75v8lhcA2ZowRDKh1YvNJaDwTpJjmRuggg8328uSDc9x/YEy6KgRgcgw==", "dependencies": { - "@asyncapi/specs": "^6.7.1", + "@asyncapi/specs": "^6.8.0", "@openapi-contrib/openapi-schema-to-json-schema": "~3.2.0", - "@stoplight/json": "^3.20.2", + "@stoplight/json": "3.21.0", "@stoplight/json-ref-readers": "^1.2.2", "@stoplight/json-ref-resolver": "^3.1.5", - "@stoplight/spectral-core": "^1.16.1", + "@stoplight/spectral-core": "^1.18.3", "@stoplight/spectral-functions": "^1.7.2", "@stoplight/spectral-parsers": "^1.0.2", "@stoplight/spectral-ref-resolver": "^1.0.3", "@stoplight/types": "^13.12.0", "@types/json-schema": "^7.0.11", "@types/urijs": "^1.19.19", - "ajv": "^8.11.0", + "ajv": "^8.17.1", "ajv-errors": "^3.0.0", "ajv-formats": "^2.1.1", "avsc": "^5.7.5", @@ -230,9 +230,9 @@ "link": true }, "node_modules/@asyncapi/specs": { - "version": "6.7.1", - "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-6.7.1.tgz", - "integrity": "sha512-jEaW2vgAwD9GboCdO/TI1zN2k+iowL8YFYwiZwTIr4U4KDmsgo3BLypScl6Jl4+IvY9RdsWE67nuzVX7jooiqQ==", + "version": "6.8.0", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-6.8.0.tgz", + "integrity": "sha512-1i6xs8+IOh6U5T7yH+bCMGQBF+m7kP/NpwyAlt++XaDQutoGCgACf24mQBgcDVqDWWoY81evQv+9ABvw0BviVg==", "dependencies": { "@types/json-schema": "^7.0.11" } @@ -6414,14 +6414,14 @@ } }, "node_modules/ajv": { - "version": "8.12.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", - "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dependencies": { - "fast-deep-equal": "^3.1.1", + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.2.2" + "require-from-string": "^2.0.2" }, "funding": { "type": "github", @@ -11714,6 +11714,11 @@ "resolved": "https://registry.npmjs.org/fast-memoize/-/fast-memoize-2.5.2.tgz", "integrity": "sha512-Ue0LwpDYErFbmNnZSF0UH6eImUwDmogUO1jyE+JbN2gsQz/jICm1Ve7t9QT0rNSsfJt+Hs4/S3GnsDVjL4HVrw==" }, + "node_modules/fast-uri": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.2.tgz", + "integrity": "sha512-GR6f0hD7XXyNJa25Tb9BuIdN0tdr+0BMi6/CJPH3wJO1JjNG3n/VsSw38AwRdKZABm8lGbPfakLRkYzx2V9row==" + }, "node_modules/fastest-levenshtein": { "version": "1.0.16", "resolved": "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.16.tgz", @@ -26463,6 +26468,7 @@ "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, "dependencies": { "punycode": "^2.1.0" }