Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 1414 #1419

Merged
merged 2 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ func parseSecAttributes(context string, lines []string, index *int) (*spec.Secur

var search []string

attribute := strings.ToLower(strings.Split(lines[*index], " ")[0])
attribute := strings.ToLower(FieldsByAnySpace(lines[*index], 2)[0])
switch attribute {
case secBasicAttr:
return spec.BasicAuth(), nil
Expand All @@ -642,14 +642,23 @@ func parseSecAttributes(context string, lines []string, index *int) (*spec.Secur
extensions, description := make(map[string]interface{}), ""

for ; *index < len(lines); *index++ {
v := lines[*index]
v := strings.TrimSpace(lines[*index])
if len(v) == 0 {
continue
}

fields := FieldsByAnySpace(v, 2)
securityAttr := strings.ToLower(fields[0])
var value string
if len(fields) > 1 {
value = fields[1]
}

securityAttr := strings.ToLower(strings.Split(v, " ")[0])
for _, findterm := range search {
if securityAttr == findterm {
attrMap[securityAttr] = strings.TrimSpace(v[len(securityAttr):])
attrMap[securityAttr] = value

continue
break
}
}

Expand All @@ -664,12 +673,12 @@ func parseSecAttributes(context string, lines []string, index *int) (*spec.Secur

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

// Not mandatory field
if securityAttr == descriptionAttr {
description = strings.TrimSpace(v[len(securityAttr):])
description = value
}

// next securityDefinitions
Expand Down
14 changes: 7 additions & 7 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3732,10 +3732,10 @@ func TestTryAddDescription(t *testing.T) {
{
name: "added description",
lines: []string{
"@securitydefinitions.apikey test",
"@in header",
"@name x-api-key",
"@description some description",
"\t@securitydefinitions.apikey test",
"\t@in header",
"\t@name x-api-key",
"\t@description some description",
},
want: &spec.SecurityScheme{
SecuritySchemeProps: spec.SecuritySchemeProps{
Expand All @@ -3749,9 +3749,9 @@ func TestTryAddDescription(t *testing.T) {
{
name: "no description",
lines: []string{
"@securitydefinitions.oauth2.application swagger",
"@tokenurl https://example.com/oauth/token",
"@not-description some description",
" @securitydefinitions.oauth2.application swagger",
" @tokenurl https://example.com/oauth/token",
" @not-description some description",
},
want: &spec.SecurityScheme{
SecuritySchemeProps: spec.SecuritySchemeProps{
Expand Down