spec.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 // Deprecated: useless expression
  20. Syntax ApiSyntax // Deprecated: useless expression
  21. Imports []Import // Deprecated: useless expression
  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. // Deprecated: Use Service AtServer instead.
  64. AtServerAnnotation Annotation
  65. Method string
  66. Path string
  67. RequestType Type
  68. ResponseType Type
  69. Docs Doc
  70. Handler string
  71. AtDoc AtDoc
  72. HandlerDoc Doc
  73. HandlerComment Doc
  74. Doc Doc
  75. Comment Doc
  76. }
  77. // Service describes api service
  78. Service struct {
  79. Name string
  80. Groups []Group
  81. }
  82. // Type defines api type
  83. Type interface {
  84. Name() string
  85. Comments() []string
  86. Documents() []string
  87. }
  88. // DefineStruct describes api structure
  89. DefineStruct struct {
  90. RawName string
  91. Members []Member
  92. Docs Doc
  93. }
  94. // PrimitiveType describes the basic golang type, such as bool,int32,int64, ...
  95. PrimitiveType struct {
  96. RawName string
  97. }
  98. // MapType describes a map for api
  99. MapType struct {
  100. RawName string
  101. // only support the PrimitiveType
  102. Key string
  103. // it can be asserted as PrimitiveType: int、bool、
  104. // PointerType: *string、*User、
  105. // MapType: map[${PrimitiveType}]interface、
  106. // ArrayType:[]int、[]User、[]*User
  107. // InterfaceType: interface{}
  108. // Type
  109. Value Type
  110. }
  111. // ArrayType describes a slice for api
  112. ArrayType struct {
  113. RawName string
  114. Value Type
  115. }
  116. // InterfaceType describes an interface for api
  117. InterfaceType struct {
  118. RawName string
  119. }
  120. // PointerType describes a pointer for api
  121. PointerType struct {
  122. RawName string
  123. Type Type
  124. }
  125. // AtDoc describes a metadata for api grammar: @doc(...)
  126. AtDoc struct {
  127. Properties map[string]string
  128. Text string
  129. }
  130. )