mirror of
https://github.com/beego/bee.git
synced 2024-11-26 06:21:34 +00:00
Merge pull request #75 from jmsegrev/master
Fix for api docs generate bug
This commit is contained in:
commit
52d6031795
36
g_docs.go
36
g_docs.go
@ -570,13 +570,35 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Model, realType
|
|||||||
} else {
|
} else {
|
||||||
mp.Type = realType
|
mp.Type = realType
|
||||||
}
|
}
|
||||||
// if the tag contains json tag, set the name to the left most json tag
|
|
||||||
|
// dont add property if anonymous field
|
||||||
|
if field.Names != nil {
|
||||||
|
|
||||||
|
// set property name as field name
|
||||||
var name = field.Names[0].Name
|
var name = field.Names[0].Name
|
||||||
if field.Tag != nil {
|
|
||||||
stag := reflect.StructTag(strings.Trim(field.Tag.Value, "`"))
|
// if no tag skip tag processing
|
||||||
if tag := stag.Get("json"); tag != "" {
|
if field.Tag == nil {
|
||||||
name = tag
|
m.Properties[name] = mp
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tagValues []string
|
||||||
|
stag := reflect.StructTag(strings.Trim(field.Tag.Value, "`"))
|
||||||
|
tag := stag.Get("json")
|
||||||
|
|
||||||
|
if tag != "" {
|
||||||
|
tagValues = strings.Split(tag, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
// dont add property if json tag first value is "-"
|
||||||
|
if len(tagValues) == 0 || tagValues[0] != "-" {
|
||||||
|
|
||||||
|
// set property name to the left most json tag value only if is not omitempty
|
||||||
|
if len(tagValues) > 0 && tagValues[0] != "omitempty" {
|
||||||
|
name = tagValues[0]
|
||||||
|
}
|
||||||
|
|
||||||
if thrifttag := stag.Get("thrift"); thrifttag != "" {
|
if thrifttag := stag.Get("thrift"); thrifttag != "" {
|
||||||
ts := strings.Split(thrifttag, ",")
|
ts := strings.Split(thrifttag, ",")
|
||||||
if ts[0] != "" {
|
if ts[0] != "" {
|
||||||
@ -589,11 +611,13 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Model, realType
|
|||||||
if desc := stag.Get("description"); desc != "" {
|
if desc := stag.Get("description"); desc != "" {
|
||||||
mp.Description = desc
|
mp.Description = desc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.Properties[name] = mp
|
||||||
|
}
|
||||||
if ignore := stag.Get("ignore"); ignore != "" {
|
if ignore := stag.Get("ignore"); ignore != "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Properties[name] = mp
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user