interfaces.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package common
  2. // RouteContainer is the entrypoint for a service, which may contain multiple
  3. // routes under a common path with a common set of path parameters.
  4. type RouteContainer interface {
  5. // RootPath is the path that all contained routes are nested under.
  6. RootPath() string
  7. // PathParameters are common parameters defined in the root path.
  8. PathParameters() []Parameter
  9. // Routes are all routes exposed under the root path.
  10. Routes() []Route
  11. }
  12. // Route is a logical endpoint of a service.
  13. type Route interface {
  14. // Method defines the HTTP Method.
  15. Method() string
  16. // Path defines the route's endpoint.
  17. Path() string
  18. // OperationName defines a machine-readable ID for the route.
  19. OperationName() string
  20. // Parameters defines the list of accepted parameters.
  21. Parameters() []Parameter
  22. // Description is a human-readable route description.
  23. Description() string
  24. // Consumes defines the consumed content-types.
  25. Consumes() []string
  26. // Produces defines the produced content-types.
  27. Produces() []string
  28. // Metadata allows adding extensions to the generated spec.
  29. Metadata() map[string]interface{}
  30. // RequestPayloadSample defines an example request payload. Can return nil.
  31. RequestPayloadSample() interface{}
  32. // ResponsePayloadSample defines an example response payload. Can return nil.
  33. ResponsePayloadSample() interface{}
  34. // StatusCodeResponses defines a mapping of HTTP Status Codes to the specific response(s).
  35. // Multiple responses with the same HTTP Status Code are acceptable.
  36. StatusCodeResponses() []StatusCodeResponse
  37. }
  38. // StatusCodeResponse is an explicit response type with an HTTP Status Code.
  39. type StatusCodeResponse interface {
  40. // Code defines the HTTP Status Code.
  41. Code() int
  42. // Message returns the human-readable message.
  43. Message() string
  44. // Model defines an example payload for this response.
  45. Model() interface{}
  46. }
  47. // Parameter is a Route parameter.
  48. type Parameter interface {
  49. // Name defines the unique-per-route identifier.
  50. Name() string
  51. // Description is the human-readable description of the param.
  52. Description() string
  53. // Required defines if this parameter must be provided.
  54. Required() bool
  55. // Kind defines the type of the parameter itself.
  56. Kind() ParameterKind
  57. // DataType defines the type of data the parameter carries.
  58. DataType() string
  59. // AllowMultiple defines if more than one value can be supplied for the parameter.
  60. AllowMultiple() bool
  61. }
  62. // ParameterKind is an enum of route parameter types.
  63. type ParameterKind int
  64. const (
  65. // PathParameterKind indicates the request parameter type is "path".
  66. PathParameterKind = ParameterKind(iota)
  67. // QueryParameterKind indicates the request parameter type is "query".
  68. QueryParameterKind
  69. // BodyParameterKind indicates the request parameter type is "body".
  70. BodyParameterKind
  71. // HeaderParameterKind indicates the request parameter type is "header".
  72. HeaderParameterKind
  73. // FormParameterKind indicates the request parameter type is "form".
  74. FormParameterKind
  75. // UnknownParameterKind indicates the request parameter type has not been specified.
  76. UnknownParameterKind
  77. )