Skip to content

Commit c553043

Browse files
Merge branch 'master' into split_red
2 parents 79cc231 + 31c2a86 commit c553043

File tree

6 files changed

+75
-26
lines changed

6 files changed

+75
-26
lines changed

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# For more details, read the following article on GitHub: https://help.github.com/articles/about-codeowners/.
66

77
# These are the default owners for the whole content of the "@asyncapi/asyncapi-react" repository. The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file.
8-
* @magicmatatjahu @derberg @fmvilas @asyncapi-bot-eve
8+
* @magicmatatjahu @fmvilas @asyncapi-bot-eve @AceTheCreator

library/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"dependencies": {
7171
"@asyncapi/avro-schema-parser": "^3.0.24",
7272
"@asyncapi/openapi-schema-parser": "^3.0.24",
73-
"@asyncapi/parser": "^3.1.0",
73+
"@asyncapi/parser": "^3.3.0",
7474
"@asyncapi/protobuf-schema-parser": "^3.2.14",
7575
"highlight.js": "^10.7.2",
7676
"isomorphic-dompurify": "^2.14.0",

library/src/containers/AsyncApi/Standalone.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ class AsyncApiComponent extends Component<AsyncApiProps, AsyncAPIState> {
7575
if (!error) {
7676
return null;
7777
}
78-
return concatenatedConfig.show?.errors && <Error error={error} />;
78+
return (
79+
concatenatedConfig.show?.errors && (
80+
<section className="aui-root">
81+
<Error error={error} />
82+
</section>
83+
)
84+
);
7985
}
8086

8187
return (

library/src/containers/Error/Error.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ const renderErrors = (errors: ValidationError[]): React.ReactNode => {
1010

1111
return errors
1212
.map((singleError: ValidationError, index: number) => {
13-
if (!singleError?.title || !singleError.location) {
13+
if (!singleError?.title) {
1414
return null;
1515
}
1616
return (
17-
<div key={index} className="flex">
18-
<span>{`${singleError.location.startLine}.`}</span>
17+
<div key={index} className="flex gap-2">
18+
<span>{`line ${singleError?.location?.startLine + singleError?.location?.startOffset}:`}</span>
1919
<code className="whitespace-pre-wrap break-all ml-2">
2020
{singleError.title}
2121
</code>

library/src/helpers/parser.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { OpenAPISchemaParser } from '@asyncapi/openapi-schema-parser';
33
import { ProtoBuffSchemaParser } from '@asyncapi/protobuf-schema-parser';
44
import { AvroSchemaParser } from '@asyncapi/avro-schema-parser';
55

6-
import { ErrorObject, ParserReturn, FetchingSchemaInterface } from '../types';
6+
import {
7+
ErrorObject,
8+
ParserReturn,
9+
FetchingSchemaInterface,
10+
ValidationError,
11+
} from '../types';
712

813
import { VALIDATION_ERRORS_TYPE } from '../constants';
914

@@ -22,8 +27,40 @@ export class Parser {
2227
): Promise<ParserReturn> {
2328
try {
2429
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
25-
const { document } = await asyncapiParser.parse(content, parserOptions);
26-
return { asyncapi: document };
30+
const parseResult = await asyncapiParser.parse(content, parserOptions);
31+
32+
const error: {
33+
title: string | undefined;
34+
validationErrors: ValidationError[] | undefined;
35+
} = {
36+
title: 'There are errors in your Asyncapi document',
37+
validationErrors: [],
38+
};
39+
40+
if (parseResult.document === undefined) {
41+
parseResult.diagnostics.forEach((diagnostic) => {
42+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
43+
if (diagnostic.severity == 0) {
44+
const tempObj: ValidationError = {
45+
title: diagnostic.message,
46+
location: {
47+
jsonPointer: '/' + diagnostic.path.join('/'),
48+
startLine: diagnostic.range.start.line,
49+
startColumn: diagnostic.range.start.character,
50+
// as of @asyncapi/parser 3.3.0 offset of 1 correctly shows the error line
51+
startOffset: 1,
52+
endLine: diagnostic.range.end.line,
53+
endColumn: diagnostic.range.end.character,
54+
endOffset: 0,
55+
},
56+
};
57+
error.validationErrors?.push(tempObj);
58+
}
59+
});
60+
throw error;
61+
}
62+
63+
return { asyncapi: parseResult.document };
2764
} catch (err) {
2865
return this.handleError(err as ErrorObject);
2966
}

package-lock.json

Lines changed: 23 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)