Skip to content

Upgrade to go 1.18 for generics parsing support #1162

Closed

Description

@rdlaitila

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

Activity

  1. rdlaitila commented on Mar 16, 2022

    @rdlaitila
    Author

    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
    
  2. ubogdan commented on Mar 16, 2022

    @ubogdan
    Contributor

    I see building swag against go 1.18 is not enough.

  3. rdlaitila commented on Mar 17, 2022

    @rdlaitila
    Author

    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.

  4. rdlaitila commented on Mar 17, 2022

    @rdlaitila
    Author

    @ubogdan i've put togther an adhoc fix for myself here https://github.com/rdlaitila/swag/commit/6d3d4c96d30bfc34d588a560c8944b470e0c40b6 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.

  5. al4669 commented on Mar 17, 2022

    @al4669

    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)
    
  6. applejag commented on Mar 30, 2022

    @applejag

    @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
  7. rdlaitila commented on Mar 30, 2022

    @rdlaitila
    Author

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

  8. hcsaustrup commented on Apr 4, 2022

    @hcsaustrup

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

  9. applejag commented on Apr 6, 2022

    @applejag

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址