mirror of
https://github.com/beego/bee.git
synced 2024-11-22 05:00:54 +00:00
add swagger spec support for struct embedded field
This commit is contained in:
parent
76a4feb17e
commit
363abeeae2
@ -1092,14 +1092,40 @@ func parseStruct(st *ast.StructType, k string, m *swagger.Schema, realTypes *[]s
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, pkg := range astPkgs {
|
// only parse case of when embedded field is TypeName
|
||||||
for _, fl := range pkg.Files {
|
// cases of *TypeName and Interface are not handled, maybe useless for swagger spec
|
||||||
for nameOfObj, obj := range fl.Scope.Objects {
|
tag := ""
|
||||||
if obj.Name == fmt.Sprint(field.Type) {
|
if field.Tag != nil {
|
||||||
parseObject(obj, nameOfObj, m, realTypes, astPkgs, pkg.Name)
|
stag := reflect.StructTag(strings.Trim(field.Tag.Value, "`"))
|
||||||
|
tag = stag.Get("json")
|
||||||
|
}
|
||||||
|
|
||||||
|
if tag != "" {
|
||||||
|
tagValues := strings.Split(tag, ",")
|
||||||
|
if tagValues[0] == "-" {
|
||||||
|
//if json tag is "-", omit
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
//if json tag is "something", output: something #definition/pkgname.Type
|
||||||
|
m.Properties[tagValues[0]] = mp
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//if no json tag, expand all fields of the type here
|
||||||
|
nm := &swagger.Schema{}
|
||||||
|
for _, pkg := range astPkgs {
|
||||||
|
for _, fl := range pkg.Files {
|
||||||
|
for nameOfObj, obj := range fl.Scope.Objects {
|
||||||
|
if obj.Name == fmt.Sprint(field.Type) {
|
||||||
|
parseObject(obj, nameOfObj, nm, realTypes, astPkgs, pkg.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for name, p := range nm.Properties {
|
||||||
|
m.Properties[name] = p
|
||||||
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user