From 29c9e1bab765bd1b360edfbc1e3a6d8a50571206 Mon Sep 17 00:00:00 2001 From: astaxie Date: Thu, 22 Sep 2016 23:04:58 +0800 Subject: [PATCH] fix the map type generate --- g_docs.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/g_docs.go b/g_docs.go index 8a7f99d..a92c917 100644 --- a/g_docs.go +++ b/g_docs.go @@ -683,12 +683,18 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string } } } else { - if isBasicType(realType) { + if sType == "object" { + mp.Ref = "#/definitions/" + realType + } else if isBasicType(realType) { typeFormat := strings.Split(sType, ":") mp.Type = typeFormat[0] mp.Format = typeFormat[1] - } else if sType == "object" { - mp.Ref = "#/definitions/" + realType + } else if realType == "map" { + typeFormat := strings.Split(sType, ":") + mp.AdditionalProperties = &swagger.Propertie{ + Type: typeFormat[0], + Format: typeFormat[1], + } } } if field.Names != nil { @@ -768,7 +774,11 @@ func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) { case *ast.StarExpr: return false, fmt.Sprint(t.X), "object" case *ast.MapType: - return false, fmt.Sprint(t.Value), "object" + val := fmt.Sprintf("%v", t.Value) + if isBasicType(val) { + return false, "map", basicTypes[val] + } + return false, val, "object" } if k, ok := basicTypes[fmt.Sprint(f.Type)]; ok { return false, fmt.Sprint(f.Type), k