Skip to content

Commit

Permalink
Fix issue #1150
Browse files Browse the repository at this point in the history
To summarize the issue, running `swag fmt` will set (at least) 2 spaces between the attribute tag and the rest of the comment. But this is a problem for struct with single comment:

```diff
type Example struct {
	Foobar string
-} // @name Example
+} // @name  Example
```

Indeed the doc generation doesn't interpret this correctly for struct (it completely ignore it).

So there are 2 solutions:

- fix the indent (which is feel more natural)
- fix the doc generation to correctly parse 2 spaces

This commit is fixing the indent part.

Basically I just set the padding=1 on `tabwriter`.

The cons is that it will also impacts all other godocs.

For instance (taken from the readme):

```diff
-// @title           Swagger Example API
-// @Version         1.0
-// @description     This is a sample server celler server.
-// @termsofservice  http://swagger.io/terms/
+// @title          Swagger Example API
+// @Version        1.0
+// @description    This is a sample server celler server.
+// @termsofservice http://swagger.io/terms/
```
  • Loading branch information
MattKetmo committed Jun 30, 2022
1 parent 1cd0b53 commit 31cbc21
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion formatter.go
Expand Up @@ -78,7 +78,7 @@ func formatComments(fileName string, contents []byte, formattedComments []byte,
}

func formatFuncDoc(commentList []*ast.Comment, formattedComments io.Writer, oldCommentsMap map[string]string) {
w := tabwriter.NewWriter(formattedComments, 0, 0, 2, ' ', 0)
w := tabwriter.NewWriter(formattedComments, 0, 0, 1, ' ', 0)

for _, comment := range commentList {
text := comment.Text
Expand Down

0 comments on commit 31cbc21

Please sign in to comment.