beego/bee — pull request #75 by jmsegrev (2014-10-22 16:06:08+00:00)
Title: Fix for api docs generate bug

A handler with ```// @Success 200 {object} models.User```

```
package models

type User struct {
baseModel
Id bson.ObjectId `bson:"_id,omitempty"`
Name string
Email string
Username string
Password []byte `json:"-"`
Active bool
VerificationHash string `bson:",omitempty" json:"-,omitempty"`
Verified bool `bson:",omitempty" json:"omitempty"`
}

```

After ```bee generate docs``` will result:
```
panic: runtime error: index out of range

goroutine 16 [running]:
runtime.panic(0x877e40, 0xb79e9c)
/usr/local/go/src/pkg/runtime/panic.c:279 +0xf5
main.getModel(0xc2080ef8b0, 0xb, 0xc2080ef8b0, 0x6, 0xc2080ef8b7, 0x4, 0xc2080ef8e0, 0x4, 0x0, 0x0, ...)
/home/verges/Workspace/go/src/github.com/beego/bee/g_docs.go:565 +0xed1
main.parserComments(0xc2080f42c0, 0xc2080ee544, 0x4, 0xc2080ef720, 0xe, 0xc20800f8f1, 0x26, 0x0, 0x0)
/home/verges/Workspace/go/src/github.com/beego/bee/g_docs.go:397 +0x12fd
main.analisyscontrollerPkg(0xc20800f8f1, 0x26)
/home/verges/Workspace/go/src/github.com/beego/bee/g_docs.go:306 +0x95e
main.generateDocs(0xc208042b80, 0x38)
/home/verges/Workspace/go/src/github.com/beego/bee/g_docs.go:150 +0x523
main.generateCode(0xb779c0, 0xc20800e020, 0x1, 0x1, 0x0)
/home/verges/Workspace/go/src/github.com/beego/bee/g.go:125 +0xb51
main.main()
/home/verges/Workspace/go/src/github.com/beego/bee/bee.go:113 +0x33a
```
The previous runtime error is due to the anonymous field having no name.

Also if there was no anonymous field (baseModel) in User struct, the object description would result:
```
User {
- ([]byte, optional): , // wrong name, and I want it hidden
-,omitempty (string, optional): , // wrong name, and I want it hidden
Active (bool, optional): ,
Email (string, optional): ,
Id (&{bson ObjectId}, optional): ,
Name (string, optional): ,
Username (string, optional): ,
omitempty (bool, optional): // wrong name
}
```

This pull request fixes the anonymous field bug, adds support for hidden fields on api docs object description by using ```json:"-"```, and avoids the use of "-" and "omitempty" as field name.

With pull request, object description result:
```
User {
Active (bool, optional): ,
Email (string, optional): ,
Id (&{bson ObjectId}, optional): ,
Name (string, optional): ,
Username (string, optional): ,
Verified (bool, optional):
}
```