swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.77k stars 1.2k forks source link

Bypass errors or completely skip package analysis/parsing #1867

Open maitredede opened 3 months ago

maitredede commented 3 months ago

Hello

Describe the bug

I use https://github.com/MarcoWel/gozxing in my code, but its code has invalid argument params : authors used @param comment syntax for methods, also used by swaggo. And swaggo tries to parse it.

// getCharacter Gets the character (or string) corresponding to the passed code in the given table
//
// @param table the table used
// @param code the code of the character
func getCharacter(table Table, code int) (string, error)
ParseComment error in file /home/memyselfandi/go/pkg/mod/github.com/!marco!wel/gozxing@v0.0.0-20240430191452-4f47d0b5ffcf/aztec/decoder/decoder.go :missing required param comment parameters "table the table used"

To Reproduce Steps to reproduce the behavior:

  1. Create a project that uses github.com/MarcoWel/gozxing
  2. swag init --parseDependency --parseDependencyLevel=2

Expected behavior Since the error is legit, I would like to skip this error, or totally skip the gozxing library.

I tried using .swaggo to skip library, and also some variants of the --exclude argument.

Screenshots N/A

Your swag version swag version v1.16.2

Your go version go version go1.22.6 linux/amd64

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

ubogdan commented 1 month ago

This issue comes from the fact you are importing the library in your handlers. Try to define an interface and to provide the implementation at runtime so swag won't try to parse it. :bulb: