From cf6b1f8ddd24b5ac41cccf0dbd4ece974462bfdf Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Fri, 29 Mar 2024 07:54:21 +0100 Subject: [PATCH 1/2] refactor(editor-preview-asyncapi): allow flexible options usage Refs #4585 --- src/plugins/editor-preview-asyncapi/actions.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/plugins/editor-preview-asyncapi/actions.js b/src/plugins/editor-preview-asyncapi/actions.js index a50c26c1e88..b74b80f67fc 100644 --- a/src/plugins/editor-preview-asyncapi/actions.js +++ b/src/plugins/editor-preview-asyncapi/actions.js @@ -53,12 +53,18 @@ export const parseFailure = ({ error, parseResult, content, requestId }) => ({ export const parse = (content, options = {}) => { const uid = new ShortUniqueId({ length: 10 }); + /** + * We dive ability to fully distinguish between parser and parse options. + * If parser or parse options are not provided, we will use the options object as it is. + */ const { parserOptions, parseOptions } = options; - const parser = new Parser(parserOptions); - parser.registerSchemaParser(OpenAPISchemaParser()); - parser.registerSchemaParser(AvroSchemaParser()); - parser.registerSchemaParser(Raml10SchemaParser()); - parser.registerSchemaParser(ProtoBuffSchemaParser()); + const schemaParsers = [ + OpenAPISchemaParser(), + AvroSchemaParser(), + Raml10SchemaParser(), + ProtoBuffSchemaParser(), + ]; + const parser = new Parser({ schemaParsers, ...(parserOptions ?? options) }); return async (system) => { /** @@ -71,7 +77,7 @@ export const parse = (content, options = {}) => { editorPreviewAsyncAPIActions.parseStarted({ content, requestId }); try { - const parseResult = await parser.parse(content, parseOptions); + const parseResult = await parser.parse(content, parseOptions ?? options); if (parseResult.document) { editorPreviewAsyncAPIActions.parseSuccess({ parseResult, content, requestId }); From c295be91b064b0a5f4ca7eef87cd812b527c8d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Fri, 29 Mar 2024 07:55:19 +0100 Subject: [PATCH 2/2] Update src/plugins/editor-preview-asyncapi/actions.js --- src/plugins/editor-preview-asyncapi/actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/editor-preview-asyncapi/actions.js b/src/plugins/editor-preview-asyncapi/actions.js index b74b80f67fc..d3c8869bc83 100644 --- a/src/plugins/editor-preview-asyncapi/actions.js +++ b/src/plugins/editor-preview-asyncapi/actions.js @@ -54,7 +54,7 @@ export const parse = (content, options = {}) => { const uid = new ShortUniqueId({ length: 10 }); /** - * We dive ability to fully distinguish between parser and parse options. + * We give ability to fully distinguish between parser and parse options. * If parser or parse options are not provided, we will use the options object as it is. */ const { parserOptions, parseOptions } = options;