spec.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package spec
  2. // RoutePrefixKey is the prefix keyword for the routes.
  3. const RoutePrefixKey = "prefix"
  4. type (
  5. // Doc describes document
  6. Doc []string
  7. // Annotation defines key-value
  8. Annotation struct {
  9. Properties map[string]string
  10. }
  11. // ApiSyntax describes the syntax grammar
  12. ApiSyntax struct {
  13. Version string
  14. Doc Doc
  15. Comment Doc
  16. }
  17. // ApiSpec describes an api file
  18. ApiSpec struct {
  19. Info Info
  20. Syntax ApiSyntax
  21. Imports []Import
  22. Types []Type
  23. Service Service
  24. }
  25. // Import describes api import
  26. Import struct {
  27. Value string
  28. Doc Doc
  29. Comment Doc
  30. }
  31. // Group defines a set of routing information
  32. Group struct {
  33. Annotation Annotation
  34. Routes []Route
  35. }
  36. // Info describes info grammar block
  37. Info struct {
  38. // Deprecated: use Properties instead
  39. Title string
  40. // Deprecated: use Properties instead
  41. Desc string
  42. // Deprecated: use Properties instead
  43. Version string
  44. // Deprecated: use Properties instead
  45. Author string
  46. // Deprecated: use Properties instead
  47. Email string
  48. Properties map[string]string
  49. }
  50. // Member describes the field of a structure
  51. Member struct {
  52. Name string
  53. // 数据类型字面值,如:string、map[int]string、[]int64、[]*User
  54. Type Type
  55. Tag string
  56. Comment string
  57. // 成员头顶注释说明
  58. Docs Doc
  59. IsInline bool
  60. }
  61. // Route describes api route
  62. Route struct {
  63. AtServerAnnotation Annotation
  64. Method string
  65. Path string
  66. RequestType Type
  67. ResponseType Type
  68. Docs Doc
  69. Handler string
  70. AtDoc AtDoc
  71. HandlerDoc Doc
  72. HandlerComment Doc
  73. Doc Doc
  74. Comment Doc
  75. }
  76. // Service describes api service
  77. Service struct {
  78. Name string
  79. Groups []Group
  80. }
  81. // Type defines api type
  82. Type interface {
  83. Name() string
  84. Comments() []string
  85. Documents() []string
  86. }
  87. // DefineStruct describes api structure
  88. DefineStruct struct {
  89. RawName string
  90. Members []Member
  91. Docs Doc
  92. }
  93. // PrimitiveType describes the basic golang type, such as bool,int32,int64, ...
  94. PrimitiveType struct {
  95. RawName string
  96. }
  97. // MapType describes a map for api
  98. MapType struct {
  99. RawName string
  100. // only support the PrimitiveType
  101. Key string
  102. // it can be asserted as PrimitiveType: int、bool、
  103. // PointerType: *string、*User、
  104. // MapType: map[${PrimitiveType}]interface、
  105. // ArrayType:[]int、[]User、[]*User
  106. // InterfaceType: interface{}
  107. // Type
  108. Value Type
  109. }
  110. // ArrayType describes a slice for api
  111. ArrayType struct {
  112. RawName string
  113. Value Type
  114. }
  115. // InterfaceType describes an interface for api
  116. InterfaceType struct {
  117. RawName string
  118. }
  119. // PointerType describes a pointer for api
  120. PointerType struct {
  121. RawName string
  122. Type Type
  123. }
  124. // AtDoc describes a metadata for api grammar: @doc(...)
  125. AtDoc struct {
  126. Properties map[string]string
  127. Text string
  128. }
  129. )