forked from emicklei/go-restful-swagger12
-
Notifications
You must be signed in to change notification settings - Fork 7
/
util.go
executable file
·46 lines (42 loc) · 886 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package swagger
import (
"regexp"
)
func getModelName(name string) string {
reg := regexp.MustCompile("[a-z]+\\.")
modelName := reg.ReplaceAllString(name, "")
modelName = "#/definitions/" + modelName
return modelName
}
func getOtherName(name string) string {
switch name {
case "uint", "uint8", "uint16", "uint32", "uint64", "int", "int8", "int16", "int32", "int64", "byte":
return "integer"
case "float32", "float64":
return "number"
case "time.Time":
return "string"
case "bool":
return "boolean"
default:
return name
}
}
func getFormat(name string) string {
switch name {
case "int64":
return "int64"
case "int", "int32":
return "int32"
case "float32":
return "float"
case "float64":
return "double"
case "byte", "uint8":
return "byte"
case "time.Time", "*time.Time", "datetime", "dateTime":
return "date-time"
default:
return ""
}
}