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

Docs generation loop #88

Closed
dmirubtsov opened this Issue Apr 8, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@dmirubtsov
Copy link

dmirubtsov commented Apr 8, 2018

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?

@pei0804

This comment has been minimized.

Copy link
Member

pei0804 commented Apr 8, 2018

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

@pei0804

This comment has been minimized.

Copy link
Member

pei0804 commented Apr 8, 2018

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

I will create skip field method.

@dmirubtsov

This comment has been minimized.

Copy link

dmirubtsov commented Apr 9, 2018

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
@pei0804

This comment has been minimized.

Copy link
Member

pei0804 commented Apr 9, 2018

OK I check.

@pei0804

This comment has been minimized.

Copy link
Member

pei0804 commented Apr 9, 2018

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

@pei0804

This comment has been minimized.

Copy link
Member

pei0804 commented Apr 9, 2018

I fix it. #92

@easonlin404

This comment has been minimized.

Copy link
Member

easonlin404 commented Apr 10, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment