From 3c2458601917d127c28da2b781e1cc27d9f48371 Mon Sep 17 00:00:00 2001 From: Cody's Dad <40604284+AceTheCreator@users.noreply.github.com> Date: Mon, 7 Oct 2024 18:31:25 +0100 Subject: [PATCH] Revert "fix: informative Stubs when document is invalid (#1068)" This reverts commit 31c2a86cea10ec08c909b96a3957d9c7223fd722. --- library/package.json | 2 +- .../src/containers/AsyncApi/Standalone.tsx | 8 +--- library/src/containers/Error/Error.tsx | 6 +-- library/src/helpers/parser.ts | 43 ++----------------- package-lock.json | 40 ++++++++--------- 5 files changed, 25 insertions(+), 74 deletions(-) diff --git a/library/package.json b/library/package.json index 30c50b9dc..5ccf2943d 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.3.0", + "@asyncapi/parser": "^3.1.0", "@asyncapi/protobuf-schema-parser": "^3.2.14", "highlight.js": "^10.7.2", "isomorphic-dompurify": "^2.14.0", diff --git a/library/src/containers/AsyncApi/Standalone.tsx b/library/src/containers/AsyncApi/Standalone.tsx index 9c5cc3c8e..658aa9b4e 100644 --- a/library/src/containers/AsyncApi/Standalone.tsx +++ b/library/src/containers/AsyncApi/Standalone.tsx @@ -75,13 +75,7 @@ class AsyncApiComponent extends Component { if (!error) { return null; } - return ( - concatenatedConfig.show?.errors && ( -
- -
- ) - ); + return concatenatedConfig.show?.errors && ; } return ( diff --git a/library/src/containers/Error/Error.tsx b/library/src/containers/Error/Error.tsx index eba833efa..984cc8fa2 100644 --- a/library/src/containers/Error/Error.tsx +++ b/library/src/containers/Error/Error.tsx @@ -10,12 +10,12 @@ const renderErrors = (errors: ValidationError[]): React.ReactNode => { return errors .map((singleError: ValidationError, index: number) => { - if (!singleError?.title) { + if (!singleError?.title || !singleError.location) { return null; } return ( -
- {`line ${singleError?.location?.startLine + singleError?.location?.startOffset}:`} +
+ {`${singleError.location.startLine}.`} {singleError.title} diff --git a/library/src/helpers/parser.ts b/library/src/helpers/parser.ts index 0ecb3cc28..44947ca09 100644 --- a/library/src/helpers/parser.ts +++ b/library/src/helpers/parser.ts @@ -3,12 +3,7 @@ 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, - ValidationError, -} from '../types'; +import { ErrorObject, ParserReturn, FetchingSchemaInterface } from '../types'; import { VALIDATION_ERRORS_TYPE } from '../constants'; @@ -27,40 +22,8 @@ export class Parser { ): Promise { try { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - const parseResult = await asyncapiParser.parse(content, parserOptions); - - const error: { - title: string | undefined; - validationErrors: ValidationError[] | undefined; - } = { - title: 'There are errors in your Asyncapi document', - validationErrors: [], - }; - - 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, - location: { - jsonPointer: '/' + diagnostic.path.join('/'), - startLine: diagnostic.range.start.line, - startColumn: diagnostic.range.start.character, - // 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, - }, - }; - error.validationErrors?.push(tempObj); - } - }); - throw error; - } - - return { asyncapi: parseResult.document }; + const { document } = await asyncapiParser.parse(content, parserOptions); + return { asyncapi: document }; } catch (err) { return this.handleError(err as ErrorObject); } diff --git a/package-lock.json b/package-lock.json index 4766f325b..6571612ba 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.3.0", + "@asyncapi/parser": "^3.1.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.3.0", - "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-3.3.0.tgz", - "integrity": "sha512-IqBeDU/YxiHP/ySPYR5ayT/EE2ad9V75v8lhcA2ZowRDKh1YvNJaDwTpJjmRuggg8328uSDc9x/YEy6KgRgcgw==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-3.1.0.tgz", + "integrity": "sha512-rUd+fsPRE68o+F3gLqk7OaBj5J5VgBiLk9eJBGEXolNmKbVd45mxJm2aBpMkphQEmYHuBvxZyiNYlSCyr1D2fA==", "dependencies": { - "@asyncapi/specs": "^6.8.0", + "@asyncapi/specs": "^6.7.1", "@openapi-contrib/openapi-schema-to-json-schema": "~3.2.0", - "@stoplight/json": "3.21.0", + "@stoplight/json": "^3.20.2", "@stoplight/json-ref-readers": "^1.2.2", "@stoplight/json-ref-resolver": "^3.1.5", - "@stoplight/spectral-core": "^1.18.3", + "@stoplight/spectral-core": "^1.16.1", "@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.17.1", + "ajv": "^8.11.0", "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.8.0", - "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-6.8.0.tgz", - "integrity": "sha512-1i6xs8+IOh6U5T7yH+bCMGQBF+m7kP/NpwyAlt++XaDQutoGCgACf24mQBgcDVqDWWoY81evQv+9ABvw0BviVg==", + "version": "6.7.1", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-6.7.1.tgz", + "integrity": "sha512-jEaW2vgAwD9GboCdO/TI1zN2k+iowL8YFYwiZwTIr4U4KDmsgo3BLypScl6Jl4+IvY9RdsWE67nuzVX7jooiqQ==", "dependencies": { "@types/json-schema": "^7.0.11" } @@ -6414,14 +6414,14 @@ } }, "node_modules/ajv": { - "version": "8.17.1", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", - "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", + "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", "dependencies": { - "fast-deep-equal": "^3.1.3", - "fast-uri": "^3.0.1", + "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2" + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" }, "funding": { "type": "github", @@ -11714,11 +11714,6 @@ "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", @@ -26468,7 +26463,6 @@ "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" }