example.api 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // syntax: specify the api syntax version,
  2. // through this version can be a good control
  3. // api syntax upgrade incompatibility issues
  4. syntax = "v1"
  5. // Info block is a key-value pair description body,
  6. // you can add some descriptions of the current api
  7. // file through this description body, you can add
  8. // any key-value pair, which does not participate in the api generation
  9. info(
  10. title: sample of api
  11. desc: "you can add a newline
  12. description by quotes"
  13. author: songmeizi
  14. anyAnotherKey: anyTnotherValue
  15. )
  16. // The structure in the api evolved from the structure of golang,
  17. // and it is also reserved to support the structure of golang.
  18. // a golang structure
  19. type Foo struct{
  20. Foo int
  21. }
  22. // api structure
  23. type Bar {
  24. Bar int
  25. }
  26. // structure group
  27. type (
  28. FooBar {
  29. Foo int
  30. Bar bool
  31. }
  32. )
  33. // Like the info block, @server can define any key-value pair.
  34. // The difference is that @server is a description of the service
  35. // block or route, which will participate in the api file generation.
  36. // There are several important keys that need to be understood,
  37. // which have special meanings. The jwt key is to declare that code
  38. // generation needs to include jwt authentication logic. The group key
  39. // is to declare that the files generated by the code need to be grouped
  40. // according to the value corresponding to the group. The handler key
  41. // determines the handler in golang. Layer file logic generation
  42. @server(
  43. jwt: Auth
  44. group: foo
  45. anyAnotherKey: anyTnotherValue
  46. )
  47. // service block is the description of the api service,
  48. // including @doc block, @handler and api routing information
  49. service foo-api {
  50. // shortening doc declaration
  51. @doc("foo")
  52. // shortening handler declaration
  53. @handler foo
  54. // route
  55. get /foo (Foo) returns (Bar)
  56. @doc(
  57. summary: foo
  58. )
  59. @server(
  60. handler: bar
  61. )
  62. post /bar (Foo)
  63. }