diff --git a/package-lock.json b/package-lock.json index 110a07a..242e90c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@api-components/api-method-documentation", - "version": "5.2.21", + "version": "5.2.22", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@api-components/api-method-documentation", - "version": "5.2.21", + "version": "5.2.22", "license": "Apache-2.0", "dependencies": { "@advanced-rest-client/arc-icons": "^3.3.4", diff --git a/package.json b/package.json index ae78def..8f95c29 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@api-components/api-method-documentation", "description": "A HTTP method documentation build from AMF model", - "version": "5.2.21", + "version": "5.2.22", "license": "Apache-2.0", "main": "index.js", "module": "index.js", diff --git a/src/ApiMethodDocumentation.js b/src/ApiMethodDocumentation.js index 0e64416..519eaf3 100644 --- a/src/ApiMethodDocumentation.js +++ b/src/ApiMethodDocumentation.js @@ -232,6 +232,14 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) { * This is a map of the type name to the binding name. */ bindings: {type: Array}, + /** + * Adds a servers to async API + * + * @param {string} url - The URL of the server. + * @param {object} [description] - An object containing a string `description` property. + */ + servers: {type:Array}, + _servers: {type:Array}, }; } @@ -335,6 +343,21 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) { this._processServerInfo(); } + get servers() { + return this._servers; + } + + set servers(value) { + + const old = this._servers; + /* istanbul ignore if */ + if (old === value) { + return; + } + this._servers = value; + this.requestUpdate('servers', old); + } + get _titleHidden() { if (!this.noTryIt) { return false; @@ -897,6 +920,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) { @@ -1233,6 +1258,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) { .amf="${amf}" .method="${method}" .endpoint="${endpoint}" + .servers="${servers}" ?compatibility="${compatibility}" ?graph="${graph}" noTryit diff --git a/src/ApiUrl.js b/src/ApiUrl.js index 33c453c..1cff0b5 100644 --- a/src/ApiUrl.js +++ b/src/ApiUrl.js @@ -59,6 +59,14 @@ export class ApiUrl extends AmfHelperMixin(LitElement) { * Optional, operation id that is render only for async api */ operationId:{type: String}, + /** + * Adds a servers to async API + * + * @param {string} url - The URL of the server. + * @param {object} [description] - An object containing a string `description` property. + */ + servers: {type:Array}, + _servers: {type:Array}, _url: { type: String }, _method: { type: String }, _protocol: { type: String }, @@ -117,6 +125,19 @@ export class ApiUrl extends AmfHelperMixin(LitElement) { this._updateUrl(); } + get servers() { + return this._servers; + } + + set servers(value) { + const old = this._servers; + if (old === value) { + return; + } + this._servers = value; + this.requestUpdate('servers', old); + } + get endpoint() { return this._endpoint; } @@ -173,16 +194,11 @@ export class ApiUrl extends AmfHelperMixin(LitElement) { get asyncServersNames(){ - if(!this.endpoint){ - return '' - } - const endpoint = Array.isArray(this.endpoint) ? this.endpoint[0]: this.endpoint - const apiContractServerKey = this._getAmfKey( this.ns.aml.vocabularies.apiContract.server) - const endpointServers = this._ensureArray(endpoint[apiContractServerKey]) + const servers = this._ensureArray(this.servers) // try to find servers in channel level - if(endpointServers){ - return endpointServers.map((item)=>(this._getValue(item, this.ns.aml.vocabularies.core.name))); + if(servers){ + return servers.map((item)=>(this._getValue(item, this.ns.aml.vocabularies.core.name))); } // try to find root server (only one) that is received by property @@ -278,11 +294,9 @@ export class ApiUrl extends AmfHelperMixin(LitElement) { } renderAsyncApi(asyncServersNames){ - const { url, _endpoint } = this; - if(!_endpoint){ - return '' - } - return html` + const { url } = this; + + return html`
${this._getMethodTemplate()} diff --git a/test/api-url.test.js b/test/api-url.test.js index d8a48e6..96178e3 100644 --- a/test/api-url.test.js +++ b/test/api-url.test.js @@ -166,8 +166,8 @@ describe('', () => { await nextFrame(); await nextFrame(); - const url = 'mqtt://api.streetlights.smartylighting.com:{port}' - assert.equal(element.shadowRoot.querySelector('.url-value').textContent.trim(), url); + const expectedServer = 'production' + assert.equal(element.shadowRoot.querySelector('.url-value').textContent.trim(), expectedServer); }); }); });