From a7a5423b0c6b10a1745e7cd7424295b6c70a9cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Thu, 15 Sep 2022 11:27:41 +0200 Subject: [PATCH] chore: update next-spec branch with master changes (#606) --- .eslintrc | 1 + .github/workflows/if-nodejs-release.yml | 18 ++ .github/workflows/if-nodejs-version-bump.yml | 18 +- .github/workflows/link-check-cron.yml | 2 +- .github/workflows/stale-issues-prs.yml | 5 +- lib/asyncapiSchemaFormatParser.js | 17 +- lib/parser.js | 30 ++- lib/utils.js | 17 ++ package-lock.json | 239 ++++++++++++------- package.json | 8 +- test/browser_test.js | 5 +- test/parseFromUrl_test.js | 8 +- test/refs/refed.yaml | 2 +- test/sample_browser/asyncapi.yaml | 8 - test/sample_browser/index.html | 75 ++++-- test/sample_browser/main/asyncapi.yaml | 25 ++ test/sample_browser/refs/refed.yaml | 6 + test/sample_browser/refs/refed2.yaml | 1 + test/utils_test.js | 14 ++ 19 files changed, 358 insertions(+), 141 deletions(-) delete mode 100644 test/sample_browser/asyncapi.yaml create mode 100644 test/sample_browser/main/asyncapi.yaml create mode 100644 test/sample_browser/refs/refed.yaml create mode 100644 test/sample_browser/refs/refed2.yaml create mode 100644 test/utils_test.js diff --git a/.eslintrc b/.eslintrc index 329b5967f..e17fc6c2f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,6 +2,7 @@ env: node: true es6: true mocha: true + browser: true plugins: - sonarjs diff --git a/.github/workflows/if-nodejs-release.yml b/.github/workflows/if-nodejs-release.yml index bc5b53766..16cc8851b 100644 --- a/.github/workflows/if-nodejs-release.yml +++ b/.github/workflows/if-nodejs-release.yml @@ -48,6 +48,15 @@ jobs: - if: steps.packagejson.outputs.exists == 'true' name: Run test run: npm test + - if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel + name: Report workflow run status to Slack + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + fields: repo,action,workflow + text: 'Release workflow failed in testing job' + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} release: needs: [test-nodejs] @@ -84,3 +93,12 @@ jobs: GIT_COMMITTER_NAME: asyncapi-bot GIT_COMMITTER_EMAIL: info@asyncapi.io run: npm run release + - if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel + name: Report workflow run status to Slack + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + fields: repo,action,workflow + text: 'Release workflow failed in release job' + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} \ No newline at end of file diff --git a/.github/workflows/if-nodejs-version-bump.yml b/.github/workflows/if-nodejs-version-bump.yml index 721caa9d7..5e7aa14ac 100644 --- a/.github/workflows/if-nodejs-version-bump.yml +++ b/.github/workflows/if-nodejs-version-bump.yml @@ -24,6 +24,13 @@ jobs: - name: Check if Node.js project and has package.json id: packagejson run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false" + - if: steps.packagejson.outputs.exists == 'true' + name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: 14 + cache: 'npm' + cache-dependency-path: '**/package-lock.json' - if: steps.packagejson.outputs.exists == 'true' name: Install dependencies run: npm install @@ -46,4 +53,13 @@ jobs: author: asyncapi-bot title: 'chore(release): ${{github.event.release.tag_name}}' body: 'Version bump in package.json for release [${{github.event.release.tag_name}}](${{github.event.release.html_url}})' - branch: version-bump/${{github.event.release.tag_name}} \ No newline at end of file + branch: version-bump/${{github.event.release.tag_name}} + - if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel + name: Report workflow run status to Slack + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + fields: repo,action,workflow + text: 'Unable to bump the version in package.json after the release' + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} \ No newline at end of file diff --git a/.github/workflows/link-check-cron.yml b/.github/workflows/link-check-cron.yml index 44e1a5cb0..2d1e1fc02 100644 --- a/.github/workflows/link-check-cron.yml +++ b/.github/workflows/link-check-cron.yml @@ -34,4 +34,4 @@ jobs: fields: repo,action,workflow env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} - if: failure() # Only, on failure, send a message on the Slack Docs Channel (if there are broken links) + if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel diff --git a/.github/workflows/stale-issues-prs.yml b/.github/workflows/stale-issues-prs.yml index c1c0c61da..5dc053a49 100644 --- a/.github/workflows/stale-issues-prs.yml +++ b/.github/workflows/stale-issues-prs.yml @@ -13,7 +13,7 @@ jobs: name: Mark issue or PR as stale runs-on: ubuntu-latest steps: - - uses: actions/stale@v4.0.0 + - uses: actions/stale@v5.1.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} stale-issue-message: | @@ -41,4 +41,5 @@ jobs: stale-issue-label: stale stale-pr-label: stale exempt-issue-labels: keep-open - exempt-pr-labels: keep-open \ No newline at end of file + exempt-pr-labels: keep-open + close-issue-reason: not_planned diff --git a/lib/asyncapiSchemaFormatParser.js b/lib/asyncapiSchemaFormatParser.js index c303f5f16..7b3b60c90 100644 --- a/lib/asyncapiSchemaFormatParser.js +++ b/lib/asyncapiSchemaFormatParser.js @@ -7,7 +7,7 @@ const cloneDeep = require('lodash.clonedeep'); const ajv = new Ajv({ jsonPointers: true, allErrors: true, - schemaId: 'id', + schemaId: 'auto', logger: false, }); ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); @@ -68,7 +68,8 @@ function getMimeTypes() { function getValidator(version) { let validate = ajv.getSchema(version); if (!validate) { - ajv.addSchema(preparePayloadSchema(asyncapi[String(version)]), version); + const payloadSchema = preparePayloadSchema(asyncapi[String(version)], version); + ajv.addSchema(payloadSchema, version); validate = ajv.getSchema(version); } return validate; @@ -80,12 +81,18 @@ function getValidator(version) { * * @private * @param {Object} asyncapiSchema AsyncAPI specification JSON Schema + * @param {Object} version AsyncAPI version. * @returns {Object} valid JSON Schema document describing format of AsyncAPI-valid schema for message payload */ -function preparePayloadSchema(asyncapiSchema) { +function preparePayloadSchema(asyncapiSchema, version) { + const payloadSchema = `http://asyncapi.com/definitions/${version}/schema.json`; + const definitions = asyncapiSchema.definitions; + // Remove the meta schemas because it is already present within Ajv, and it's not possible to add duplicate schemas. + delete definitions['http://json-schema.org/draft-07/schema']; + delete definitions['http://json-schema.org/draft-04/schema']; return { - $ref: '#/definitions/schema', - definitions: asyncapiSchema.definitions + $ref: payloadSchema, + definitions }; } diff --git a/lib/parser.js b/lib/parser.js index f756fcae9..f7c123a01 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -6,7 +6,14 @@ const $RefParser = require('@apidevtools/json-schema-ref-parser'); const mergePatch = require('tiny-merge-patch').apply; const ParserError = require('./errors/parser-error'); 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'); const OPERATIONS = ['publish', 'subscribe']; @@ -19,8 +26,9 @@ const xParserMessageParsed = 'x-parser-message-parsed'; const ajv = new Ajv({ jsonPointers: true, allErrors: true, - schemaId: 'id', + schemaId: 'auto', logger: false, + validateSchema: true, }); ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); @@ -55,7 +63,11 @@ async function parse(asyncapiYAMLorJSON, options = {}) { let parsedJSON; let initialFormat; - 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}`; + } try { ({ initialFormat, parsedJSON } = toJS(asyncapiYAMLorJSON)); @@ -127,12 +139,16 @@ async function parse(asyncapiYAMLorJSON, options = {}) { * @param {ParserOptions=} [options] Configuration to pass to the {@link #asyncapiparserparseroptions--object|ParserOptions} method. * @returns {Promise} The parsed AsyncAPI document. */ -function parseFromUrl(url, fetchOptions, options) { +function parseFromUrl(url, fetchOptions, options = {}) { //Why not just addinga default to the arguments list? //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. //To not break the API by changing argument position and to silet the linter it is just better to move adding if (!fetchOptions) fetchOptions = {}; + if (!options.hasOwnProperty('path')) { + options = { ...options, path: getBaseUrl(url) }; + } + return new Promise((resolve, reject) => { fetch(url, fetchOptions) .then(res => res.text()) @@ -186,7 +202,11 @@ async function handleCircularRefs(refParser, parsedJSON, initialFormat, asyncapi function getValidator(version) { let validate = ajv.getSchema(version); if (!validate) { - ajv.addSchema(asyncapi[String(version)], version); + const asyncapiSchema = asyncapi[String(version)]; + // Remove the meta schemas because it is already present within Ajv, and it's not possible to add duplicate schemas. + delete asyncapiSchema.definitions['http://json-schema.org/draft-07/schema']; + delete asyncapiSchema.definitions['http://json-schema.org/draft-04/schema']; + ajv.addSchema(asyncapiSchema, version); validate = ajv.getSchema(version); } return validate; diff --git a/lib/utils.js b/lib/utils.js index 0faf2e0c0..e80b5a381 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -219,6 +219,23 @@ utils.parseUrlQueryParameters = str => { return str.match(/\?((.*=.*)(&?))/g); }; +/** + * 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 * @function getMissingProps diff --git a/package-lock.json b/package-lock.json index 8ce09a833..8dfa092cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,16 @@ { "name": "@asyncapi/parser", - "version": "1.15.1", + "version": "1.16.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@asyncapi/parser", - "version": "1.15.1", + "version": "1.16.0", "license": "Apache-2.0", "dependencies": { "@apidevtools/json-schema-ref-parser": "^9.0.6", - "@asyncapi/specs": "^2.14.0", + "@asyncapi/specs": "^3.0.0", "@fmvilas/pseudo-yaml-ast": "^0.3.1", "ajv": "^6.10.1", "js-yaml": "^3.13.1", @@ -39,7 +39,7 @@ "mkdirp": "^1.0.4", "mocha": "^6.1.4", "nyc": "^15.1.0", - "puppeteer": "^7.0.1", + "puppeteer": "^17.0.0", "rimraf": "^3.0.2", "semantic-release": "19.0.3", "shx": "^0.3.3", @@ -59,9 +59,9 @@ } }, "node_modules/@asyncapi/specs": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-2.14.0.tgz", - "integrity": "sha512-hHsYF6XsYNIKb1P2rXaooF4H+uKKQ4b/Ljxrk3rZ3riEDiSxMshMEfb1fUlw9Yj4V4OmJhjXwkNvw8W59AXv1A==" + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-3.1.0.tgz", + "integrity": "sha512-6xFvzDd54+M9g6EM259Y4a4iiFb2VzPr6eoxA/ttwTu7NRxaGScocXskXtuz53ZWx9BWZWuzwDYKfM3KBkDfiQ==" }, "node_modules/@babel/code-frame": { "version": "7.8.3", @@ -993,9 +993,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "13.13.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.0.tgz", - "integrity": "sha512-WE4IOAC6r/yBZss1oQGM5zs2D7RuKR6Q+w+X2SouPofnWn+LbCqClRyhO3ZE7Ix8nmFgo/oVuuE01cJT2XB13A==", + "version": "18.7.18", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.18.tgz", + "integrity": "sha512-m+6nTEOadJZuTPkKR/SYK3A2d7FZrgElol9UP1Kae90VVU4a6mxnPuLiIW1m4Cq4gZ/nWb9GrdVXJCoCazDAbg==", "dev": true, "optional": true }, @@ -1018,9 +1018,9 @@ "dev": true }, "node_modules/@types/yauzl": { - "version": "2.9.1", - "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.1.tgz", - "integrity": "sha512-A1b8SU4D10uoPjwb0lnHmmu8wZhR9d+9o2PKBQT2jU5YPTKsxac6M2qGAdY7VcL+dHHhARVUDmeg0rOrcd9EjA==", + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==", "dev": true, "optional": true, "dependencies": { @@ -1448,9 +1448,9 @@ "dev": true }, "node_modules/bl": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.3.tgz", - "integrity": "sha512-fs4G6/Hu4/EE+F75J8DuN/0IpQqNjAdC7aEQv7Qt8MHGUH7Ckv2MwTEEeN9QehD0pfIDkMI1bkHYkKy7xHyKIg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", + "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", "dev": true, "dependencies": { "buffer": "^5.5.0", @@ -1774,7 +1774,7 @@ "node_modules/buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=", + "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", "dev": true, "engines": { "node": "*" @@ -2564,6 +2564,15 @@ "sha.js": "^2.4.8" } }, + "node_modules/cross-fetch": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", + "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==", + "dev": true, + "dependencies": { + "node-fetch": "2.6.7" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -2851,9 +2860,9 @@ } }, "node_modules/devtools-protocol": { - "version": "0.0.847576", - "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.847576.tgz", - "integrity": "sha512-0M8kobnSQE0Jmly7Mhbeq0W/PpZfnuK+WjN2ZRVPbGqYwCHCioAVp84H0TcLimgECcN5H976y5QiXMGBC9JKmg==", + "version": "0.0.1036444", + "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1036444.tgz", + "integrity": "sha512-0y4f/T8H9lsESV9kKP1HDUXgHxCdniFeJh6Erq+FbdOEvp/Ydp9t8kcAAM5gOd17pMrTDlFWntoHtzzeTUWKNw==", "dev": true }, "node_modules/diacritics-map": { @@ -4055,7 +4064,7 @@ "node_modules/fd-slicer": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", - "integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=", + "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", "dev": true, "dependencies": { "pend": "~1.2.0" @@ -10312,7 +10321,7 @@ "node_modules/pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", - "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=", + "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", "dev": true }, "node_modules/picomatch": { @@ -10566,27 +10575,56 @@ } }, "node_modules/puppeteer": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-7.0.1.tgz", - "integrity": "sha512-04V05BKQdloUCOa7JyQBaNXPIiVByz1eAFAElcrpMHIQkfu22J0RKFhRWkXZGXdl03yoHuaZwqyB/qG7YJu5Ew==", + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-17.1.3.tgz", + "integrity": "sha512-tVtvNSOOqlq75rUgwLeDAEQoLIiBqmRg0/zedpI6fuqIocIkuxG23A7FIl1oVSkuSMMLgcOP5kVhNETmsmjvPw==", "dev": true, "hasInstallScript": true, "dependencies": { - "debug": "^4.1.0", - "devtools-protocol": "0.0.847576", - "extract-zip": "^2.0.0", - "https-proxy-agent": "^5.0.0", - "node-fetch": "^2.6.1", - "pkg-dir": "^4.2.0", - "progress": "^2.0.1", - "proxy-from-env": "^1.0.0", - "rimraf": "^3.0.2", - "tar-fs": "^2.0.0", - "unbzip2-stream": "^1.3.3", - "ws": "^7.2.3" + "cross-fetch": "3.1.5", + "debug": "4.3.4", + "devtools-protocol": "0.0.1036444", + "extract-zip": "2.0.1", + "https-proxy-agent": "5.0.1", + "progress": "2.0.3", + "proxy-from-env": "1.1.0", + "rimraf": "3.0.2", + "tar-fs": "2.1.1", + "unbzip2-stream": "1.4.3", + "ws": "8.8.1" + }, + "engines": { + "node": ">=14.1.0" + } + }, + "node_modules/puppeteer/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "dependencies": { + "ms": "2.1.2" }, "engines": { - "node": ">=10.18.1" + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/puppeteer/node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "dev": true, + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" } }, "node_modules/q": { @@ -14324,9 +14362,9 @@ } }, "node_modules/shell-quote": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.7.2.tgz", - "integrity": "sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==", + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.7.3.tgz", + "integrity": "sha512-Vpfqwm4EnqGdlsBFNmHhxhElJYrdfcxPThu+ryKS5J8L/fhAwLazFZtq+S+TWZ9ANj2piSQLGj6NQg+lKPmxrw==", "dev": true }, "node_modules/shelljs": { @@ -15843,12 +15881,12 @@ } }, "node_modules/ws": { - "version": "7.4.6", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", - "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.8.1.tgz", + "integrity": "sha512-bGy2JzvzkPowEJV++hF07hAD6niYSr0JzBNo/J29WsB57A2r7Wlc1UFcTR9IzrPvuNVO4B8LGqF8qcpsVOhJCA==", "dev": true, "engines": { - "node": ">=8.3.0" + "node": ">=10.0.0" }, "peerDependencies": { "bufferutil": "^4.0.1", @@ -16054,7 +16092,7 @@ "node_modules/yauzl": { "version": "2.10.0", "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", - "integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=", + "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", "dev": true, "dependencies": { "buffer-crc32": "~0.2.3", @@ -16074,9 +16112,9 @@ } }, "@asyncapi/specs": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-2.14.0.tgz", - "integrity": "sha512-hHsYF6XsYNIKb1P2rXaooF4H+uKKQ4b/Ljxrk3rZ3riEDiSxMshMEfb1fUlw9Yj4V4OmJhjXwkNvw8W59AXv1A==" + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-3.1.0.tgz", + "integrity": "sha512-6xFvzDd54+M9g6EM259Y4a4iiFb2VzPr6eoxA/ttwTu7NRxaGScocXskXtuz53ZWx9BWZWuzwDYKfM3KBkDfiQ==" }, "@babel/code-frame": { "version": "7.8.3", @@ -16876,9 +16914,9 @@ "dev": true }, "@types/node": { - "version": "13.13.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.0.tgz", - "integrity": "sha512-WE4IOAC6r/yBZss1oQGM5zs2D7RuKR6Q+w+X2SouPofnWn+LbCqClRyhO3ZE7Ix8nmFgo/oVuuE01cJT2XB13A==", + "version": "18.7.18", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.18.tgz", + "integrity": "sha512-m+6nTEOadJZuTPkKR/SYK3A2d7FZrgElol9UP1Kae90VVU4a6mxnPuLiIW1m4Cq4gZ/nWb9GrdVXJCoCazDAbg==", "dev": true, "optional": true }, @@ -16901,9 +16939,9 @@ "dev": true }, "@types/yauzl": { - "version": "2.9.1", - "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.1.tgz", - "integrity": "sha512-A1b8SU4D10uoPjwb0lnHmmu8wZhR9d+9o2PKBQT2jU5YPTKsxac6M2qGAdY7VcL+dHHhARVUDmeg0rOrcd9EjA==", + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==", "dev": true, "optional": true, "requires": { @@ -17259,9 +17297,9 @@ "dev": true }, "bl": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.3.tgz", - "integrity": "sha512-fs4G6/Hu4/EE+F75J8DuN/0IpQqNjAdC7aEQv7Qt8MHGUH7Ckv2MwTEEeN9QehD0pfIDkMI1bkHYkKy7xHyKIg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", + "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", "dev": true, "requires": { "buffer": "^5.5.0", @@ -17563,7 +17601,7 @@ "buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=", + "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", "dev": true }, "buffer-from": { @@ -18208,6 +18246,15 @@ "sha.js": "^2.4.8" } }, + "cross-fetch": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", + "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==", + "dev": true, + "requires": { + "node-fetch": "2.6.7" + } + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -18440,9 +18487,9 @@ } }, "devtools-protocol": { - "version": "0.0.847576", - "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.847576.tgz", - "integrity": "sha512-0M8kobnSQE0Jmly7Mhbeq0W/PpZfnuK+WjN2ZRVPbGqYwCHCioAVp84H0TcLimgECcN5H976y5QiXMGBC9JKmg==", + "version": "0.0.1036444", + "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1036444.tgz", + "integrity": "sha512-0y4f/T8H9lsESV9kKP1HDUXgHxCdniFeJh6Erq+FbdOEvp/Ydp9t8kcAAM5gOd17pMrTDlFWntoHtzzeTUWKNw==", "dev": true }, "diacritics-map": { @@ -19393,7 +19440,7 @@ "fd-slicer": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", - "integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=", + "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", "dev": true, "requires": { "pend": "~1.2.0" @@ -24132,7 +24179,7 @@ "pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", - "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=", + "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", "dev": true }, "picomatch": { @@ -24326,23 +24373,43 @@ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" }, "puppeteer": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-7.0.1.tgz", - "integrity": "sha512-04V05BKQdloUCOa7JyQBaNXPIiVByz1eAFAElcrpMHIQkfu22J0RKFhRWkXZGXdl03yoHuaZwqyB/qG7YJu5Ew==", + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-17.1.3.tgz", + "integrity": "sha512-tVtvNSOOqlq75rUgwLeDAEQoLIiBqmRg0/zedpI6fuqIocIkuxG23A7FIl1oVSkuSMMLgcOP5kVhNETmsmjvPw==", "dev": true, "requires": { - "debug": "^4.1.0", - "devtools-protocol": "0.0.847576", - "extract-zip": "^2.0.0", - "https-proxy-agent": "^5.0.0", - "node-fetch": "^2.6.1", - "pkg-dir": "^4.2.0", - "progress": "^2.0.1", - "proxy-from-env": "^1.0.0", - "rimraf": "^3.0.2", - "tar-fs": "^2.0.0", - "unbzip2-stream": "^1.3.3", - "ws": "^7.2.3" + "cross-fetch": "3.1.5", + "debug": "4.3.4", + "devtools-protocol": "0.0.1036444", + "extract-zip": "2.0.1", + "https-proxy-agent": "5.0.1", + "progress": "2.0.3", + "proxy-from-env": "1.1.0", + "rimraf": "3.0.2", + "tar-fs": "2.1.1", + "unbzip2-stream": "1.4.3", + "ws": "8.8.1" + }, + "dependencies": { + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "dev": true, + "requires": { + "agent-base": "6", + "debug": "4" + } + } } }, "q": { @@ -27018,9 +27085,9 @@ "dev": true }, "shell-quote": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.7.2.tgz", - "integrity": "sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==", + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.7.3.tgz", + "integrity": "sha512-Vpfqwm4EnqGdlsBFNmHhxhElJYrdfcxPThu+ryKS5J8L/fhAwLazFZtq+S+TWZ9ANj2piSQLGj6NQg+lKPmxrw==", "dev": true }, "shelljs": { @@ -28275,9 +28342,9 @@ } }, "ws": { - "version": "7.4.6", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", - "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.8.1.tgz", + "integrity": "sha512-bGy2JzvzkPowEJV++hF07hAD6niYSr0JzBNo/J29WsB57A2r7Wlc1UFcTR9IzrPvuNVO4B8LGqF8qcpsVOhJCA==", "dev": true, "requires": {} }, @@ -28435,7 +28502,7 @@ "yauzl": { "version": "2.10.0", "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", - "integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=", + "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", "dev": true, "requires": { "buffer-crc32": "~0.2.3", diff --git a/package.json b/package.json index a2176e2a9..454088da4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@asyncapi/parser", - "version": "1.15.1", + "version": "1.16.0", "description": "JavaScript AsyncAPI parser.", "main": "lib/index.js", "types": "types.d.ts", @@ -24,7 +24,7 @@ "release": "semantic-release", "lint": "eslint --max-warnings 0 --config \".eslintrc\" \".\"", "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\"", "cover:report": "nyc report --reporter=text --reporter=html", "test:browser": "npm run test:browser:cleanup && npm run bundle && shx cp \"dist/bundle.js\" \"test/sample_browser/\" && start-server-and-test \"http-server test/sample_browser --cors -s\" 8080 \"mocha --timeout 20000 test/browser_test.js\" && npm run test:browser:cleanup", @@ -66,7 +66,7 @@ "mkdirp": "^1.0.4", "mocha": "^6.1.4", "nyc": "^15.1.0", - "puppeteer": "^7.0.1", + "puppeteer": "^17.0.0", "rimraf": "^3.0.2", "semantic-release": "19.0.3", "shx": "^0.3.3", @@ -76,7 +76,7 @@ }, "dependencies": { "@apidevtools/json-schema-ref-parser": "^9.0.6", - "@asyncapi/specs": "^2.14.0", + "@asyncapi/specs": "^3.0.0", "@fmvilas/pseudo-yaml-ast": "^0.3.1", "ajv": "^6.10.1", "js-yaml": "^3.13.1", diff --git a/test/browser_test.js b/test/browser_test.js index a32acf0af..5cd48f41f 100644 --- a/test/browser_test.js +++ b/test/browser_test.js @@ -28,8 +28,9 @@ describe('Check Parser in the browser', function() { try { console.info('getting fromString element'); const specString = await page.$('#fromString'); + const content = await page.evaluate(element => element.textContent, specString); - expect(content).to.be.equal('2.0.0'); + expect(content).to.be.equal('{"asyncapi":"2.4.0","info":{"title":"Account Service","version":"1.0.0","description":"This service is in charge of processing user signups"},"channels":{"user/signedup":{"subscribe":{"message":{"payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user","x-parser-schema-id":""},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}},"x-parser-schema-id":""}},"x-parser-schema-id":""},"x-parser-original-schema-format":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-original-payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user"},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}}}}},"schemaFormat":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-message-parsed":true,"x-parser-message-name":"UserSignedUp"}}}},"components":{"messages":{"UserSignedUp":{"payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user","x-parser-schema-id":""},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}},"x-parser-schema-id":""}},"x-parser-schema-id":""},"x-parser-original-schema-format":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-original-payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user"},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}}}}},"schemaFormat":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-message-parsed":true,"x-parser-message-name":"UserSignedUp"}}},"x-parser-spec-parsed":true}'); } catch (e) { throw new Error(e); } @@ -47,7 +48,7 @@ describe('Check Parser in the browser', function() { const specUrl = await page.$('#fromUrl'); const content = await page.evaluate(element => element.textContent, specUrl); - expect(content).to.be.equal('2.0.0'); + expect(content).to.be.equal('{"asyncapi":"2.4.0","info":{"title":"Account Service","version":"1.0.0","description":"This service is in charge of processing user signups"},"channels":{"user/signedup":{"subscribe":{"message":{"payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user","x-parser-schema-id":""},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}},"x-parser-schema-id":""}},"x-parser-schema-id":""},"x-parser-original-schema-format":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-original-payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user"},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}}}}},"schemaFormat":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-message-parsed":true,"x-parser-message-name":"UserSignedUp"}}}},"components":{"messages":{"UserSignedUp":{"payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user","x-parser-schema-id":""},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}},"x-parser-schema-id":""}},"x-parser-schema-id":""},"x-parser-original-schema-format":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-original-payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user"},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}}}}},"schemaFormat":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-message-parsed":true,"x-parser-message-name":"UserSignedUp"}}},"x-parser-spec-parsed":true}'); } catch (e) { throw new Error(e); } diff --git a/test/parseFromUrl_test.js b/test/parseFromUrl_test.js index aa4a33ca0..b3d285ff6 100644 --- a/test/parseFromUrl_test.js +++ b/test/parseFromUrl_test.js @@ -6,18 +6,18 @@ const { checkErrorWrapper } = require('./testsUtils'); chai.use(chaiAsPromised); const expect = chai.expect; -const validOutputJSON = '{"asyncapi":"2.0.0","info":{"title":"My API","version":"1.0.0"},"channels":{"/test/tester":{"subscribe":{"message":{"schemaFormat":"application/vnd.aai.asyncapi;version=2.0.0","x-parser-message-parsed":true,"x-parser-message-name":""}}}},"x-parser-spec-parsed":true}'; +const validOutputJSON = '{"asyncapi":"2.4.0","info":{"title":"Account Service","version":"1.0.0","description":"This service is in charge of processing user signups"},"channels":{"user/signedup":{"subscribe":{"message":{"payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user","x-parser-schema-id":""},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}},"x-parser-schema-id":""}},"x-parser-schema-id":""},"x-parser-original-schema-format":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-original-payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user"},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}}}}},"schemaFormat":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-message-parsed":true,"x-parser-message-name":"UserSignedUp"}}}},"components":{"messages":{"UserSignedUp":{"payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user","x-parser-schema-id":""},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}},"x-parser-schema-id":""}},"x-parser-schema-id":""},"x-parser-original-schema-format":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-original-payload":{"type":"object","properties":{"displayName":{"type":"string","description":"Name of the user"},"email":{"type":"string","format":"email","description":"Email of the user","test":{"type":"object","properties":{"testing1":{"type":"string"},"testing2":{"type":"string"}}}}}},"schemaFormat":"application/vnd.aai.asyncapi;version=2.4.0","x-parser-message-parsed":true,"x-parser-message-name":"UserSignedUp"}}},"x-parser-spec-parsed":true}'; describe('parseFromUrl()', function() { it('should parse YAML correctly from URL', async function() { - const result = await parser.parseFromUrl('http://localhost:8080/asyncapi.yaml'); + const result = await parser.parseFromUrl('http://localhost:8080/main/asyncapi.yaml'); expect(JSON.stringify(result.json())).to.equal(validOutputJSON); }); it('should parse 2 AsyncAPI specs in Promise.all() from URL', async function() { const input = [ - parser.parseFromUrl('http://localhost:8080/asyncapi.yaml'), - parser.parseFromUrl('http://localhost:8080/asyncapi.yaml') + parser.parseFromUrl('http://localhost:8080/main/asyncapi.yaml'), + parser.parseFromUrl('http://localhost:8080/main/asyncapi.yaml') ]; const result = await Promise.all(input); expect(JSON.stringify(result[0].json())).to.equal(validOutputJSON); diff --git a/test/refs/refed.yaml b/test/refs/refed.yaml index 1b912b83b..7a154eeba 100644 --- a/test/refs/refed.yaml +++ b/test/refs/refed.yaml @@ -1,4 +1,4 @@ type: object properties: testing: - $ref: 'refed2.yaml' + $ref: './refed2.yaml' diff --git a/test/sample_browser/asyncapi.yaml b/test/sample_browser/asyncapi.yaml deleted file mode 100644 index 95eaabca1..000000000 --- a/test/sample_browser/asyncapi.yaml +++ /dev/null @@ -1,8 +0,0 @@ -asyncapi: 2.0.0 -info: - title: My API - version: 1.0.0 -channels: - "/test/tester": - subscribe: - message: {} \ No newline at end of file diff --git a/test/sample_browser/index.html b/test/sample_browser/index.html index e24c90c1a..5000ba965 100644 --- a/test/sample_browser/index.html +++ b/test/sample_browser/index.html @@ -1,27 +1,58 @@ - -
-
+ + + + + + + AsyncAPI document parsing test + + - \ No newline at end of file + + + +

#fromString

+
+
+
+

#fromUrl

+ + + diff --git a/test/sample_browser/main/asyncapi.yaml b/test/sample_browser/main/asyncapi.yaml new file mode 100644 index 000000000..bf4deb469 --- /dev/null +++ b/test/sample_browser/main/asyncapi.yaml @@ -0,0 +1,25 @@ +asyncapi: '2.4.0' +info: + title: Account Service + version: 1.0.0 + description: This service is in charge of processing user signups +channels: + user/signedup: + subscribe: + message: + $ref: '#/components/messages/UserSignedUp' +components: + messages: + UserSignedUp: + payload: + type: object + properties: + displayName: + type: string + description: Name of the user + email: + type: string + format: email + description: Email of the user + test: + $ref: '../refs/refed.yaml' \ No newline at end of file diff --git a/test/sample_browser/refs/refed.yaml b/test/sample_browser/refs/refed.yaml new file mode 100644 index 000000000..5f6488eff --- /dev/null +++ b/test/sample_browser/refs/refed.yaml @@ -0,0 +1,6 @@ +type: object +properties: + testing1: + $ref: "./refed2.yaml" + testing2: + $ref: "http://localhost:8080/refs/refed2.yaml" diff --git a/test/sample_browser/refs/refed2.yaml b/test/sample_browser/refs/refed2.yaml new file mode 100644 index 000000000..5c21d88b9 --- /dev/null +++ b/test/sample_browser/refs/refed2.yaml @@ -0,0 +1 @@ +type: string diff --git a/test/utils_test.js b/test/utils_test.js new file mode 100644 index 000000000..352631447 --- /dev/null +++ b/test/utils_test.js @@ -0,0 +1,14 @@ +const chai = require('chai'); +const chaiAsPromised = require('chai-as-promised'); +const { getBaseUrl } = require('../lib/utils'); + +chai.use(chaiAsPromised); +const expect = chai.expect; + +describe('getBaseUrl()', function () { + it('should accept totally valid absolute URL of an AsyncAPI document', async function () { + await expect( + getBaseUrl('https://asyncapi.com/good/asyncapi.yaml') + ).to.equal('https://asyncapi.com/good/'); + }); +});