@@ -569,6 +569,9 @@ func parseGeneralAPIInfo(parser *Parser, comments []string) error {
569569
570570 parser .swagger .SecurityDefinitions [value ] = scheme
571571
572+ case securityAttr :
573+ parser .swagger .Security = append (parser .swagger .Security , parseSecurity (value ))
574+
572575 case "@query.collection.format" :
573576 parser .collectionFormatInQuery = TransToValidCollectionFormat (value )
574577
@@ -768,6 +771,34 @@ func parseSecAttributes(context string, lines []string, index *int) (*spec.Secur
768771 return scheme , nil
769772}
770773
774+ func parseSecurity (commentLine string ) map [string ][]string {
775+ securityMap := make (map [string ][]string )
776+
777+ for _ , securityOption := range strings .Split (commentLine , "||" ) {
778+ securityOption = strings .TrimSpace (securityOption )
779+
780+ left , right := strings .Index (securityOption , "[" ), strings .Index (securityOption , "]" )
781+
782+ if ! (left == - 1 && right == - 1 ) {
783+ scopes := securityOption [left + 1 : right ]
784+
785+ var options []string
786+
787+ for _ , scope := range strings .Split (scopes , "," ) {
788+ options = append (options , strings .TrimSpace (scope ))
789+ }
790+
791+ securityKey := securityOption [0 :left ]
792+ securityMap [securityKey ] = append (securityMap [securityKey ], options ... )
793+ } else {
794+ securityKey := strings .TrimSpace (securityOption )
795+ securityMap [securityKey ] = []string {}
796+ }
797+ }
798+
799+ return securityMap
800+ }
801+
771802func initIfEmpty (license * spec.License ) * spec.License {
772803 if license == nil {
773804 return new (spec.License )
0 commit comments