Skip to content

Commit

Permalink
fix: remove forceful normalization of YAML to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
aeworxet committed Jul 3, 2024
1 parent 0676ea0 commit 087a11f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-pumas-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@asyncapi/parser": patch
---

fix: remove forceful normalization of YAML to JSON
18 changes: 4 additions & 14 deletions packages/parser/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParseOutput> {
let spectralDocument: Document | undefined;

try {
options = mergePatch<ParseOptions>(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,
Expand All @@ -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);
Expand Down

0 comments on commit 087a11f

Please sign in to comment.