Skip to content

Commit

Permalink
fix #1742
Browse files Browse the repository at this point in the history
Signed-off-by: sdghchj <sdghchj@qq.com>
  • Loading branch information
sdghchj committed Jan 17, 2024
1 parent 76695ca commit 67f89d1
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ func parseSecAttributes(context string, lines []string, index *int) (*spec.Secur
attrMap, scopes := make(map[string]string), make(map[string]string)
extensions, description := make(map[string]interface{}), ""

loopline:
for ; *index < len(lines); *index++ {
v := strings.TrimSpace(lines[*index])
if len(v) == 0 {
Expand All @@ -751,23 +752,21 @@ func parseSecAttributes(context string, lines []string, index *int) (*spec.Secur
for _, findterm := range search {
if securityAttr == findterm {
attrMap[securityAttr] = value

break
continue loopline
}
}

isExists, err := isExistsScope(securityAttr)
if err != nil {
if isExists, err := isExistsScope(securityAttr); err != nil {
return nil, err
}

if isExists {
scopes[securityAttr[len(scopeAttrPrefix):]] = v[len(securityAttr):]
} else if isExists {
scopes[securityAttr[len(scopeAttrPrefix):]] = value
continue
}

if strings.HasPrefix(securityAttr, "@x-") {
// Add the custom attribute without the @
extensions[securityAttr[1:]] = value
continue
}

// Not mandatory field
Expand Down Expand Up @@ -914,14 +913,14 @@ func getMarkdownForTag(tagName string, dirPath string) ([]byte, error) {
func isExistsScope(scope string) (bool, error) {
s := strings.Fields(scope)
for _, v := range s {
if strings.Contains(v, scopeAttrPrefix) {
if strings.HasPrefix(v, scopeAttrPrefix) {
if strings.Contains(v, ",") {
return false, fmt.Errorf("@scope can't use comma(,) get=" + v)
}
}
}

return strings.Contains(scope, scopeAttrPrefix), nil
return strings.HasPrefix(scope, scopeAttrPrefix), nil
}

func getTagsFromComment(comment string) (tags []string) {
Expand Down

0 comments on commit 67f89d1

Please sign in to comment.