spec.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. Annotations []Annotation
  55. Routes []Route
  56. Groups []Group
  57. }
  58. Type struct {
  59. Name string
  60. Annotations []Annotation
  61. Members []Member
  62. }
  63. // 系统预设基本数据类型
  64. BasicType struct {
  65. StringExpr string
  66. Name string
  67. }
  68. PointerType struct {
  69. StringExpr string
  70. // it can be asserted as BasicType: int、bool、
  71. // PointerType: *string、*User、
  72. // MapType: map[${BasicType}]interface、
  73. // ArrayType:[]int、[]User、[]*User
  74. // InterfaceType: interface{}
  75. // Type
  76. Star interface{}
  77. }
  78. MapType struct {
  79. StringExpr string
  80. // only support the BasicType
  81. Key string
  82. // it can be asserted as BasicType: int、bool、
  83. // PointerType: *string、*User、
  84. // MapType: map[${BasicType}]interface、
  85. // ArrayType:[]int、[]User、[]*User
  86. // InterfaceType: interface{}
  87. // Type
  88. Value interface{}
  89. }
  90. ArrayType struct {
  91. StringExpr string
  92. // it can be asserted as BasicType: int、bool、
  93. // PointerType: *string、*User、
  94. // MapType: map[${BasicType}]interface、
  95. // ArrayType:[]int、[]User、[]*User
  96. // InterfaceType: interface{}
  97. // Type
  98. ArrayType interface{}
  99. }
  100. InterfaceType struct {
  101. StringExpr string
  102. // do nothing,just for assert
  103. }
  104. TimeType struct {
  105. StringExpr string
  106. }
  107. StructType struct {
  108. StringExpr string
  109. }
  110. )
  111. func (spec *ApiSpec) ContainsTime() bool {
  112. for _, item := range spec.Types {
  113. members := item.Members
  114. for _, member := range members {
  115. if _, ok := member.Expr.(*TimeType); ok {
  116. return true
  117. }
  118. }
  119. }
  120. return false
  121. }