From b56b3794e481bf9be4d88afa2a614fb04bacd312 Mon Sep 17 00:00:00 2001 From: wucheng Date: Wed, 12 Aug 2020 10:19:09 +0800 Subject: [PATCH] fixbug: ignore tag did not works; set property type to the second tag value only if it is not omitempty and isBasicType --- generate/swaggergen/g_docs.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 48b54ad..b84b12d 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -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") }