Merge pull request #526 from wilhelmguo/master

fix *time.Time type parse error.
This commit is contained in:
astaxie 2018-07-21 22:29:20 +08:00 committed by GitHub
commit f496e0f36f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -78,7 +78,7 @@ var basicTypes = map[string]string{
"byte": "string:byte", "byte": "string:byte",
"rune": "string:byte", "rune": "string:byte",
// builtin golang objects // builtin golang objects
"time.Time": "string:string", "time.Time": "string:datetime",
} }
var stdlibObject = map[string]string{ var stdlibObject = map[string]string{
@ -1051,7 +1051,7 @@ func parseStruct(st *ast.StructType, k string, m *swagger.Schema, realTypes *[]s
isObject := false isObject := false
if isSlice { if isSlice {
mp.Type = "array" mp.Type = "array"
if isBasicType(strings.Replace(realType, "[]", "", -1)) { if sType, ok := basicTypes[(strings.Replace(realType, "[]", "", -1))]; ok {
typeFormat := strings.Split(sType, ":") typeFormat := strings.Split(sType, ":")
mp.Items = &swagger.Propertie{ mp.Items = &swagger.Propertie{
Type: typeFormat[0], Type: typeFormat[0],
@ -1198,6 +1198,9 @@ func typeAnalyser(f *ast.Field) (isSlice bool, realType, swaggerType string) {
switch t := f.Type.(type) { switch t := f.Type.(type) {
case *ast.StarExpr: case *ast.StarExpr:
basicType := fmt.Sprint(t.X) basicType := fmt.Sprint(t.X)
if object, isStdLibObject := stdlibObject[basicType]; isStdLibObject {
basicType = object
}
if k, ok := basicTypes[basicType]; ok { if k, ok := basicTypes[basicType]; ok {
return false, basicType, k return false, basicType, k
} }