Skip to content

Commit

Permalink
fix: fmt issue with struct
Browse files Browse the repository at this point in the history
Fix issue swaggo#1150

To summarize of the issue, running `swag fmt` will set (at least) 2 spaces between the attribute tag and the rest of the comment.

For instance:

```
type Example struct {
	Foobar string
} // @name  Example
```

However the doc generation doesn't interpret this correctly for struct (it completly 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):

```
// @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 02a9baf
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 02a9baf

Please sign in to comment.