@asyncapi/parser
Advanced tools
Comparing version 1.0.0-rc.3 to 1.0.0-rc.4
@@ -18,3 +18,2 @@ const path = require('path'); | ||
const xParserCircle = 'x-parser-circular'; | ||
const refParser = new $RefParser; | ||
@@ -80,6 +79,7 @@ /** | ||
const refParser = new $RefParser; | ||
//because of Ajv lacks support for circular refs, parser should not resolve them before Ajv validation and first needs to ignore them and leave circular $refs to successfully validate the document | ||
//this is done pair to advice from Ajv creator https://github.com/ajv-validator/ajv/issues/1122#issuecomment-559378449 | ||
//later we perform full dereference of circular refs if they occure | ||
await dereference(parsedJSON, initialFormat, asyncapiYAMLorJSON, { ...options, dereference: { circular: 'ignore' } }); | ||
await dereference(refParser, parsedJSON, initialFormat, asyncapiYAMLorJSON, { ...options, dereference: { circular: 'ignore' } }); | ||
@@ -105,3 +105,3 @@ const ajv = new Ajv({ | ||
await customDocumentOperations(parsedJSON, asyncapiYAMLorJSON, initialFormat, options); | ||
if (refParser.$refs.circular) await handleCircularRefs(parsedJSON, initialFormat, asyncapiYAMLorJSON, options); | ||
if (refParser.$refs.circular) await handleCircularRefs(refParser, parsedJSON, initialFormat, asyncapiYAMLorJSON, options); | ||
} catch (e) { | ||
@@ -142,3 +142,3 @@ if (e instanceof ParserError) throw e; | ||
async function dereference(parsedJSON, initialFormat, asyncapiYAMLorJSON, options) { | ||
async function dereference(refParser, parsedJSON, initialFormat, asyncapiYAMLorJSON, options) { | ||
try { | ||
@@ -165,4 +165,4 @@ return await refParser.dereference(options.path, parsedJSON, { | ||
*/ | ||
async function handleCircularRefs(parsedJSON, initialFormat, asyncapiYAMLorJSON, options) { | ||
await dereference(parsedJSON, initialFormat, asyncapiYAMLorJSON, { ...options, dereference: { circular: true } }); | ||
async function handleCircularRefs(refParser, parsedJSON, initialFormat, asyncapiYAMLorJSON, options) { | ||
await dereference(refParser, parsedJSON, initialFormat, asyncapiYAMLorJSON, { ...options, dereference: { circular: true } }); | ||
//mark entire document as containing circular references | ||
@@ -169,0 +169,0 @@ parsedJSON[String(xParserCircle)] = true; |
{ | ||
"name": "@asyncapi/parser", | ||
"version": "1.0.0-rc.3", | ||
"version": "1.0.0-rc.4", | ||
"description": "JavaScript AsyncAPI parser.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
947191