Skip to content

Commit

Permalink
added test for multiple security definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
pmorelli92 committed Apr 19, 2022
1 parent 36d1424 commit a117495
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions parser.go
Expand Up @@ -616,6 +616,8 @@ func parseSecAttr(context string, search []string, lines []string, index *int) (
}
// next securityDefinitions
if strings.Index(securityAttr, "@securitydefinitions.") == 0 {
// Go back to the previous line and break
*index--
break
}
}
Expand Down
17 changes: 16 additions & 1 deletion parser_test.go
Expand Up @@ -542,7 +542,13 @@ func TestParser_ParseGeneralAPISecurity(t *testing.T) {
"@securitydefinitions.apikey ApiKey",
"@in header",
"@name X-API-KEY",
"@description some"})
"@description some",
"",
"@securitydefinitions.oauth2.accessCode OAuth2AccessCode",
"@tokenUrl https://example.com/oauth/token",
"@authorizationUrl https://example.com/oauth/authorize",
"@scope.admin foo",
})
assert.NoError(t, err)

b, _ := json.MarshalIndent(parser.GetSwagger().SecurityDefinitions, "", " ")
Expand All @@ -552,6 +558,15 @@ func TestParser_ParseGeneralAPISecurity(t *testing.T) {
"type": "apiKey",
"name": "X-API-KEY",
"in": "header"
},
"OAuth2AccessCode": {
"type": "oauth2",
"flow": "accessCode",
"authorizationUrl": "https://example.com/oauth/authorize",
"tokenUrl": "https://example.com/oauth/token",
"scopes": {
"admin": " foo"
}
}
}`
assert.Equal(t, expected, string(b))
Expand Down

0 comments on commit a117495

Please sign in to comment.