Swag: Docs generation loop

Created on 8 Apr 2018  Â·  7Comments  Â·  Source: swaggo/swag

I'm getting too many messages when generating docs by swag init:

➜  api git:(master) swag init
2018/04/08 19:00:18 Generate swagger docs....
2018/04/08 19:00:18 Generate general API Info
2018/04/08 19:00:18 Generating models.Transaction
2018/04/08 19:00:18 Generating models.Wallet
2018/04/08 19:00:18 Skipping 'models.Wallet', already present.
2018/04/08 19:00:18 Skipping 'models.Wallet', already present.
2018/04/08 19:00:18 Skipping 'models.Wallet', already present.
2018/04/08 19:00:18 Skipping 'models.Wallet', already present.
2018/04/08 19:00:18 Skipping 'models.Wallet', already present.
...

2018/04/08 23:45:34 Skipping 'models.Wallet', already present.
2018/04/08 23:45:34 Skipping 'models.Wallet', already present.
2018/04/08 23:45:34 Skipping 'models.Wallet', already present.
2018/04/08 23:45:34 Skipping 'models.Wallet', already present.
2018/04/08 23:45:34 Skipping 'models.Wallet', already present.
2018/04/08 23:45:34 Skipping 'models.Wallet', already present.
2018/04/08 23:45:34 Skipping 'models.Wallet', already present.
2018/04/08 23:45:34 Skipping 'models.Wallet', already present.
2018/04/08 23:45:34 Skipping 'models.Wallet', already present.
2018/04/08 23:45:34 Skipping 'models.Wallet', already present.
2018/04/08 23:45:34 Skipping 'models.Wallet', already present.
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

runtime stack:
runtime.throw(0x140f46e, 0xe)
    /usr/local/Cellar/go/1.10.1/libexec/src/runtime/panic.go:616 +0x81
runtime.newstack()
    /usr/local/Cellar/go/1.10.1/libexec/src/runtime/stack.go:1054 +0x71f
runtime.morestack()
    /usr/local/Cellar/go/1.10.1/libexec/src/runtime/asm_amd64.s:480 +0x89

goroutine 1 [running]:
github.com/swaggo/swag.(*Parser).parseStruct(0xc4204057a0, 0xc4203d4499, 0x6, 0xc4201febc0, 0x0)
    /Users/drubtsov/.go/src/github.com/swaggo/swag/parser.go:397 +0xf33 fp=0xc440600a08 sp=0xc440600a00 pc=0x131f413
github.com/swaggo/swag.(*Parser).parseTypeSpec(0xc4204057a0, 0xc4203d4499, 0x6, 0xc420420e40, 0xc43a048f00)
    /Users/drubtsov/.go/src/github.com/swaggo/swag/parser.go:381 +0x24d fp=0xc440600f18 sp=0xc440600a08 pc=0x131e37d
github.com/swaggo/swag.(*Parser).ParseDefinition(0xc4204057a0, 0xc4203d4499, 0x6, 0xc420420e40, 0xc43a044486, 0x6)
    /Users/drubtsov/.go/src/github.com/swaggo/swag/parser.go:351 +0xf9 fp=0xc440601688 sp=0xc440600f18 pc=0x131dbd9
github.com/swaggo/swag.(*Parser).parseStruct(0xc4204057a0, 0xc4203d4499, 0x6, 0xc4201fee40, 0xc43a048e70)

...additional frames elided...

One doc declaration:

// @Summary Update current user
// @ID update-user
// @Accept  json
// @Produce  json
// @Success 200 {object} models.User
// @Router /v1/user [put]
func (*userControllers) Update(c *gin.Context) {}

My models:

type User struct {
    ID            uint     `json:"id" gorm:"primary_key;unique"`
    Email         string   `json:"email" gorm:"unique_index"`
    PassHash      string   `json:"pass_hash"`
    Role          string   `json:"role"`
    Wallets       []Wallet `gorm:"foreignkey:OwnerID;association_foreignkey:ID"`
    FamiliesOwner []Family `json:"families" gorm:"foreignkey:OwnerID;association_foreignkey:ID"`
    Families      []Family `gorm:"many2many:user_families;"`
}

type Wallet struct {
    ID           uint          `json:"id" gorm:"primary_key;unique"`
    OwnerID      uint          `json:"owner_id"`
    FamilyID     uint          `json:"family_id"`
    CurrencyID   uint          `json:"currency_id"`
    Value        float64       `json:"value"`
    IsDeleted    bool          `json:"is_deleted"`
    Transactions []Transaction `json:"transactions" gorm:"foreignkey:WalletID;association_foreignkey:ID"`
}

type Transaction struct {
    ID       uint      `json:"id" gorm:"primary_key;unique"`
    WalletID uint      `json:"wallet_id"`
    Value    uint      `json:"value"`
    Date     time.Time `json:"date"`
}

Also, Maybe I can skip some fields in struct for a documentation?

bug feature

Most helpful comment

I'm running swag v1.2.0

I've created sample project with error — https://github.com/dmirubtsov/swag-example, you can check it with docker, simply run in project folder:

docker-compose up

All 7 comments

Now I don't prepare field skip and I check it.

I could not reproduce the problem.
What version do you have?

I will create skip field method.

I'm running swag v1.2.0

I've created sample project with error — https://github.com/dmirubtsov/swag-example, you can check it with docker, simply run in project folder:

docker-compose up

OK I check.

This was a very difficult problem.
Please give me some more time.

@dmirubtsov Please update to the latest version and try again. Reopen it if still have any problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LennyPenny picture LennyPenny  Â·  4Comments

kirillDanshin picture kirillDanshin  Â·  3Comments

wuhuizuo picture wuhuizuo  Â·  4Comments

koddr picture koddr  Â·  3Comments

chiragg6 picture chiragg6  Â·  7Comments