Skip to content

Commit

Permalink
fix @x-tagGroups (#1010)
Browse files Browse the repository at this point in the history
* test x-tagGroup

* fix x-tagGroups issue
  • Loading branch information
ubogdan authored Sep 29, 2021
1 parent bcbae0f commit f9645be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ func parseGeneralAPIInfo(parser *Parser, comments []string) error {

// parsing classic meta data model
for i, commentLine := range comments {
attribute := strings.ToLower(strings.Split(commentLine, " ")[0])
attribute := strings.Split(commentLine, " ")[0]
value := strings.TrimSpace(commentLine[len(attribute):])
multilineBlock := false
if previousAttribute == attribute {
multilineBlock = true
}
switch attribute {
switch strings.ToLower(attribute) {
case "@version":
parser.swagger.Info.Version = value
case "@title":
Expand Down Expand Up @@ -460,7 +460,10 @@ func parseGeneralAPIInfo(parser *Parser, comments []string) error {
if strings.Contains(extensionName, "logo") {
parser.swagger.Info.Extensions.Add(extensionName, valueJSON)
} else {
parser.swagger.AddExtension(extensionName, valueJSON)
if parser.swagger.Extensions == nil {
parser.swagger.Extensions = make(map[string]interface{})
}
parser.swagger.Extensions[attribute[1:]] = valueJSON
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,19 @@ func TestParser_ParseGeneralAPIInfoCollectionFromat(t *testing.T) {
assert.Equal(t, parser.collectionFormatInQuery, "tsv")
}

func TestParser_ParseGeneralAPITagGroups(t *testing.T) {
t.Parallel()

parser := New()
assert.NoError(t, parseGeneralAPIInfo(parser, []string{
"@x-tagGroups [{\"name\":\"General\",\"tags\":[\"lanes\",\"video-recommendations\"]}]",
}))

expected := []interface{}{map[string]interface{}{"name": "General", "tags": []interface{}{"lanes", "video-recommendations"}}}
assert.Equal(t, parser.swagger.Extensions["x-tagGroups"], expected)

}

func TestParser_ParseGeneralAPITagDocs(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit f9645be

Please sign in to comment.