Skip to content

Commit

Permalink
Added support for @tag.x- attributes for tags (swaggo#1784)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ponywka committed Apr 10, 2024
1 parent 91624ad commit 92e0626
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,21 @@ func parseGeneralAPIInfo(parser *Parser, comments []string) error {

parser.swagger.Extensions[attribute[1:]] = valueJSON
}
} else if strings.HasPrefix(attribute, "@tag.x-") {
extensionName := attribute[5:]

if len(value) == 0 {
return fmt.Errorf("annotation %s need a value", attribute)
}

if tag.Extensions == nil {
tag.Extensions = make(map[string]interface{})
}

// tag.Extensions.Add(extensionName, value) works wrong (transforms extensionName to lower case)
// needed to save case for ReDoc
// https://redocly.com/docs/api-reference-docs/specification-extensions/x-display-name/
tag.Extensions[extensionName] = value
}
}

Expand Down
6 changes: 4 additions & 2 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ func TestParser_ParseGeneralAPITagDocs(t *testing.T) {
"@tag.name test",
"@tag.description A test Tag",
"@tag.docs.url https://example.com",
"@tag.docs.description Best example documentation"})
"@tag.docs.description Best example documentation",
"@tag.x-displayName Test group"})
assert.NoError(t, err)

b, _ := json.MarshalIndent(parser.GetSwagger().Tags, "", " ")
Expand All @@ -587,7 +588,8 @@ func TestParser_ParseGeneralAPITagDocs(t *testing.T) {
"externalDocs": {
"description": "Best example documentation",
"url": "https://example.com"
}
},
"x-displayName": "Test group"
}
]`
assert.Equal(t, expected, string(b))
Expand Down

0 comments on commit 92e0626

Please sign in to comment.