casaos_api.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // Package codegen provides primitives to interact with the openapi HTTP API.
  2. //
  3. // Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT.
  4. package codegen
  5. import (
  6. "bytes"
  7. "compress/gzip"
  8. "encoding/base64"
  9. "fmt"
  10. "net/url"
  11. "path"
  12. "strings"
  13. "github.com/getkin/kin-openapi/openapi3"
  14. "github.com/labstack/echo/v4"
  15. )
  16. const (
  17. Access_tokenScopes = "access_token.Scopes"
  18. )
  19. // BaseResponse defines model for BaseResponse.
  20. type BaseResponse struct {
  21. // Message message returned by server side if there is any
  22. Message *string `json:"message,omitempty"`
  23. }
  24. // HealthServices defines model for HealthServices.
  25. type HealthServices struct {
  26. NotRunning *[]string `json:"not_running,omitempty"`
  27. Running *[]string `json:"running,omitempty"`
  28. }
  29. // GetHealthServicesOK defines model for GetHealthServicesOK.
  30. type GetHealthServicesOK struct {
  31. Data *HealthServices `json:"data,omitempty"`
  32. // Message message returned by server side if there is any
  33. Message *string `json:"message,omitempty"`
  34. }
  35. // ResponseInternalServerError defines model for ResponseInternalServerError.
  36. type ResponseInternalServerError = BaseResponse
  37. // ResponseOK defines model for ResponseOK.
  38. type ResponseOK = BaseResponse
  39. // ServerInterface represents all server handlers.
  40. type ServerInterface interface {
  41. // Test file methods
  42. // (GET /file/test)
  43. GetFileTest(ctx echo.Context) error
  44. // Get service status
  45. // (GET /health/services)
  46. GetHealthServices(ctx echo.Context) error
  47. }
  48. // ServerInterfaceWrapper converts echo contexts to parameters.
  49. type ServerInterfaceWrapper struct {
  50. Handler ServerInterface
  51. }
  52. // GetFileTest converts echo context to params.
  53. func (w *ServerInterfaceWrapper) GetFileTest(ctx echo.Context) error {
  54. var err error
  55. ctx.Set(Access_tokenScopes, []string{""})
  56. // Invoke the callback with all the unmarshalled arguments
  57. err = w.Handler.GetFileTest(ctx)
  58. return err
  59. }
  60. // GetHealthServices converts echo context to params.
  61. func (w *ServerInterfaceWrapper) GetHealthServices(ctx echo.Context) error {
  62. var err error
  63. ctx.Set(Access_tokenScopes, []string{""})
  64. // Invoke the callback with all the unmarshalled arguments
  65. err = w.Handler.GetHealthServices(ctx)
  66. return err
  67. }
  68. // This is a simple interface which specifies echo.Route addition functions which
  69. // are present on both echo.Echo and echo.Group, since we want to allow using
  70. // either of them for path registration
  71. type EchoRouter interface {
  72. CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  73. DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  74. GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  75. HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  76. OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  77. PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  78. POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  79. PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  80. TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
  81. }
  82. // RegisterHandlers adds each server route to the EchoRouter.
  83. func RegisterHandlers(router EchoRouter, si ServerInterface) {
  84. RegisterHandlersWithBaseURL(router, si, "")
  85. }
  86. // Registers handlers, and prepends BaseURL to the paths, so that the paths
  87. // can be served under a prefix.
  88. func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) {
  89. wrapper := ServerInterfaceWrapper{
  90. Handler: si,
  91. }
  92. router.GET(baseURL+"/file/test", wrapper.GetFileTest)
  93. router.GET(baseURL+"/health/services", wrapper.GetHealthServices)
  94. }
  95. // Base64 encoded, gzipped, json marshaled Swagger object
  96. var swaggerSpec = []string{
  97. "H4sIAAAAAAAC/7xW70/jRhD9V1bTfoDKxBGoUmXpPnC9wiFUpSpIrUSi3GY9sfewd92ZcSBF/t+rXZtL",
  98. "SCiC649PiffHe2/e7szsAxhfN96hE4bsAQi58Y4xfpyjfERdSXmFtLIGeXIZho13gk7CX900lTVarHfp",
  99. "Z/YujLEpsdZxtqomS8huHuBbwiVk8E26YUv7dZy+14y/DrTQJQ/QkG+QxPYici0R7CWIpyqh67pZ13UJ",
  100. "5MiGbBPkQQaTS+gSeKS6cILkdBV2If1E5OlNwb0+pH0lj9yqJ1c9+5a4Nxr9T7QEV7pkAIuOP9mR7Z5H",
  101. "jcy6iBNPgYYJRSgtOczVYq24j49tjsoulZRIqCwr7daQAN7ruqkQMoAECHU+cdUaMqEWE5B1E2ZYyLqi",
  102. "F75zzHvSnJc5tc6FDdkDWME6jm94jGbtecQ9BOyxfBnQRHodvl+Dd1RowTu9fj1uDIfRtGRlfRWs7yPQ",
  103. "xiDzXPwtxiO2wdgSdY4ECThdB4zTVkpP9s94GzZcurGXuO6dsm7p909o2o7HJ6axRlrC+IFTp5RS/QT7",
  104. "lgyqGnOr303hoCFcIvGR8ZWno3hBMFO5ptvDKSgmwyjvplCKNJylKem7UWGlbBctIw13d2R8nV4Y/K3U",
  105. "FV6jKdPKFz6ttXVpb97wM19o55DmAX7ubFHK/IfxuLkfNa6YwteKrQLQf6hW7mykmC+qFl8WbOtC6SpI",
  106. "+FGznlz1ov5/Rb2adOcWTF2vSp3+cqEa8iubI6vassGq0g59y6pGKX3OaulJ5Xa5REInig06TdbzKKCc",
  107. "eVKWucWQ47nKLZuW2XrHiWoq1IxqZdlKKAXq5tzKx3ahCBvPVjytZwePbvRO7IffyzxUntRnb5268S2p",
  108. "D5aNp3yzO+8HRkWR3ro/TheL9wv8/XA0jeliJebuJmBIYIXEfZKsjkO6+gadbixkcDIaj04ggUZLGXM0",
  109. "XdoKU0GOhblA2U+0a2RRYdmjZyOIkBRT9iKHLPTWMxtiYonFb6vtHo/Hf1fUv6xLtzpFl8D3b9nyXOeL",
  110. "9aita03r5/QH23TBkN3A2fbwLOxLy1iXU94qzM/aco6ihnqqWLS0rPxSoTal+jRU0u8+qQHmWct2OsDX",
  111. "GPfco+bfdzCEOgQyhLplYc+/beJWN4jvpad94GbWzcKCQMZxvqUKMkhXx0P2Q1gwwO+6fnA9+TA53LSP",
  112. "Hfbw4np5w5MTD0T3R6KLc/Jt0/MN637euyt7gc66vwIAAP//o5zNVnEKAAA=",
  113. }
  114. // GetSwagger returns the content of the embedded swagger specification file
  115. // or error if failed to decode
  116. func decodeSpec() ([]byte, error) {
  117. zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
  118. if err != nil {
  119. return nil, fmt.Errorf("error base64 decoding spec: %s", err)
  120. }
  121. zr, err := gzip.NewReader(bytes.NewReader(zipped))
  122. if err != nil {
  123. return nil, fmt.Errorf("error decompressing spec: %s", err)
  124. }
  125. var buf bytes.Buffer
  126. _, err = buf.ReadFrom(zr)
  127. if err != nil {
  128. return nil, fmt.Errorf("error decompressing spec: %s", err)
  129. }
  130. return buf.Bytes(), nil
  131. }
  132. var rawSpec = decodeSpecCached()
  133. // a naive cached of a decoded swagger spec
  134. func decodeSpecCached() func() ([]byte, error) {
  135. data, err := decodeSpec()
  136. return func() ([]byte, error) {
  137. return data, err
  138. }
  139. }
  140. // Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
  141. func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
  142. var res = make(map[string]func() ([]byte, error))
  143. if len(pathToFile) > 0 {
  144. res[pathToFile] = rawSpec
  145. }
  146. return res
  147. }
  148. // GetSwagger returns the Swagger specification corresponding to the generated code
  149. // in this file. The external references of Swagger specification are resolved.
  150. // The logic of resolving external references is tightly connected to "import-mapping" feature.
  151. // Externally referenced files must be embedded in the corresponding golang packages.
  152. // Urls can be supported but this task was out of the scope.
  153. func GetSwagger() (swagger *openapi3.T, err error) {
  154. var resolvePath = PathToRawSpec("")
  155. loader := openapi3.NewLoader()
  156. loader.IsExternalRefsAllowed = true
  157. loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
  158. var pathToFile = url.String()
  159. pathToFile = path.Clean(pathToFile)
  160. getSpec, ok := resolvePath[pathToFile]
  161. if !ok {
  162. err1 := fmt.Errorf("path not found: %s", pathToFile)
  163. return nil, err1
  164. }
  165. return getSpec()
  166. }
  167. var specData []byte
  168. specData, err = rawSpec()
  169. if err != nil {
  170. return
  171. }
  172. swagger, err = loader.LoadFromData(specData)
  173. if err != nil {
  174. return
  175. }
  176. return
  177. }