@@ -403,6 +403,36 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
403403 this . _processServerInfo ( ) ;
404404 }
405405
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+ _computeAsyncSecurityMethod ( methodSecurity , serversSecurity ) {
430+ if ( ! Array . isArray ( methodSecurity ) || ! Array . isArray ( serversSecurity ) ) {
431+ return [ ]
432+ }
433+ return methodSecurity . filter ( method => ! serversSecurity . some ( server => server [ '@id' ] === method [ '@id' ] ) ) ;
434+ }
435+
406436 _processMethodChange ( ) {
407437 this . __methodProcessingDebouncer = false ;
408438 const { method } = this ;
@@ -413,8 +443,20 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
413443 this . returns = this . _computeReturns ( method ) ;
414444 if ( this . _isAsyncAPI ( this . amf ) ) {
415445 this . _overwriteExpects ( ) ;
446+
447+ // find security from all servers for this endpoint
448+ this . serversSecurity = this . asyncSecurityServers ;
449+
450+ // security that is defined by operation
451+ const methodSecurity = this . _computeSecurity ( method ) ;
452+
453+ // method security that is defined by operation and is not defined by servers
454+ this . methodSecurity = this . _computeAsyncSecurityMethod ( methodSecurity , this . serversSecurity ) ;
455+ this . security = this . methodSecurity . length > 0 ?this . methodSecurity : this . serversSecurity ;
456+ } else {
457+ this . security = this . _computeSecurity ( method ) || this . _computeSecurity ( this . server ) ;
416458 }
417- this . security = this . _computeSecurity ( method ) || this . _computeSecurity ( this . server ) ;
459+
418460 const extendsTypes = this . _computeExtends ( method ) ;
419461 this . extendsTypes = extendsTypes ;
420462 this . traits = this . _computeTraits ( extendsTypes ) ;
@@ -923,7 +965,12 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
923965 }
924966
925967 _getSecurityTemplate ( ) {
926- const { renderSecurity, security } = this ;
968+ const { renderSecurity, serversSecurity, security : securityNoAsync } = this ;
969+ let security = securityNoAsync
970+ if ( this . _isAsyncAPI ( this . amf ) ) {
971+ // when is async api shows security that is defined by servers
972+ security = serversSecurity
973+ }
927974 if ( ! renderSecurity || ! security || ! security . length ) {
928975 return '' ;
929976 }
@@ -1032,6 +1079,7 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
10321079
10331080 _getRequestTemplate ( ) {
10341081 return html `< section class ="request-documentation ">
1082+ ${ this . _getAsyncSecurityMethodTemplate ( ) }
10351083 ${ this . _getMessagesTemplate ( ) }
10361084 ${ this . _getCodeSnippetsTemplate ( ) }
10371085 ${ this . _getSecurityTemplate ( ) }
@@ -1042,6 +1090,27 @@ export class ApiMethodDocumentation extends AmfHelperMixin(LitElement) {
10421090 </ section > `
10431091 }
10441092
1093+ _getAsyncSecurityMethodTemplate ( ) {
1094+ const { renderSecurity, methodSecurity } = this ;
1095+ if ( ! renderSecurity || ! methodSecurity || ! methodSecurity . length || ! this . _isAsyncAPI ( this . amf ) ) {
1096+ return '' ;
1097+ }
1098+ const { compatibility, amf, narrow } = this ;
1099+ return html `< section class ="async-method-security ">
1100+ < div
1101+ class ="section-title-area "
1102+ >
1103+ < div class ="heading3 table-title " role ="heading " aria-level ="2 "> Additional security requirements</ div >
1104+
1105+ </ div >
1106+ ${ methodSecurity . map ( ( item ) => html `< api-security-documentation
1107+ .amf ="${ amf } "
1108+ .security ="${ item } "
1109+ ?narrow ="${ narrow } "
1110+ ?compatibility ="${ compatibility } "> </ api-security-documentation > ` ) }
1111+ </ section > ` ;
1112+ }
1113+
10451114 _getMessagesTemplate ( ) {
10461115 const { message } = this ;
10471116 if ( ! message || ! Array . isArray ( message ) || message . length <= 1 ) {
0 commit comments