@asyncapi/parser
Advanced tools
Comparing version 1.15.2 to 1.16.0
@@ -9,3 +9,10 @@ const path = require('path'); | ||
const { validateChannels, validateTags, validateServerVariables, validateOperationId, validateServerSecurity, validateMessageId } = require('./customValidators.js'); | ||
const { toJS, findRefs, getLocationOf, improveAjvErrors, getDefaultSchemaFormat } = require('./utils'); | ||
const { | ||
toJS, | ||
findRefs, | ||
getLocationOf, | ||
improveAjvErrors, | ||
getDefaultSchemaFormat, | ||
getBaseUrl, | ||
} = require('./utils'); | ||
const AsyncAPIDocument = require('./models/asyncapi'); | ||
@@ -60,3 +67,7 @@ | ||
options.path = options.path || `${process.cwd()}${path.sep}`; | ||
if (typeof window !== 'undefined' && !options.hasOwnProperty('path')) { | ||
options.path = getBaseUrl(window.location.href); | ||
} else { | ||
options.path = options.path || `${process.cwd()}${path.sep}`; | ||
} | ||
@@ -133,3 +144,3 @@ try { | ||
*/ | ||
function parseFromUrl(url, fetchOptions, options) { | ||
function parseFromUrl(url, fetchOptions, options = {}) { | ||
//Why not just addinga default to the arguments list? | ||
@@ -140,2 +151,6 @@ //All function parameters with default values should be declared after the function parameters without default values. Otherwise, it makes it impossible for callers to take advantage of defaults; they must re-specify the defaulted values or pass undefined in order to "get to" the non-default parameters. | ||
if (!options.hasOwnProperty('path')) { | ||
options = { ...options, path: getBaseUrl(url) }; | ||
} | ||
return new Promise((resolve, reject) => { | ||
@@ -142,0 +157,0 @@ fetch(url, fetchOptions) |
@@ -223,2 +223,19 @@ const YAML = require('js-yaml'); | ||
/** | ||
* Returns base URL parsed from location of AsyncAPI document | ||
* | ||
* @function getBaseUrl | ||
* @private | ||
* @param {String} url URL of AsyncAPI document | ||
*/ | ||
utils.getBaseUrl = url => { | ||
url = typeof url !== 'string' ? String(url) : url; | ||
//URL validation is not performed because 'node-fetch' performs its own | ||
//validation at fetch time, so no repetition of this task is made. | ||
//Only ensuring that 'url' has type of 'string' and letting 'node-fetch' deal | ||
//with the rest. | ||
return url.substring(0, url.lastIndexOf('/') + 1); | ||
}; | ||
/** | ||
* Returns an array of not existing properties in provided object with names specified in provided array | ||
@@ -225,0 +242,0 @@ * @function getMissingProps |
{ | ||
"name": "@asyncapi/parser", | ||
"version": "1.15.2", | ||
"version": "1.16.0", | ||
"description": "JavaScript AsyncAPI parser.", | ||
@@ -27,3 +27,3 @@ "main": "lib/index.js", | ||
"lint:fix": "eslint --max-warnings 0 --config \".eslintrc\" \".\" --fix", | ||
"test:lib": "nyc --silent --no-clean mocha --exclude \"test/browser_test.js\" --exclude \"test/parseFromUrl_test.js\" --recursive", | ||
"test:lib": "npm run test:browser:cleanup && nyc --silent --no-clean mocha --exclude \"test/browser_test.js\" --exclude \"test/parseFromUrl_test.js\" --recursive", | ||
"test:parseFromUrl": "nyc --silent --no-clean start-server-and-test \"http-server test/sample_browser --cors -s\" 8080 \"mocha test/parseFromUrl_test.js\"", | ||
@@ -70,3 +70,3 @@ "cover:report": "nyc report --reporter=text --reporter=html", | ||
"nyc": "^15.1.0", | ||
"puppeteer": "^7.0.1", | ||
"puppeteer": "^17.0.0", | ||
"rimraf": "^3.0.2", | ||
@@ -73,0 +73,0 @@ "semantic-release": "19.0.3", |
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
1389951
8701