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
1 changed files with 15 additions and 3 deletions

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")
if tag != "" {
tagValues = strings.Split(tag, ",")
@ -1156,6 +1160,14 @@ func parseStruct(st *ast.StructType, k string, m *swagger.Schema, realTypes *[]s
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 != "" {
ts := strings.Split(thrifttag, ",")
if ts[0] != "" {
@ -1175,15 +1187,15 @@ func parseStruct(st *ast.StructType, k string, m *swagger.Schema, realTypes *[]s
m.Properties[name] = mp
}
if ignore := stag.Get("ignore"); ignore != "" {
continue
}
} else {
// only parse case of when embedded field is TypeName
// cases of *TypeName and Interface are not handled, maybe useless for swagger spec
tag := ""
if field.Tag != nil {
stag := reflect.StructTag(strings.Trim(field.Tag.Value, "`"))
if ignore := stag.Get("ignore"); ignore != "" {
continue
}
tag = stag.Get("json")
}