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

Upgrade to go 1.18 for generics parsing support #1162

Closed
b2ku opened this issue Mar 16, 2022 · 9 comments · Fixed by #1168
Closed

Upgrade to go 1.18 for generics parsing support #1162

b2ku opened this issue Mar 16, 2022 · 9 comments · Fixed by #1168

Comments

@b2ku
Copy link

b2ku commented Mar 16, 2022

Is your feature request related to a problem? Please describe.
Unable to swag init --parseDependency where deps are using generic features

% swag init --parseDependency
...
2022/03/16 12:38:37 ParseFile error:/path/to/package@v0.1.0/something.go:8:16: expected '(', found '[' (and 7 more errors)

Describe the solution you'd like
The ability to init swagger docs with dependencies that use generic language features

Describe alternatives you've considered
Cloning and updating the go.mod to 1.18 and compiling locally for the time being.

Additional context
n/a

@b2ku
Copy link
Author

b2ku commented Mar 16, 2022

related to #1104 (comment) I tried compiling swag with 1.18 and it passes my prior error but is unable to find the new alias any:

swag init --parseDependency
...
2022/03/16 12:45:52 ParseComment error in file /path/to/package@v0.1.0/something.go :cannot find type definition: any

@ubogdan
Copy link
Contributor

ubogdan commented Mar 16, 2022

I see building swag against go 1.18 is not enough.

@b2ku
Copy link
Author

b2ku commented Mar 17, 2022

For what its worth, swapping out the any alias with interface{} gets around the error. This only works if you control the libraries which likely isn't possible in all cases.

b2ku added a commit to b2ku/swag that referenced this issue Mar 17, 2022
b2ku added a commit to b2ku/swag that referenced this issue Mar 17, 2022
b2ku added a commit to b2ku/swag that referenced this issue Mar 17, 2022
@b2ku
Copy link
Author

b2ku commented Mar 17, 2022

@ubogdan i've put togther an adhoc fix for myself here b2ku@6d3d4c9 in addition to bumping to 1.18

It seems to work with my own packages that use any judiciously. I don't have a good working knowledge of swag so I don't know if this sort of change is worth a PR.

@al4669
Copy link

al4669 commented Mar 17, 2022

I've also noticed it fails when you have any type constraint declarations in your code:

type Number interface {
	int32 | int64
}

error: expected ';', found '|' (and 1 more errors)

@applejag
Copy link
Contributor

applejag commented Mar 30, 2022

@rdlaitila I hope you don't mind that I publishes your changes as a PR in #1168.

It's not released yet, so in the meantime you can do the following to install the Go 1.18 compatible version of Swaggo:
Edit: It's now released and available since v1.8.1:

go install github.com/swaggo/swag/cmd/swag@v1.8.1

@b2ku
Copy link
Author

b2ku commented Mar 30, 2022

@jilleJr no problem. I was not sure those changes were even structurally or logically sound for swag so I was hesitant. TY!

@hcsaustrup
Copy link

hcsaustrup commented Apr 4, 2022

I had the same issue, and it seems parsing of the actual code was fixed with v1.8.1. The // @success 200 {object} model.Response[SomeType] annotation still fails when attempting to specify a generic struct as a response object. Is the syntax for describing a generic struct response documented anywhere? :-)

@applejag
Copy link
Contributor

applejag commented Apr 6, 2022

@hcsaustrup Deserves a separate issue IMO. The PR was only fixing the fact that swaggo would fail to parse Go 1.18 code to begin with and did not understand the new any keyword.

To parse generic types in the swaggo comments would be a different story, I presume, and would involve a bit more technical details.

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 a pull request may close this issue.

5 participants