spec.go 2.5 KB

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