From a1174951dc0bf5e1a16d5ab649da2b1e23822c1a Mon Sep 17 00:00:00 2001 From: Pablo Morelli Date: Tue, 19 Apr 2022 14:50:37 +0200 Subject: [PATCH] added test for multiple security definitions --- parser.go | 2 ++ parser_test.go | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/parser.go b/parser.go index cf59ee065..980c1d7b2 100644 --- a/parser.go +++ b/parser.go @@ -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 } } diff --git a/parser_test.go b/parser_test.go index 8d5a8b762..908d54a7f 100644 --- a/parser_test.go +++ b/parser_test.go @@ -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, "", " ") @@ -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))