From 31cbc21561002f7fa1c6bfa226de9aeaff03ef03 Mon Sep 17 00:00:00 2001 From: Matthieu Moquet Date: Thu, 30 Jun 2022 14:13:10 +0200 Subject: [PATCH] Fix issue https://github.com/swaggo/swag/issues/1150 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/ ``` --- formatter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formatter.go b/formatter.go index ca3e24c0f..4ad002ebd 100644 --- a/formatter.go +++ b/formatter.go @@ -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