spec.go 2.8 KB

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