Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(editor-preview-asyncapi): allow flexible options usage #4883

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
char0n marked this conversation as resolved.
Show resolved Hide resolved
* 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