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

fix: fmt issue with struct #1248

Merged
merged 1 commit into from
Jun 30, 2022
Merged

Conversation

MattKetmo
Copy link
Contributor

Fix issue #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:

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):

-// @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/

I don't know if there was a reason for the choice of padding=2 apart aesthetic.
Ping @HYY-yu who first use it in commit 93acd2ad

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/
```
Copy link
Contributor

@ubogdan ubogdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codecov
Copy link

codecov bot commented Jun 30, 2022

Codecov Report

Merging #1248 (1524e3a) into master (1cd0b53) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1248   +/-   ##
=======================================
  Coverage   94.98%   94.99%           
=======================================
  Files          14       14           
  Lines        2614     2618    +4     
=======================================
+ Hits         2483     2487    +4     
  Misses         72       72           
  Partials       59       59           
Impacted Files Coverage Δ
formatter.go 100.00% <100.00%> (ø)
generics.go 94.02% <0.00%> (+0.37%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1cd0b53...1524e3a. Read the comment docs.

@ubogdan ubogdan merged commit bd21bb0 into swaggo:master Jun 30, 2022
@ubogdan
Copy link
Contributor

ubogdan commented Jun 30, 2022

@MattKetmo Thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants