Skip to content

Commit e8a705b

Browse files
Merge pull request #80 from advanced-rest-client/feat/W-15520218/servers-in-operation
feat(W-15520218): show servers name in documentation operation for as…
2 parents deb3581 + e668505 commit e8a705b

File tree

7 files changed

+154
-12
lines changed

7 files changed

+154
-12
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'],

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
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.16",
4+
"version": "5.2.17",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ApiMethodDocumentation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
804804
}
805805

806806
_getTitleTemplate() {
807+
const isAsyncApi = this._isAsyncAPI(this.amf)
807808
if (this._titleHidden) {
808809
return '';
809810
}
@@ -826,7 +827,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
826827
</div>`}
827828
</div>
828829
${methodSummary ? html`<p class="summary">${methodSummary}</p>` : ''}
829-
${operationId ? html`<span class="operation-id">Operation ID: ${operationId}</span>` : ''}
830+
${operationId && !isAsyncApi ? html`<span class="operation-id">Operation ID: ${operationId}</span>` : ''}
830831
`;
831832
}
832833

@@ -846,6 +847,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
846847
.apiVersion="${this.apiVersion}"
847848
.baseUri="${this.baseUri}"
848849
.operation="${this.method}"
850+
.operationId="${this.operationId}"
849851
@change="${this._handleUrlChange}"
850852
>
851853
</api-url>`;

src/ApiUrl.js

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
5555
* @attribute
5656
*/
5757
baseUri: { type: String },
58+
/**
59+
* Optional, operation id that is render only for async api
60+
*/
61+
operationId:{type: String},
5862
_url: { type: String },
5963
_method: { type: String },
6064
_protocol: { type: String },
6165
_protocolVersion: { type: String },
6266
_operation: { type: Object },
63-
_server: { type: Object }
67+
_server: { type: Object },
68+
_operationId:{type: String}
6469
};
6570
}
6671

@@ -165,8 +170,46 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
165170
return this._baseUri;
166171
}
167172

173+
174+
175+
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])
182+
183+
// try to find servers in channel level
184+
if(endpointServers){
185+
return endpointServers.map((item)=>(this._getValue(item, this.ns.aml.vocabularies.core.name)));
186+
}
187+
188+
// try to find root server (only one) that is received by property
189+
if(this.server){
190+
return [this._getValue(this.server, this.ns.aml.vocabularies.core.name)]
191+
}
192+
193+
// in case that async api doesn't have servers
194+
return null
195+
}
196+
197+
get operationId(){
198+
return this._operationId
199+
}
200+
201+
set operationId(value){
202+
this._operationId = value
203+
}
204+
168205
render() {
169-
const { url } = this;
206+
const { url, asyncServersNames } = this;
207+
const isAsyncApi = this._isAsyncAPI(this.amf)
208+
209+
if(isAsyncApi && asyncServersNames){
210+
// only if an async api and has servers
211+
return this.renderAsyncApi(asyncServersNames)
212+
}
170213
return html`
171214
<style>${this.styles}</style>
172215
<section class="url-area">
@@ -234,6 +277,54 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
234277
this._dispatchChangeEvent();
235278
}
236279

