spec.go 2.6 KB

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