123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- // Package codegen provides primitives to interact with the openapi HTTP API.
- //
- // Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT.
- package codegen
- import (
- "bytes"
- "compress/gzip"
- "encoding/base64"
- "fmt"
- "net/url"
- "path"
- "strings"
- "github.com/getkin/kin-openapi/openapi3"
- "github.com/labstack/echo/v4"
- )
- const (
- Access_tokenScopes = "access_token.Scopes"
- )
- // BaseResponse defines model for BaseResponse.
- type BaseResponse struct {
- // Message message returned by server side if there is any
- Message *string `json:"message,omitempty"`
- }
- // HealthServices defines model for HealthServices.
- type HealthServices struct {
- NotRunning *[]string `json:"not_running,omitempty"`
- Running *[]string `json:"running,omitempty"`
- }
- // GetHealthServicesOK defines model for GetHealthServicesOK.
- type GetHealthServicesOK struct {
- Data *HealthServices `json:"data,omitempty"`
- // Message message returned by server side if there is any
- Message *string `json:"message,omitempty"`
- }
- // ResponseInternalServerError defines model for ResponseInternalServerError.
- type ResponseInternalServerError = BaseResponse
- // ResponseOK defines model for ResponseOK.
- type ResponseOK = BaseResponse
- // ServerInterface represents all server handlers.
- type ServerInterface interface {
- // Test file methods
- // (GET /file/test)
- GetFileTest(ctx echo.Context) error
- // Get service status
- // (GET /health/services)
- GetHealthServices(ctx echo.Context) error
- }
- // ServerInterfaceWrapper converts echo contexts to parameters.
- type ServerInterfaceWrapper struct {
- Handler ServerInterface
- }
- // GetFileTest converts echo context to params.
- func (w *ServerInterfaceWrapper) GetFileTest(ctx echo.Context) error {
- var err error
- ctx.Set(Access_tokenScopes, []string{""})
- // Invoke the callback with all the unmarshalled arguments
- err = w.Handler.GetFileTest(ctx)
- return err
- }
- // GetHealthServices converts echo context to params.
- func (w *ServerInterfaceWrapper) GetHealthServices(ctx echo.Context) error {
- var err error
- ctx.Set(Access_tokenScopes, []string{""})
- // Invoke the callback with all the unmarshalled arguments
- err = w.Handler.GetHealthServices(ctx)
- return err
- }
- // This is a simple interface which specifies echo.Route addition functions which
- // are present on both echo.Echo and echo.Group, since we want to allow using
- // either of them for path registration
- type EchoRouter interface {
- CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- }
- // RegisterHandlers adds each server route to the EchoRouter.
- func RegisterHandlers(router EchoRouter, si ServerInterface) {
- RegisterHandlersWithBaseURL(router, si, "")
- }
- // Registers handlers, and prepends BaseURL to the paths, so that the paths
- // can be served under a prefix.
- func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) {
- wrapper := ServerInterfaceWrapper{
- Handler: si,
- }
- router.GET(baseURL+"/file/test", wrapper.GetFileTest)
- router.GET(baseURL+"/health/services", wrapper.GetHealthServices)
- }
- // Base64 encoded, gzipped, json marshaled Swagger object
- var swaggerSpec = []string{
- "H4sIAAAAAAAC/7xW70/jRhD9V1bTfoDKxBGoUmXpPnC9wiFUpSpIrUSi3GY9sfewd92ZcSBF/t+rXZtL",
- "SCiC649PiffHe2/e7szsAxhfN96hE4bsAQi58Y4xfpyjfERdSXm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KMkhXx0P2Q1gwwO+6fnA9+TA53LSP",
- "Hfbw4np5w5MTD0T3R6KLc/Jt0/MN637euyt7gc66vwIAAP//o5zNVnEKAAA=",
- }
- // GetSwagger returns the content of the embedded swagger specification file
- // or error if failed to decode
- func decodeSpec() ([]byte, error) {
- zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
- if err != nil {
- return nil, fmt.Errorf("error base64 decoding spec: %s", err)
- }
- zr, err := gzip.NewReader(bytes.NewReader(zipped))
- if err != nil {
- return nil, fmt.Errorf("error decompressing spec: %s", err)
- }
- var buf bytes.Buffer
- _, err = buf.ReadFrom(zr)
- if err != nil {
- return nil, fmt.Errorf("error decompressing spec: %s", err)
- }
- return buf.Bytes(), nil
- }
- var rawSpec = decodeSpecCached()
- // a naive cached of a decoded swagger spec
- func decodeSpecCached() func() ([]byte, error) {
- data, err := decodeSpec()
- return func() ([]byte, error) {
- return data, err
- }
- }
- // Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
- func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
- var res = make(map[string]func() ([]byte, error))
- if len(pathToFile) > 0 {
- res[pathToFile] = rawSpec
- }
- return res
- }
- // GetSwagger returns the Swagger specification corresponding to the generated code
- // in this file. The external references of Swagger specification are resolved.
- // The logic of resolving external references is tightly connected to "import-mapping" feature.
- // Externally referenced files must be embedded in the corresponding golang packages.
- // Urls can be supported but this task was out of the scope.
- func GetSwagger() (swagger *openapi3.T, err error) {
- var resolvePath = PathToRawSpec("")
- loader := openapi3.NewLoader()
- loader.IsExternalRefsAllowed = true
- loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
- var pathToFile = url.String()
- pathToFile = path.Clean(pathToFile)
- getSpec, ok := resolvePath[pathToFile]
- if !ok {
- err1 := fmt.Errorf("path not found: %s", pathToFile)
- return nil, err1
- }
- return getSpec()
- }
- var specData []byte
- specData, err = rawSpec()
- if err != nil {
- return
- }
- swagger, err = loader.LoadFromData(specData)
- if err != nil {
- return
- }
- return
- }
|