fix *time.Time type parse error.

This commit is contained in:
guoshaowei 2018-05-10 14:37:03 +08:00
parent e90da8f77b
commit bb68873f45
2 changed files with 6 additions and 3 deletions

View File

@ -57,7 +57,7 @@ Prints the current Bee, Beego and Go version alongside the platform information.
} }
var outputFormat string var outputFormat string
const version = "1.9.1" const version = "1.9.2"
func init() { func init() {
fs := flag.NewFlagSet("version", flag.ContinueOnError) fs := flag.NewFlagSet("version", flag.ContinueOnError)

View File

@ -77,7 +77,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{
@ -919,7 +919,7 @@ func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string
mp := swagger.Propertie{} mp := swagger.Propertie{}
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],
@ -1035,6 +1035,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
} }