Swag: Using channels (`chan`) causes `swag` error with `not supported`

Created on 19 Apr 2020  路  6Comments  路  Source: swaggo/swag

Describe the bug
When using channel (chan) fields in response structure, swag init fails with message, e.g. not supported&{279 0 3 int}.

To Reproduce
Steps to reproduce the behavior:
example code:

type Response struct {
    ID      int      `json:"id"`
    control chan int `json:"-"`
}

// @Success 200 {object} Response
func GetResponse(c *gin.Context) {
}

Run swag init

Expected behavior
Why not just treating chan as an object?
Not mentioning: when this field is ignored (json:"-", as above) - I wouldn't expect swag to even look at it... (I saw also your latest swagignore, but in the code it is checked long after the getPropertyName, that fails)
If not the above, then at least, I would appreciate clear error message, currently it says: not supported&{279 0 3 int}, which seems not only missing space, but could be also more verbose in pointing more clearly what is the expression that fails.

Your swag version
swag version v1.6.5

Your go version
go version go1.14 linux/amd64

Additional context
Quick workaround, I used is to redefine (_wrap_) chan into a struct:

type Chan chan int

type Response struct {
    ID      int  `json:"id"`
    control Chan `json:"-"`
}

// @Success 200 {object} Response
func GetResponse(c *gin.Context) {
}

This actually made me think, that maybe chan should just be treated as object...

enhancement

Most helpful comment

before the new release fixing this problem, how can I ignore this error output and do my work?

If I use the branch refactored, how can I get the new command swag?

Sorry to bother you!

Enter dir github.com/swaggo/swag/cmd/swag, then run cmds:

git checkout refactored
go build    

All 6 comments

try branch refactored

Yes, that one works, beautiful! When do you plan to merge it?

Yes, that one works, beautiful! When do you plan to merge it?

I am not the owner of this repository, and refactor changed lots of code, merge may lead to some uncertain risk. Wait for @easonlin404 's consideration.

before the new release fixing this problem, how can I ignore this error output and do my work?

If I use the branch refactored, how can I get the new command swag?

Sorry to bother you!

before the new release fixing this problem, how can I ignore this error output and do my work?

If I use the branch refactored, how can I get the new command swag?

Sorry to bother you!

Enter dir github.com/swaggo/swag/cmd/swag, then run cmds:

git checkout refactored
go build    

m not the owner of this repository, and refactor changed lots of code, merge may lead to some uncertain risk. Wait for @easonlin404 's consideration.

@sdghchj I saw refactored branch has diverged with master. could you create a new PR?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

touyu picture touyu  路  3Comments

wingsofovnia picture wingsofovnia  路  3Comments

wuhuizuo picture wuhuizuo  路  4Comments

JimChung0403 picture JimChung0403  路  3Comments

kirillDanshin picture kirillDanshin  路  3Comments