Skip to content

Commit

Permalink
refactor(editor-preview-asyncapi): allow flexible options usage
Browse files Browse the repository at this point in the history
Refs #4585
  • Loading branch information
char0n committed Mar 29, 2024
1 parent 4f6f2ef commit cf6b1f8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/plugins/editor-preview-asyncapi/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
/**
Expand All @@ -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 });
Expand Down

0 comments on commit cf6b1f8

Please sign in to comment.