280+
renderAsyncApi(asyncServersNames){
281+
const { url, _method } = this;
282+
if(!_method){
283+
return ''
284+
}
285+
return html`
286+
<style>${this.styles}</style>
287+
<section class="async-servers-names-area">
288+
${this._getMethodTemplate()}
289+
<div class="async-servers">
290+
${this._getAsyncPathTemplate()}
291+
${this._getOperationIdTemplate()}
292+
${this._getAsyncServersNamesTemplate(asyncServersNames)}
293+
</div>
294+
</section>
295+
<clipboard-copy id="urlCopy" .content="${url}"></clipboard-copy>
296+
`;
297+
}
298+
299+
_getAsyncPathTemplate() {
300+
if (this.isNotHttp && !!this._method) {
301+
return html`<div class="async-servers-path url-channel-value">${this.path}</div>`;
302+
}
303+
return '';
304+
}
305+
306+
_getOperationIdTemplate() {
307+
const { operationId } = this;
308+
if (operationId) {
309+
return html`<div class="async-server-names-container">
310+
<span class="async-server-names-title">Operation ID: ${operationId}</span></div>`
311+
}
312+
return html``
313+
}
314+
315+
_getAsyncServersNamesTemplate(asyncServersNames) {
316+
const { _method } = this;
317+
if (asyncServersNames && !!_method) {
318+
return html`<div class="async-server-names-container">
319+
<span class="async-server-names-title">Available on servers:</span> ${this._getAsyncServersNamesList(asyncServersNames)}</div>`
320+
}
321+
return html``
322+
}
323+
324+
_getAsyncServersNamesList(asyncServersNames) {
325+
return asyncServersNames.map((name) => html`<span class="async-server-name url-value">${name}</span>`)
326+
}
327+
237328
/**
238329
* Computes value for `httpMethod` property.
239330
*

src/Styles.js

Lines changed: 45 additions & 1 deletion
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;
@@ -98,6 +98,10 @@ export default css`
9898
position: relative;
9999
}
100100
101+
.async-servers-names-area{
102+
padding: var(--api-method-documentation-url-padding, 13px);
103+
}
104+
101105
.section-title-area {
102106
display: flex;
103107
flex-direction: row;
@@ -269,4 +273,44 @@ api-security-documentation:last-of-type {
269273
.messages-options > anypoint-dropdown-menu {
270274
margin-left: 0;
271275
}
276+
277+
.async-servers{
278+
margin-left: 11px;
279+
}
280+
281+
.async-servers .async-servers-path{
282+
font-size: 20px;
283+
font-style: normal;
284+
font-weight: 400;
285+
line-height: normal;
286+
margin-top: -1px;
287+
word-break: break-all;
288+
}
289+
290+
.async-servers .async-server-names-title{
291+
font-size: 14px;
292+
font-style: normal;
293+
font-weight: 400;
294+
line-height: normal;
295+
font-family: var(--api-method-documentation-async-server-names-title-font,Helvetica)
296+
}
297+
298+
.async-servers .async-server-names-container{
299+
margin-top: 16px;
300+
margin-bottom: 10px;
301+
}
302+
303+
.async-servers .async-server-name{
304+
color: var(--api-method-documentation-async-server-names-color,#249FC6);
305+
text-align: center;
306+
font-family: var(--api-method-documentation-async-server-names-font,Avenir);
307+
font-size: 14px;
308+
font-style: normal;
309+
font-weight: 500;
310+
line-height: normal;
311+
border-radius: 4px;
312+
border: 1px solid var(--api-method-documentation-async-server-names-border-color,#249FC6);;
313+
padding: 0px 8px 0px 8px;
314+
margin-right: 10px;
315+
}
272316
`;

test/api-url.test.js

Lines changed: 10 additions & 6 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
});
@@ -144,15 +148,15 @@ describe('<api-url>', () => {
144148
});
145149

146150
it('should render channel', async () => {
147-
const channel = 'Channelsmartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured'
148-
await waitUntil(() => element.shadowRoot.querySelector('.url-channel-value'));
149-
assert.equal(element.shadowRoot.querySelector('.url-channel-value').textContent, channel);
151+
const channel = 'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured'
152+
await waitUntil(() => element.shadowRoot.querySelector('.async-servers-path'));
153+
assert.equal(element.shadowRoot.querySelector('.async-servers-path').textContent, channel);
150154
});
151155

152156
it('should render server', async () => {
153-
const expectedServer = 'Servermqtt://api.streetlights.smartylighting.com:{port}'
154-
await waitUntil(() => element.shadowRoot.querySelector('.url-server-value'));
155-
assert.equal(element.shadowRoot.querySelector('.url-server-value').textContent, expectedServer);
157+
const expectedServer = 'production'
158+
await waitUntil(() => element.shadowRoot.querySelector('.async-server-name'));
159+
assert.equal(element.shadowRoot.querySelector('.async-server-name').textContent, expectedServer);
156160
});
157161

158162
it('should only render url value when no operation selected', async () => {

0 commit comments

Comments
 (0)