MCPcopy
hub / github.com/swaggo/swag / ParseSecurityComment

Method ParseSecurityComment

operation.go:741–777  ·  view source on GitHub ↗

ParseSecurityComment parses comment for given `security` comment string.

(commentLine string)

Source from the content-addressed store, hash-verified

739
740// ParseSecurityComment parses comment for given `security` comment string.
741func (operation *Operation) ParseSecurityComment(commentLine string) error {
742 if len(commentLine) == 0 {
743 operation.Security = []map[string][]string{}
744 return nil
745 }
746
747 var (
748 securityMap = make(map[string][]string)
749 securitySource = commentLine[strings.Index(commentLine, "@Security")+1:]
750 )
751
752 for _, securityOption := range securityPairSepPattern.Split(securitySource, -1) {
753 securityOption = strings.TrimSpace(securityOption)
754
755 left, right := strings.Index(securityOption, "["), strings.Index(securityOption, "]")
756
757 if !(left == -1 && right == -1) {
758 scopes := securityOption[left+1 : right]
759
760 var options []string
761
762 for _, scope := range strings.Split(scopes, ",") {
763 options = append(options, strings.TrimSpace(scope))
764 }
765
766 securityKey := securityOption[0:left]
767 securityMap[securityKey] = append(securityMap[securityKey], options...)
768 } else {
769 securityKey := strings.TrimSpace(securityOption)
770 securityMap[securityKey] = []string{}
771 }
772 }
773
774 operation.Security = append(operation.Security, securityMap)
775
776 return nil
777}
778
779// findTypeDef attempts to find the *ast.TypeSpec for a specific type given the
780// type's name and the package's import path.

Callers 1

ParseCommentMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected