Skip to content

Commit 55d00b7

Browse files
authored
refactor(editor-preview-asyncapi): allow flexible parser/parse options usage (#4883)
Refs #4585
1 parent 4f6f2ef commit 55d00b7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/plugins/editor-preview-asyncapi/actions.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ export const parseFailure = ({ error, parseResult, content, requestId }) => ({
5353
export const parse = (content, options = {}) => {
5454
const uid = new ShortUniqueId({ length: 10 });
5555

56+
/**
57+
* We give ability to fully distinguish between parser and parse options.
58+
* If parser or parse options are not provided, we will use the options object as it is.
59+
*/
5660
const { parserOptions, parseOptions } = options;
57-
const parser = new Parser(parserOptions);
58-
parser.registerSchemaParser(OpenAPISchemaParser());
59-
parser.registerSchemaParser(AvroSchemaParser());
60-
parser.registerSchemaParser(Raml10SchemaParser());
61-
parser.registerSchemaParser(ProtoBuffSchemaParser());
61+
const schemaParsers = [
62+
OpenAPISchemaParser(),
63+
AvroSchemaParser(),
64+
Raml10SchemaParser(),
65+
ProtoBuffSchemaParser(),
66+
];
67+
const parser = new Parser({ schemaParsers, ...(parserOptions ?? options) });
6268

6369
return async (system) => {
6470
/**
@@ -71,7 +77,7 @@ export const parse = (content, options = {}) => {
7177
editorPreviewAsyncAPIActions.parseStarted({ content, requestId });
7278

7379
try {
74-
const parseResult = await parser.parse(content, parseOptions);
80+
const parseResult = await parser.parse(content, parseOptions ?? options);
7581

7682
if (parseResult.document) {
7783
editorPreviewAsyncAPIActions.parseSuccess({ parseResult, content, requestId });

0 commit comments

Comments
 (0)