spec.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package spec
  2. type (
  3. Annotation struct {
  4. Name string
  5. Properties map[string]string
  6. Value string
  7. }
  8. ApiSpec struct {
  9. Info Info
  10. Types []Type
  11. Service Service
  12. }
  13. Group struct {
  14. Annotations []Annotation
  15. Routes []Route
  16. }
  17. Info struct {
  18. Title string
  19. Desc string
  20. Version string
  21. Author string
  22. Email string
  23. }
  24. Member struct {
  25. Annotations []Annotation
  26. Name string
  27. // 数据类型字面值,如:string、map[int]string、[]int64、[]*User
  28. Type string
  29. // it can be asserted as BasicType: int、bool、
  30. // PointerType: *string、*User、
  31. // MapType: map[${BasicType}]interface、
  32. // ArrayType:[]int、[]User、[]*User
  33. // InterfaceType: interface{}
  34. // Type
  35. Expr interface{}
  36. Tag string
  37. // Deprecated
  38. Comment string // 换成标准struct中将废弃
  39. // 成员尾部注释说明
  40. Comments []string
  41. // 成员头顶注释说明
  42. Docs []string
  43. IsInline bool
  44. }
  45. Route struct {
  46. Annotations []Annotation
  47. Method string
  48. Path string
  49. RequestType Type
  50. ResponseType Type
  51. }
  52. Service struct {
  53. Name string
  54. Groups []Group
  55. }
  56. Type struct {
  57. Name string
  58. Annotations []Annotation
  59. Members []Member
  60. }
  61. // 系统预设基本数据类型
  62. BasicType struct {
  63. StringExpr string
  64. Name string
  65. }
  66. PointerType struct {
  67. StringExpr string
  68. // it can be asserted as BasicType: int、bool、
  69. // PointerType: *string、*User、
  70. // MapType: map[${BasicType}]interface、
  71. // ArrayType:[]int、[]User、[]*User
  72. // InterfaceType: interface{}
  73. // Type
  74. Star interface{}
  75. }
  76. MapType struct {
  77. StringExpr string
  78. // only support the BasicType
  79. Key string
  80. // it can be asserted as BasicType: int、bool、
  81. // PointerType: *string、*User、
  82. // MapType: map[${BasicType}]interface、
  83. // ArrayType:[]int、[]User、[]*User
  84. // InterfaceType: interface{}
  85. // Type
  86. Value interface{}
  87. }
  88. ArrayType struct {
  89. StringExpr string
  90. // it can be asserted as BasicType: int、bool、
  91. // PointerType: *string、*User、
  92. // MapType: map[${BasicType}]interface、
  93. // ArrayType:[]int、[]User、[]*User
  94. // InterfaceType: interface{}
  95. // Type
  96. ArrayType interface{}
  97. }
  98. InterfaceType struct {
  99. StringExpr string
  100. // do nothing,just for assert
  101. }
  102. TimeType struct {
  103. StringExpr string
  104. }
  105. StructType struct {
  106. StringExpr string
  107. }
  108. )
  109. func (spec *ApiSpec) ContainsTime() bool {
  110. for _, item := range spec.Types {
  111. members := item.Members
  112. for _, member := range members {
  113. if _, ok := member.Expr.(*TimeType); ok {
  114. return true
  115. }
  116. }
  117. }
  118. return false
  119. }