Skip to content

Commit f954f37

Browse files
Merge pull request #87 from advanced-rest-client/feat/W-15607551/show-servers-name
Feat/w 15607551/show servers name
2 parents 20a88e5 + 36734a4 commit f954f37

File tree

5 files changed

+58
-18
lines changed

5 files changed

+58
-18
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/api-method-documentation",
33
"description": "A HTTP method documentation build from AMF model",
4-
"version": "5.2.21",
4+
"version": "5.2.22",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ApiMethodDocumentation.js

+26
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
232232
* This is a map of the type name to the binding name.
233233
*/
234234
bindings: {type: Array},
235+
/**
236+
* Adds a servers to async API
237+
*
238+
* @param {string} url - The URL of the server.
239+
* @param {object} [description] - An object containing a string `description` property.
240+
*/
241+
servers: {type:Array},
242+
_servers: {type:Array},
235243
};
236244
}
237245

@@ -335,6 +343,21 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
335343
this._processServerInfo();
336344
}
337345

346+
get servers() {
347+
return this._servers;
348+
}
349+
350+
set servers(value) {
351+
352+
const old = this._servers;
353+
/* istanbul ignore if */
354+
if (old === value) {
355+
return;
356+
}
357+
this._servers = value;
358+
this.requestUpdate('servers', old);
359+
}
360+
338361
get _titleHidden() {
339362
if (!this.noTryIt) {
340363
return false;
@@ -897,6 +920,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
897920
<api-url
898921
.amf="${this.amf}"
899922
.server="${this.server}"
923+
.servers="${this.servers}"
900924
.endpoint="${this.endpoint}"
901925
.apiVersion="${this.apiVersion}"
902926
.baseUri="${this.baseUri}"
@@ -1225,6 +1249,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
12251249
amf,
12261250
compatibility,
12271251
graph,
1252+
servers
12281253
} = this;
12291254
return html`
12301255
<div class="callback-section">
@@ -1233,6 +1258,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
12331258
.amf="${amf}"
12341259
.method="${method}"
12351260
.endpoint="${endpoint}"
1261+
.servers="${servers}"
12361262
?compatibility="${compatibility}"
12371263
?graph="${graph}"
12381264
noTryit

src/ApiUrl.js

+27-13
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
5959
* Optional, operation id that is render only for async api
6060
*/
6161
operationId:{type: String},
62+
/**
63+
* Adds a servers to async API
64+
*
65+
* @param {string} url - The URL of the server.
66+
* @param {object} [description] - An object containing a string `description` property.
67+
*/
68+
servers: {type:Array},
69+
_servers: {type:Array},
6270
_url: { type: String },
6371
_method: { type: String },
6472
_protocol: { type: String },
@@ -117,6 +125,19 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
117125
this._updateUrl();
118126
}
119127

128+
get servers() {
129+
return this._servers;
130+
}
131+
132+
set servers(value) {
133+
const old = this._servers;
134+
if (old === value) {
135+
return;
136+
}
137+
this._servers = value;
138+
this.requestUpdate('servers', old);
139+
}
140+
120141
get endpoint() {
121142
return this._endpoint;
122143
}
@@ -173,16 +194,11 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
173194

174195

175196
get asyncServersNames(){
176-
if(!this.endpoint){
177-
return ''
178-
}
179-
const endpoint = Array.isArray(this.endpoint) ? this.endpoint[0]: this.endpoint
180-
const apiContractServerKey = this._getAmfKey( this.ns.aml.vocabularies.apiContract.server)
181-
const endpointServers = this._ensureArray(endpoint[apiContractServerKey])
197+
const servers = this._ensureArray(this.servers)
182198

183199
// try to find servers in channel level
184-
if(endpointServers){
185-
return endpointServers.map((item)=>(this._getValue(item, this.ns.aml.vocabularies.core.name)));
200+
if(servers){
201+
return servers.map((item)=>(this._getValue(item, this.ns.aml.vocabularies.core.name)));
186202
}
187203

188204
// try to find root server (only one) that is received by property
@@ -278,11 +294,9 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
278294
}
279295

280296
renderAsyncApi(asyncServersNames){
281-
const { url, _endpoint } = this;
282-
if(!_endpoint){
283-
return ''
284-
}
285-
return html`
297+
const { url } = this;
298+
299+
return html`
286300
<style>${this.styles}</style>
287301
<section class="async-servers-names-area">
288302
${this._getMethodTemplate()}

test/api-url.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ describe('<api-url>', () => {
166166
await nextFrame();
167167
await nextFrame();
168168

169-
const url = 'mqtt://api.streetlights.smartylighting.com:{port}'
170-
assert.equal(element.shadowRoot.querySelector('.url-value').textContent.trim(), url);
169+
const expectedServer = 'production'
170+
assert.equal(element.shadowRoot.querySelector('.url-value').textContent.trim(), expectedServer);
171171
});
172172
});
173173
});

0 commit comments

Comments
 (0)