Skip to content

Commit a5fc40f

Browse files
feat(W-15520218): show servers name in documentation operation for async api
1 parent deb3581 commit a5fc40f

File tree

4 files changed

+121
-3
lines changed

4 files changed

+121
-3
lines changed

demo/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class ComponentDemo extends ApiDemoPage {
152152
_apiListTemplate() {
153153
return [
154154
['demo-api', 'Demo API'],
155+
['jldAsync26', 'Async API 2.6'],
155156
['multi-server', 'Multiple servers'],
156157
['google-drive-api', 'Google Drive'],
157158
['appian-api', 'Appian API'],

src/ApiUrl.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,38 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
165165
return this._baseUri;
166166
}
167167

168+
169+
170+
get asyncServersNames(){
171+
if(!this.endpoint){
172+
return ''
173+
}
174+
const endpoint = Array.isArray(this.endpoint) ? this.endpoint[0]: this.endpoint
175+
const apiContractServerKey = this._getAmfKey( this.ns.aml.vocabularies.apiContract.server)
176+
const endpointServers = this._ensureArray(endpoint[apiContractServerKey])
177+
178+
// try to find servers in channel level
179+
if(endpointServers){
180+
return endpointServers.map((item)=>(this._getValue(item, this.ns.aml.vocabularies.core.name)));
181+
}
182+
183+
// try to find root server (only one) that is received by property
184+
if(this.server){
185+
return [this._getValue(this.server, this.ns.aml.vocabularies.core.name)]
186+
}
187+
188+
// in case that async api doesn't have servers
189+
return null
190+
}
191+
168192
render() {
169-
const { url } = this;
193+
const { url, asyncServersNames } = this;
194+
const isAsyncApi = this._isAsyncAPI(this.amf)
195+
196+
if(isAsyncApi && asyncServersNames){
197+
// only if an async api and has servers
198+
return this.renderAsyncApi(asyncServersNames)
199+
}
170200
return html`
171201
<style>${this.styles}</style>
172202
<section class="url-area">
@@ -234,6 +264,44 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
234264
this._dispatchChangeEvent();
235265
}
236266

267+
renderAsyncApi(asyncServersNames){
268+
const { url, _method } = this;
269+
if(!_method){
270+
return ''
271+
}
272+
return html`
273+
<style>${this.styles}</style>
274+
<section class="async-servers-names-area">
275+
${this._getMethodTemplate()}
276+
<div class="async-servers">
277+
${this._getAsyncPathTemplate()}
278+
${this._getAsyncServersNamesTemplate(asyncServersNames)}
279+
</div>
280+
</section>
281+
<clipboard-copy id="urlCopy" .content="${url}"></clipboard-copy>
282+
`;
283+
}
284+
285+
_getAsyncPathTemplate() {
286+
if (this.isNotHttp && !!this._method) {
287+
return html`<div class="async-servers-path">${this.path}</div>`;
288+
}
289+
return '';
290+
}
291+
292+
_getAsyncServersNamesTemplate(asyncServersNames) {
293+
const { _method } = this;
294+
if (asyncServersNames && !!_method) {
295+
return html`<div class="async-server-names-container">
296+
<span class="async-server-names-title">Available on servers:</span> ${this._getAsyncServersNamesList(asyncServersNames)}</div>`
297+
}
298+
return html``
299+
}
300+
301+
_getAsyncServersNamesList(asyncServersNames) {
302+
return asyncServersNames.map((name) => html`<span class="async-server-name">${name}</span>`)
303+
}
304+
237305
/**
238306
* Computes value for `httpMethod` property.
239307
*

src/Styles.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default css`
7373
flex: 1;
7474
}
7575
76-
.url-area {
76+
.url-area, .async-servers-names-area {
7777
flex: 1;
7878
display: flex;
7979
flex-direction: row;
@@ -93,7 +93,7 @@ export default css`
9393
--api-method-documentation-url-font-color,
9494
var(--code-color)
9595
);
96-
padding: var(--api-method-documentation-url-padding, 8px);
96+
padding: var(--api-method-documentation-url-padding, 13px);
9797
border-radius: var(--api-method-documentation-url-border-radius, 4px);
9898
position: relative;
9999
}
@@ -269,4 +269,49 @@ api-security-documentation:last-of-type {
269269
.messages-options > anypoint-dropdown-menu {
270270
margin-left: 0;
271271
}
272+
273+
.async-servers-names-area{
274+
flex-wrap: wrap
275+
}
276+
277+
.async-servers{
278+
margin-left: 11px;
279+
}
280+
281+
.async-servers .async-servers-path{
282+
color: var(--api-method-documentation-async-channel-name-color,#000);
283+
font-size: 20px;
284+
font-style: normal;
285+
font-weight: 400;
286+
line-height: normal;
287+
margin-top: -1px;
288+
}
289+
290+
.async-servers .async-server-names-title{
291+
color: var(--api-method-documentation-async-server-names-title-color,#414141);
292+
font-size: 14px;
293+
font-style: normal;
294+
font-weight: 400;
295+
line-height: normal;
296+
font-family: var(--api-method-documentation-async-server-names-title-font,Helvetica)
297+
}
298+
299+
.async-servers .async-server-names-container{
300+
margin-top: 16px;
301+
margin-bottom: 10px;
302+
}
303+
304+
.async-servers .async-server-name{
305+
color: var(--api-method-documentation-async-server-names-color,#249FC6);
306+
text-align: center;
307+
font-family: var(--api-method-documentation-async-server-names-font,Avenir);
308+
font-size: 14px;
309+
font-style: normal;
310+
font-weight: 500;
311+
line-height: normal;
312+
border-radius: 4px;
313+
border: 1px solid var(--api-method-documentation-async-server-names-border-color,#249FC6);;
314+
padding: 0px 8px 0px 8px;
315+
margin-right: 10px;
316+
}
272317
`;

test/api-url.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ describe('<api-url>', () => {
115115
assert.equal(element.url, 'amqp://broker.mycompany.com');
116116
});
117117

118+
it('should compute server names', () => {
119+
assert.equal(element.asyncServersNames[0], 'production');
120+
});
121+
118122
it('should compute method', () => {
119123
assert.equal(element._method, 'PUBLISH');
120124
});

0 commit comments

Comments
 (0)