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

Added support for @tag.x- attributes for tags (#1784) #1785

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ When a short string in your documentation is insufficient, or you need images, c
| description.markdown | A short description of the application. Parsed from the api.md file. This is an alternative to @description |// @description.markdown No value needed, this parses the description from api.md |
| tag.name | Name of a tag.| // @tag.name This is the name of the tag |
| tag.description.markdown | Description of the tag this is an alternative to tag.description. The description will be read from a file named like tagname.md | // @tag.description.markdown |
| tag.x-name | The extension key, must be start by x- and take only string value | // @x-example-key value |


## API Operation
Expand Down
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