diff --git a/config/webpack/browser.config.babel.js b/config/webpack/browser.config.babel.js index 0a6b7683e..bd9a0ee29 100644 --- a/config/webpack/browser.config.babel.js +++ b/config/webpack/browser.config.babel.js @@ -63,7 +63,7 @@ const browserMin = { devtool: 'source-map', performance: { hints: 'error', - maxEntrypointSize: 460000, + maxEntrypointSize: 470000, maxAssetSize: 50000000, }, output: { diff --git a/package-lock.json b/package-lock.json index 9f3e9ded5..e365cb51b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,11 +18,11 @@ "cookie": "~0.6.0", "deepmerge": "~4.3.0", "fast-json-patch": "^3.0.0-1", - "is-plain-object": "^5.0.0", "js-yaml": "^4.1.0", "node-abort-controller": "^3.1.1", "node-fetch-commonjs": "^3.3.2", "openapi-path-templating": "^1.5.1", + "openapi-server-url-templating": "^1.0.0", "qs": "^6.10.2", "ramda-adjunct": "^5.0.0", "traverse": "=0.6.8" @@ -8157,14 +8157,6 @@ "node": ">=8" } }, - "node_modules/is-plain-object": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", - "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/is-potential-custom-element-name": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", @@ -11688,6 +11680,17 @@ "node": ">=12.20.0" } }, + "node_modules/openapi-server-url-templating": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/openapi-server-url-templating/-/openapi-server-url-templating-1.0.0.tgz", + "integrity": "sha512-hJ3sCVx7XyYATfRqBfUY+dE+DSM/tsqZ83xtcyHhNqtDiN2Il/uedCzBaE9re3gLRkC4I0GrCI84aaQHboNMCw==", + "dependencies": { + "apg-lite": "^1.0.3" + }, + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", diff --git a/package.json b/package.json index ab1626195..bc62a5db6 100644 --- a/package.json +++ b/package.json @@ -81,11 +81,11 @@ "cookie": "~0.6.0", "deepmerge": "~4.3.0", "fast-json-patch": "^3.0.0-1", - "is-plain-object": "^5.0.0", "js-yaml": "^4.1.0", "node-abort-controller": "^3.1.1", "node-fetch-commonjs": "^3.3.2", "openapi-path-templating": "^1.5.1", + "openapi-server-url-templating": "^1.0.0", "qs": "^6.10.2", "ramda-adjunct": "^5.0.0", "traverse": "=0.6.8" diff --git a/src/execute/index.js b/src/execute/index.js index 38d4836f6..00571f429 100755 --- a/src/execute/index.js +++ b/src/execute/index.js @@ -1,6 +1,9 @@ import cookie from 'cookie'; -import { isPlainObject } from 'is-plain-object'; -import { escapeRegExp } from 'ramda-adjunct'; +import { isPlainObject } from 'ramda-adjunct'; +import { + test as testServerURLTemplate, + substitute as substituteServerURLTemplate, +} from 'openapi-server-url-templating'; import { ApiDOMStructuredError } from '@swagger-api/apidom-error'; import { url } from '@swagger-api/apidom-reference/configuration/empty'; @@ -347,18 +350,18 @@ function oas3BaseUrl({ spec, pathName, method, server, contextUrl, serverVariabl selectedServerUrl = selectedServerObj.url; } - if (selectedServerUrl.includes('{')) { - // do variable substitution - const varNames = extractServerVariableNames(selectedServerUrl); - varNames.forEach((variable) => { - if (selectedServerObj.variables && selectedServerObj.variables[variable]) { - // variable is defined in server - const variableDefinition = selectedServerObj.variables[variable]; - const variableValue = serverVariables[variable] || variableDefinition.default; - - const re = new RegExp(`{${escapeRegExp(variable)}}`, 'g'); - selectedServerUrl = selectedServerUrl.replace(re, variableValue); - } + if (testServerURLTemplate(selectedServerUrl, { strict: true })) { + const selectedServerVariables = Object.entries({ ...selectedServerObj.variables }).reduce( + (acc, [serverVariableName, serverVariable]) => { + acc[serverVariableName] = serverVariable.default; + return acc; + }, + {} + ); + + selectedServerUrl = substituteServerURLTemplate(selectedServerUrl, { + ...selectedServerVariables, + ...serverVariables, }); } @@ -390,11 +393,6 @@ function buildOas3UrlWithContext(ourUrl = '', contextUrl = '') { return res[res.length - 1] === '/' ? res.slice(0, -1) : res; } -function extractServerVariableNames(serverURL) { - const match = serverURL.matchAll(/\{([^{}]+)}|([^{}]+)/g); - return Array.from(match, ([, variable]) => variable).filter(Boolean); -} - // Compose the baseUrl ( scheme + host + basePath ) function swagger2BaseUrl({ spec, scheme, contextUrl = '' }) { const parsedContextUrl = parseURIReference(contextUrl); diff --git a/src/execute/oas3/build-request.js b/src/execute/oas3/build-request.js index 0f5510cf4..a217f781b 100644 --- a/src/execute/oas3/build-request.js +++ b/src/execute/oas3/build-request.js @@ -1,6 +1,6 @@ // This function runs after the common function, // `src/execute/index.js#buildRequest` -import { isPlainObject } from 'is-plain-object'; +import { isPlainObject } from 'ramda-adjunct'; import btoa from '../../helpers/btoa.node.js';