@@ -403,6 +403,43 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
403
403
this . _processServerInfo ( ) ;
404
404
}
405
405
406
+ get asyncSecurityServers ( ) {
407
+ if ( ! this . endpoint ) {
408
+ return [ ]
409
+ }
410
+ const endpoint = Array . isArray ( this . endpoint ) ? this . endpoint [ 0 ] : this . endpoint
411
+ const apiContractServerKey = this . _getAmfKey ( this . ns . aml . vocabularies . apiContract . server )
412
+ const endpointServers = this . _ensureArray ( endpoint [ apiContractServerKey ] )
413
+ const apiSecurityKey = this . _getAmfKey ( this . ns . aml . vocabularies . security . security )
414
+
415
+ // try to find servers in channel level
416
+ if ( endpointServers ) {
417
+ return endpointServers . map ( ( server ) => server [ apiSecurityKey ] || null ) . filter ( elem => elem !== null ) . flat ( ) ;
418
+ }
419
+
420
+ // try to find root server (only one) that is received by property
421
+ if ( this . server ) {
422
+ return this . _ensureArray ( this . server [ apiSecurityKey ] ) || [ ]
423
+ }
424
+
425
+ // in case that async api doesn't have servers
426
+ return [ ]
427
+ }
428
+
429
+ /**
430
+ * Filters the methodSecurity array to remove elements that have the same '@id' as the elements in the serversSecurity array.
431
+ *
432
+ * @param {object[] } methodSecurity - The array of method security objects.
433
+ * @param {object[] } serversSecurity - The array of server security objects.
434
+ * @returns {object[] } The filtered methodSecurity array with unique elements based on the '@id' key.
435
+ */
436
+ _computeAsyncSecurityMethod ( methodSecurity , serversSecurity ) {
437
+ if ( ! Array . isArray ( methodSecurity ) || ! Array . isArray ( serversSecurity ) ) {
438
+ return [ ]
439
+ }
440
+ return methodSecurity . filter ( method => ! serversSecurity . some ( server => server [ '@id' ] === method [ '@id' ] ) ) ;
441
+ }
442
+
406
443
_processMethodChange ( ) {
407
444
this . __methodProcessingDebouncer = false ;
408
445
const { method } = this ;
@@ -411,10 +448,14 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
411
448
this . hasCustomProperties = this . _computeHasCustomProperties ( method ) ;
412
449
this . expects = this . _computeExpects ( method ) ;
413
450
this . returns = this . _computeReturns ( method ) ;
451
+
414
452
if ( this . _isAsyncAPI ( this . amf ) ) {
415
453
this . _overwriteExpects ( ) ;
454
+ this . _computeAsyncApiSecurity ( )
455
+ } else {
456
+ this . security = this . _computeSecurity ( method ) || this . _computeSecurity ( this . server ) ;
416
457
}
417
- this . security = this . _computeSecurity ( method ) || this . _computeSecurity ( this . server ) ;
458
+
418
459
const extendsTypes = this . _computeExtends ( method ) ;
419
460
this . extendsTypes = extendsTypes ;
420
461
this . traits = this . _computeTraits ( extendsTypes ) ;
@@ -424,6 +465,19 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
424
465
this . deprecated = this . _computeIsDeprecated ( method ) ;
425
466
}
426
467
468
+ _computeAsyncApiSecurity ( ) {
469
+ const { method } = this ;
470
+ // find security from all servers for this endpoint
471
+ this . serversSecurity = this . asyncSecurityServers ;
472
+
473
+ // security that is defined by operation
474
+ const methodSecurity = this . _computeSecurity ( method ) ;
475
+
476
+ // method security that is defined by operation and is not defined by servers
477
+ this . methodSecurity = this . _computeAsyncSecurityMethod ( methodSecurity , this . serversSecurity ) ;
478
+ this . security = this . methodSecurity . length > 0 ? this . methodSecurity : this . serversSecurity ;
479
+ }
480
+
427
481
_computeIsDeprecated ( method ) {
428
482
return Boolean ( this . _getValue ( method , this . _getAmfKey ( this . ns . aml . vocabularies . core . deprecated ) ) ) ;
429
483
}
@@ -923,7 +977,12 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
923
977
}
924
978
925
979
_getSecurityTemplate ( ) {
926
- const { renderSecurity, security } = this ;
980
+ const { renderSecurity, serversSecurity, security : securityNoAsync } = this ;
981
+ let security = securityNoAsync
982
+ if ( this . _isAsyncAPI ( this . amf ) ) {
983
+ // when is async api shows security that is defined by servers
984
+ security = serversSecurity
985
+ }
927
986
if ( ! renderSecurity || ! security || ! security . length ) {
928
987
return '' ;
929
988
}
@@ -1033,6 +1092,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
1033
1092
1034
1093
_getRequestTemplate ( ) {
1035
1094
return html `< section class ="request-documentation ">
1095
+ ${ this . _getAsyncSecurityMethodTemplate ( ) }
1036
1096
${ this . _getMessagesTemplate ( ) }
1037
1097
${ this . _getCodeSnippetsTemplate ( ) }
1038
1098
${ this . _getSecurityTemplate ( ) }
@@ -1043,6 +1103,27 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
1043
1103
</ section > `
1044
1104
}
1045
1105
1106
+ _getAsyncSecurityMethodTemplate ( ) {
1107
+ const { renderSecurity, methodSecurity } = this ;
1108
+ if ( ! renderSecurity || ! methodSecurity || ! methodSecurity . length || ! this . _isAsyncAPI ( this . amf ) ) {
1109
+ return '' ;
1110
+ }
1111
+ const { compatibility, amf, narrow } = this ;
1112
+ return html `< section class ="async-method-security ">
1113
+ < div
1114
+ class ="section-title-area "
1115
+ >
1116
+ < div class ="heading3 table-title " role ="heading " aria-level ="2 "> Additional security requirements</ div >
1117
+
1118
+ </ div >
1119
+ ${ methodSecurity . map ( ( item ) => html `< api-security-documentation
1120
+ .amf ="${ amf } "
1121
+ .security ="${ item } "
1122
+ ?narrow ="${ narrow } "
1123
+ ?compatibility ="${ compatibility } "> </ api-security-documentation > ` ) }
1124
+ </ section > ` ;
1125
+ }
1126
+
1046
1127
_getMessagesTemplate ( ) {
1047
1128
const { message } = this ;
1048
1129
if ( ! message || ! Array . isArray ( message ) || message . length <= 1 ) {
0 commit comments