@@ -569,6 +569,9 @@ func parseGeneralAPIInfo(parser *Parser, comments []string) error {
569
569
570
570
parser .swagger .SecurityDefinitions [value ] = scheme
571
571
572
+ case securityAttr :
573
+ parser .swagger .Security = append (parser .swagger .Security , parseSecurity (value ))
574
+
572
575
case "@query.collection.format" :
573
576
parser .collectionFormatInQuery = TransToValidCollectionFormat (value )
574
577
@@ -768,6 +771,34 @@ func parseSecAttributes(context string, lines []string, index *int) (*spec.Secur
768
771
return scheme , nil
769
772
}
770
773
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
+
771
802
func initIfEmpty (license * spec.License ) * spec.License {
772
803
if license == nil {
773
804
return new (spec.License )
0 commit comments