@@ -55,12 +55,17 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
55
55
* @attribute
56
56
*/
57
57
baseUri : { type : String } ,
58
+ /**
59
+ * Optional, operation id that is render only for async api
60
+ */
61
+ operationId :{ type : String } ,
58
62
_url : { type : String } ,
59
63
_method : { type : String } ,
60
64
_protocol : { type : String } ,
61
65
_protocolVersion : { type : String } ,
62
66
_operation : { type : Object } ,
63
- _server : { type : Object }
67
+ _server : { type : Object } ,
68
+ _operationId :{ type : String }
64
69
} ;
65
70
}
66
71
@@ -165,8 +170,46 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
165
170
return this . _baseUri ;
166
171
}
167
172
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
+
168
205
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
+ }
170
213
return html `
171
214
< style > ${ this . styles } </ style >
172
215
< section class ="url-area ">
@@ -234,6 +277,54 @@ export class ApiUrl extends AmfHelperMixin(LitElement) {
234
277
this . _dispatchChangeEvent ( ) ;
235
278
}
236
279
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
+
237
328
/**
238
329
* Computes value for `httpMethod` property.
239
330
*
0 commit comments