@@ -523,54 +523,64 @@ private void CollectAuthorization(JObject actionJson, ActionDefinition actionDef
523523 return ;
524524 }
525525
526- CollectAuthorization ( property , property . Value . Type , actionDefinition , pathParameters ) ;
526+ CollectAuthorization ( property . Value . Type , property . Value , actionDefinition , pathParameters ) ;
527527 }
528- private void CollectAuthorization ( JProperty property , JTokenType type , ActionDefinition actionDefinition , IReadOnlyDictionary < string , PathParameter > pathParameters )
528+ private void CollectAuthorization ( JTokenType type , JToken value , ActionDefinition actionDefinition , IReadOnlyDictionary < string , PathParameter > pathParameters )
529529 {
530530 switch ( type )
531531 {
532532 case JTokenType . Object :
533- JObject authorizationValue = ( JObject ) property . Value ;
534- JProperty templateProperty = authorizationValue . Property ( "name" ) ;
535- CollectAuthorization ( templateProperty , authorizationValue , actionDefinition , pathParameters ) ;
533+ JObject authorizationValue = ( JObject ) value ;
534+ JToken templateNameValue = authorizationValue . Property ( "name" ) ? . Value ;
535+ CollectAuthorization ( templateNameValue , authorizationValue , actionDefinition , pathParameters ) ;
536536 break ;
537537
538- case JTokenType . String when ( string ) property . Value == "none" :
538+ case JTokenType . String when ( string ) value == "none" :
539539 break ;
540540
541541 case JTokenType . String :
542- CollectAuthorization ( templateProperty : property , authorizationValue : new JObject ( ) , actionDefinition , pathParameters ) ;
542+ CollectAuthorization ( templateNameValue : value , authorizationValue : new JObject ( ) , actionDefinition , pathParameters ) ;
543+ break ;
544+
545+ case JTokenType . Array :
546+ JArray array = ( JArray ) value ;
547+ foreach ( JToken item in array )
548+ CollectAuthorization ( item . Type , item , actionDefinition , pathParameters ) ;
549+
543550 break ;
544551
545552 default :
546- throw new ArgumentOutOfRangeException ( nameof ( type ) , type , property . Value . Path ) ;
553+ throw new ArgumentOutOfRangeException ( nameof ( type ) , type , value . Path ) ;
547554 }
548555 }
549- private void CollectAuthorization ( JProperty templateProperty , JObject authorizationValue , ActionDefinition actionDefinition , IReadOnlyDictionary < string , PathParameter > pathParameters )
556+ private void CollectAuthorization ( JToken templateNameValue , JObject authorizationValue , ActionDefinition actionDefinition , IReadOnlyDictionary < string , PathParameter > pathParameters )
550557 {
551558 JObject authorization = authorizationValue ;
552559
553- if ( templateProperty != null
554- && ( authorization = ApplyAuthorizationTemplate ( templateProperty , authorizationValue ) ) == null ) // In case of error that has been previously logged
555- return ;
560+ // "name" property is optional, when the endpoint defines an authorization behavior manually
561+ if ( templateNameValue != null )
562+ {
563+ authorization = ApplyAuthorizationTemplate ( templateNameValue , authorizationValue ) ;
564+ if ( authorization == null ) // If the template is not found, it will have been logged already at this point
565+ return ;
566+ }
556567
557568 IReadOnlyDictionary < string , ExplicitParameter > explicitParameters = CollectExplicitParameters ( authorization , requestBody : null , pathParameters ) ;
558569 ICollection < string > bodyParameters = new Collection < string > ( ) ;
559- actionDefinition . Authorization = CreateActionDefinition < AuthorizationBehavior > ( authorization , explicitParameters , pathParameters , bodyParameters , requestBody : null ) ;
570+ AuthorizationBehavior authorizationBehavior = CreateActionDefinition < AuthorizationBehavior > ( authorization , explicitParameters , pathParameters , bodyParameters , requestBody : null ) ;
571+ actionDefinition . Authorization . Add ( authorizationBehavior ) ;
560572 }
561573
562- private JObject ApplyAuthorizationTemplate ( JProperty templateNameProperty , JObject authorizationTemplateReference )
574+ private JObject ApplyAuthorizationTemplate ( JToken templateNameValue , JObject authorizationTemplateReference )
563575 {
564- string templateName = ( string ) templateNameProperty . Value ;
576+ string templateName = ( string ) templateNameValue ;
565577 if ( ! _templates . Authorization . TryGetTemplate ( templateName , out ConfigurationAuthorizationTemplate template ) )
566578 {
567- SourceLocation templateNameLineInfo = templateNameProperty . Value . GetSourceInfo ( ) ;
579+ SourceLocation templateNameLineInfo = templateNameValue . GetSourceInfo ( ) ;
568580 Logger . LogError ( $ "Unknown authorization template '{ templateName } '", templateNameLineInfo . Source , templateNameLineInfo . Line , templateNameLineInfo . Column ) ;
569581 return null ;
570582 }
571583
572- templateNameProperty . Remove ( ) ;
573-
574584 JObject resolvedAuthorization = new JObject ( ) ;
575585
576586 if ( authorizationTemplateReference . HasValues )
0 commit comments