spec.go 2.8 KB

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