From 087a11f149059ccd80ab50a997727399be9a8a97 Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Wed, 3 Jul 2024 02:51:41 +0000 Subject: [PATCH] fix: remove forceful normalization of YAML to JSON --- .changeset/smooth-pumas-deliver.md | 5 +++++ packages/parser/src/parse.ts | 18 ++++-------------- 2 files changed, 9 insertions(+), 14 deletions(-) create mode 100644 .changeset/smooth-pumas-deliver.md diff --git a/.changeset/smooth-pumas-deliver.md b/.changeset/smooth-pumas-deliver.md new file mode 100644 index 000000000..58c83ea24 --- /dev/null +++ b/.changeset/smooth-pumas-deliver.md @@ -0,0 +1,5 @@ +--- +"@asyncapi/parser": patch +--- + +fix: remove forceful normalization of YAML to JSON diff --git a/packages/parser/src/parse.ts b/packages/parser/src/parse.ts index 9688a4314..0d3c40c05 100644 --- a/packages/parser/src/parse.ts +++ b/packages/parser/src/parse.ts @@ -38,24 +38,14 @@ const defaultOptions: ParseOptions = { validateOptions: {}, __unstable: {}, }; -import yaml from 'js-yaml'; + export async function parse(parser: Parser, spectral: Spectral, asyncapi: Input, options: ParseOptions = {}): Promise { let spectralDocument: Document | undefined; try { options = mergePatch(defaultOptions, options); - // Normalize input to always be JSON - let loadedObj; - if (typeof asyncapi === 'string') { - try { - loadedObj = yaml.load(asyncapi); - } catch (e) { - loadedObj = JSON.parse(asyncapi); - } - } else { - loadedObj = asyncapi; - } - const { validated, diagnostics, extras } = await validate(parser, spectral, loadedObj, { ...options.validateOptions, source: options.source, __unstable: options.__unstable }); + + const { validated, diagnostics, extras } = await validate(parser, spectral, asyncapi, { ...options.validateOptions, source: options.source, __unstable: options.__unstable }); if (validated === undefined) { return { document: undefined, @@ -72,7 +62,7 @@ export async function parse(parser: Parser, spectral: Spectral, asyncapi: Input, // Apply unique ids which are used as part of iterating between channels <-> operations <-> messages applyUniqueIds(validatedDoc); - const detailed = createDetailedAsyncAPI(validatedDoc, loadedObj as DetailedAsyncAPI['input'], options.source); + const detailed = createDetailedAsyncAPI(validatedDoc, asyncapi as DetailedAsyncAPI['input'], options.source); const document = createAsyncAPIDocument(detailed); setExtension(xParserSpecParsed, true, document); setExtension(xParserApiVersion, ParserAPIVersion, document);