@api-components/amf-helper-mixin
Advanced tools
Comparing version 4.1.9 to 4.2.0
{ | ||
"name": "@api-components/amf-helper-mixin", | ||
"description": "A mixin with common functions user by most AMF components to compyte AMF values", | ||
"version": "4.1.9", | ||
"version": "4.2.0", | ||
"license": "Apache-2.0", | ||
@@ -31,3 +31,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@advanced-rest-client/testing-karma-sl": "^1.3.1", | ||
"@advanced-rest-client/testing-karma-sl": "^1.4.3", | ||
"@api-components/api-model-generator": "^0.2.8", | ||
@@ -34,0 +34,0 @@ "@open-wc/eslint-config": "^2.0.0", |
@@ -689,16 +689,19 @@ /** | ||
* @param {boolean=} [opts.ignoreBase = false] Whether or not to ignore rendering | ||
* @param {string[]=} [opts.protocols] List of available protocols | ||
* of the base URI with path. | ||
* @return {string} The base uri for the endpoint. | ||
*/ | ||
_computeUri(endpoint, { server, baseUri, version, ignoreBase=false } = {}) { | ||
_computeUri(endpoint, { server, baseUri, version, ignoreBase=false, protocols, ignorePath = false } = {}) { | ||
let baseValue = ''; | ||
if (ignoreBase === false) { | ||
baseValue = this._getBaseUri(baseUri, server) || ''; | ||
baseValue = this._getBaseUri(baseUri, server, protocols) || ''; | ||
if (baseValue && baseValue[baseValue.length - 1] === '/') { | ||
baseValue = baseValue.substr(0, baseValue.length - 1); | ||
} | ||
baseValue = this._ensureUrlScheme(baseValue); | ||
baseValue = this._ensureUrlScheme(baseValue, protocols); | ||
} | ||
const path = this._getValue(endpoint, this.ns.aml.vocabularies.apiContract.path); | ||
let result = baseValue + (path || ''); | ||
let result = baseValue | ||
if (!ignorePath) { | ||
result = this._appendPath(result, endpoint); | ||
} | ||
if (version && result) { | ||
@@ -711,2 +714,13 @@ result = result.replace('{version}', version); | ||
/** | ||
* Appends endpoint's path to url | ||
* @param {string} url | ||
* @param {Object} endpoint | ||
* @return {string} | ||
*/ | ||
_appendPath(url, endpoint) { | ||
const path = this._getValue(endpoint, this.ns.aml.vocabularies.apiContract.path); | ||
return url + (path || ''); | ||
} | ||
/** | ||
* Computes base URI value from either `baseUri` or `amf` value (in this order). | ||
@@ -761,4 +775,7 @@ * | ||
if (protocols && protocols.length) { | ||
/* eslint-disable-next-line no-param-reassign */ | ||
value = `${protocols[0].toLowerCase() }://${ value}`; | ||
const protocol = protocols[0].toLowerCase(); | ||
if (!value.startsWith(protocol)) { | ||
/* eslint-disable-next-line no-param-reassign */ | ||
value = `${protocol}://${value}`; | ||
} | ||
} else { | ||
@@ -765,0 +782,0 @@ /* eslint-disable-next-line no-param-reassign */ |
Sorry, the diff of this file is too big to display
282719
2251