1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 05:00:54 +00:00

fixbug: ignore tag did not works; set property type to the second tag value only if it is not omitempty and isBasicType

This commit is contained in:
wucheng 2020-08-12 10:19:09 +08:00
parent 732fdfa321
commit b56b3794e4

View File

@ -1143,6 +1143,10 @@ func parseStruct(st *ast.StructType, k string, m *swagger.Schema, realTypes *[]s
} }
} }
if ignore := stag.Get("ignore"); ignore != "" {
continue
}
tag := stag.Get("json") tag := stag.Get("json")
if tag != "" { if tag != "" {
tagValues = strings.Split(tag, ",") tagValues = strings.Split(tag, ",")
@ -1156,6 +1160,14 @@ func parseStruct(st *ast.StructType, k string, m *swagger.Schema, realTypes *[]s
name = tagValues[0] name = tagValues[0]
} }
// set property type to the second tag value only if it is not omitempty and isBasicType
if len(tagValues) > 1 && tagValues[1] != "omitempty" && isBasicType(tagValues[1]) {
typeFormat := strings.Split(basicTypes[tagValues[1]], ":")
mp.Type = typeFormat[0]
mp.Format = typeFormat[1]
mp.Ref = ""
}
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] != "" {
@ -1175,15 +1187,15 @@ func parseStruct(st *ast.StructType, k string, m *swagger.Schema, realTypes *[]s
m.Properties[name] = mp m.Properties[name] = mp
} }
if ignore := stag.Get("ignore"); ignore != "" {
continue
}
} else { } else {
// only parse case of when embedded field is TypeName // only parse case of when embedded field is TypeName
// cases of *TypeName and Interface are not handled, maybe useless for swagger spec // cases of *TypeName and Interface are not handled, maybe useless for swagger spec
tag := "" tag := ""
if field.Tag != nil { if field.Tag != nil {
stag := reflect.StructTag(strings.Trim(field.Tag.Value, "`")) stag := reflect.StructTag(strings.Trim(field.Tag.Value, "`"))
if ignore := stag.Get("ignore"); ignore != "" {
continue
}
tag = stag.Get("json") tag = stag.Get("json")
} }