1
0
mirror of https://github.com/beego/bee.git synced 2024-12-22 10:00:50 +00:00

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

View File

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