// Package api provides primitives to interact with the openapi HTTP API. // // Code generated by github.com/deepmap/oapi-codegen/v2 version v2.1.0 DO NOT EDIT. package api import ( "bytes" "compress/gzip" "encoding/base64" "fmt" "net/http" "net/url" "path" "strings" "github.com/getkin/kin-openapi/openapi3" "github.com/labstack/echo/v4" "github.com/oapi-codegen/runtime" openapi_types "github.com/oapi-codegen/runtime/types" ) // ServerInterface represents all server handlers. type ServerInterface interface { // (GET /admin/file/{quest}) AdminListFiles(ctx echo.Context, quest openapi_types.UUID) error // (POST /admin/file/{quest}/upload) AdminUploadFile(ctx echo.Context, quest openapi_types.UUID) error // (GET /admin/games) AdminListGames(ctx echo.Context) error // (POST /admin/games) AdminEditGame(ctx echo.Context) error // (GET /admin/games/{uid}) AdminGetGame(ctx echo.Context, uid openapi_types.UUID) error // (GET /engine/{uid}) GameEngine(ctx echo.Context, uid openapi_types.UUID) error // (POST /engine/{uid}/code) EnterCode(ctx echo.Context, uid openapi_types.UUID) error // (GET /file/{uid}) GetFile(ctx echo.Context, uid openapi_types.UUID) error // (GET /games) GetGames(ctx echo.Context) error // (GET /user) GetUser(ctx echo.Context) error // (POST /user/login) PostUserLogin(ctx echo.Context) error // (POST /user/logout) PostUserLogout(ctx echo.Context) error // (POST /user/register) PostUserRegister(ctx echo.Context) error } // ServerInterfaceWrapper converts echo contexts to parameters. type ServerInterfaceWrapper struct { Handler ServerInterface } // AdminListFiles converts echo context to params. func (w *ServerInterfaceWrapper) AdminListFiles(ctx echo.Context) error { var err error // ------------- Path parameter "quest" ------------- var quest openapi_types.UUID err = runtime.BindStyledParameterWithOptions("simple", "quest", ctx.Param("quest"), &quest, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter quest: %s", err)) } ctx.Set(CookieAuthScopes, []string{"creator", "admin"}) // Invoke the callback with all the unmarshaled arguments err = w.Handler.AdminListFiles(ctx, quest) return err } // AdminUploadFile converts echo context to params. func (w *ServerInterfaceWrapper) AdminUploadFile(ctx echo.Context) error { var err error // ------------- Path parameter "quest" ------------- var quest openapi_types.UUID err = runtime.BindStyledParameterWithOptions("simple", "quest", ctx.Param("quest"), &quest, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter quest: %s", err)) } ctx.Set(CookieAuthScopes, []string{"creator", "admin"}) // Invoke the callback with all the unmarshaled arguments err = w.Handler.AdminUploadFile(ctx, quest) return err } // AdminListGames converts echo context to params. func (w *ServerInterfaceWrapper) AdminListGames(ctx echo.Context) error { var err error ctx.Set(CookieAuthScopes, []string{}) // Invoke the callback with all the unmarshaled arguments err = w.Handler.AdminListGames(ctx) return err } // AdminEditGame converts echo context to params. func (w *ServerInterfaceWrapper) AdminEditGame(ctx echo.Context) error { var err error ctx.Set(CookieAuthScopes, []string{"creator", "admin"}) // Invoke the callback with all the unmarshaled arguments err = w.Handler.AdminEditGame(ctx) return err } // AdminGetGame converts echo context to params. func (w *ServerInterfaceWrapper) AdminGetGame(ctx echo.Context) error { var err error // ------------- Path parameter "uid" ------------- var uid openapi_types.UUID err = runtime.BindStyledParameterWithOptions("simple", "uid", ctx.Param("uid"), &uid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter uid: %s", err)) } ctx.Set(CookieAuthScopes, []string{"creator", "admin"}) // Invoke the callback with all the unmarshaled arguments err = w.Handler.AdminGetGame(ctx, uid) return err } // GameEngine converts echo context to params. func (w *ServerInterfaceWrapper) GameEngine(ctx echo.Context) error { var err error // ------------- Path parameter "uid" ------------- var uid openapi_types.UUID err = runtime.BindStyledParameterWithOptions("simple", "uid", ctx.Param("uid"), &uid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter uid: %s", err)) } ctx.Set(CookieAuthScopes, []string{}) // Invoke the callback with all the unmarshaled arguments err = w.Handler.GameEngine(ctx, uid) return err } // EnterCode converts echo context to params. func (w *ServerInterfaceWrapper) EnterCode(ctx echo.Context) error { var err error // ------------- Path parameter "uid" ------------- var uid openapi_types.UUID err = runtime.BindStyledParameterWithOptions("simple", "uid", ctx.Param("uid"), &uid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter uid: %s", err)) } ctx.Set(CookieAuthScopes, []string{}) // Invoke the callback with all the unmarshaled arguments err = w.Handler.EnterCode(ctx, uid) return err } // GetFile converts echo context to params. func (w *ServerInterfaceWrapper) GetFile(ctx echo.Context) error { var err error // ------------- Path parameter "uid" ------------- var uid openapi_types.UUID err = runtime.BindStyledParameterWithOptions("simple", "uid", ctx.Param("uid"), &uid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter uid: %s", err)) } ctx.Set(CookieAuthScopes, []string{}) // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetFile(ctx, uid) return err } // GetGames converts echo context to params. func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error { var err error ctx.Set(CookieAuthScopes, []string{}) // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetGames(ctx) return err } // GetUser converts echo context to params. func (w *ServerInterfaceWrapper) GetUser(ctx echo.Context) error { var err error ctx.Set(CookieAuthScopes, []string{}) // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetUser(ctx) return err } // PostUserLogin converts echo context to params. func (w *ServerInterfaceWrapper) PostUserLogin(ctx echo.Context) error { var err error // Invoke the callback with all the unmarshaled arguments err = w.Handler.PostUserLogin(ctx) return err } // PostUserLogout converts echo context to params. func (w *ServerInterfaceWrapper) PostUserLogout(ctx echo.Context) error { var err error ctx.Set(CookieAuthScopes, []string{}) // Invoke the callback with all the unmarshaled arguments err = w.Handler.PostUserLogout(ctx) return err } // PostUserRegister converts echo context to params. func (w *ServerInterfaceWrapper) PostUserRegister(ctx echo.Context) error { var err error // Invoke the callback with all the unmarshaled arguments err = w.Handler.PostUserRegister(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+"/admin/file/:quest", wrapper.AdminListFiles) router.POST(baseURL+"/admin/file/:quest/upload", wrapper.AdminUploadFile) router.GET(baseURL+"/admin/games", wrapper.AdminListGames) router.POST(baseURL+"/admin/games", wrapper.AdminEditGame) router.GET(baseURL+"/admin/games/:uid", wrapper.AdminGetGame) router.GET(baseURL+"/engine/:uid", wrapper.GameEngine) router.POST(baseURL+"/engine/:uid/code", wrapper.EnterCode) router.GET(baseURL+"/file/:uid", wrapper.GetFile) router.GET(baseURL+"/games", wrapper.GetGames) router.GET(baseURL+"/user", wrapper.GetUser) router.POST(baseURL+"/user/login", wrapper.PostUserLogin) router.POST(baseURL+"/user/logout", wrapper.PostUserLogout) router.POST(baseURL+"/user/register", wrapper.PostUserRegister) } // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ "H4sIAAAAAAAC/8xZX2/cNgz/KoO2Rze+/nnyWxdkQbGg2Lp0L8EhUGzmosaWHIlOcwv83QdKts8+y39y", "da99is+mKPLHHylSeWaxynIlQaJh0TPTYHIlDdgfoLXSn6o39CJWEkEiPfI8T0XMUSgZfjFK0jsT30HG", "6SnXKgeNwumJVWKX4zYHFjEhETagWRmwDIzhm/ZHg1rIDSvLgGl4KISGhEVXTsVOfh3U8urmC8TISlqQ", "gIm1yMkmFjHSfytSMBfC4EFeCITMOvCbhlsWsV/DHVihEzMhbfEBIaPtKpu41nw7ZNKGZ/A+yYQ8yKQx", "S0jzWSJwbOfviwXt8K+Ar3OxQG7uF4eBlDoj/JsWeap4sgCti0Ik9PdW6Ywji9yLYILJVmgufwsDenGA", "SOkwQGVQqWlS13JqKqlrb/cUer4fAlpbZ+C27kPoPljPlrJ2xAzf/k0t6O0/y+mAKS02QvL0I8/85hrx", "n7eU7hlqtXeUVUt9Vjd1o2f1ZChj92HSr5nu50pU51D/qKC0NrMrEUm7WrhfiQKGAlM/uu7FdI27JLky", "YI/CiJuOrhulUuCyF5Bast492KO0XV472QAxFK3Lyk6QRea0ayx4SqkhcNtatnOtKc29IPMC75SeD+2u", "fPShjTVwhOQ9HlYZjkynU1VIHPj8AzjinBijR+VQ2/o25kETywpLH3+azPDWyPk0aE4GDw1mxgfhyU+U", "IfT3AKuxsnqCyv4hn4fPhZf5PET9Vitbp6W6v676ViEfeSqS+qdKm0cJT3idwiNQ9hJvrmnfFBC8aXw0", "yJos70EGGRep1wZ4yi/VaaE1SLywLnlzy4p9hKcJGdACZDwwOBBSZoG+dDZX02FbtUo7YSfo6rxU9MSp", "3feGk0Sl/6z3FYdGPKii0AGqNtIXiB7qNYSV+Z6GNGAG4kIL3P5DMNb5ou4FvC/wzoJPLaN7RVS2jjAD", "xrSqVsR4Lv6EagYQ8lZZZx1dmfy7AENMfARtXAv6+mR1srLNUA6S54JF7O3J65MV1T+Od9aM0EJqZ6/w", "+YFUlPR6AzY5iK22Mf6QsIjZYYvmnj9oGLRaNM8Agc68q8oJ0rxz4aEyahcA1AUErf56qn1dB91R+s1q", "NUTSRi7sT6vtKFhj2/hf9SlWrmmFB53QTT02m5UZQumzFSKcjgmTVfO7SrZ7E05WpChyrjEkNa8Sjp4h", "jJzs7HQjJNdb70ThGbleHqS98fGbItRUsXHinteZ+mJjeyO/dXqEAXSin7sKMxyYZa4oykMd6t6efHsA", "wudCJBP14xxqWKbTwlH9yLVjMWBAboSECUwIizMr+PMi0rlccnzrOBfWdwL+dDiTCPrUNWlH8vCwfJt1", "0eG7TvVdQpVLIe0On3ESAc4+ar4TgwZAVjECvjKogWddsKePmd6Vmj2hKlTGC35VZJYr9bSl7UZHdvzs", "utUDDsL23WQZsHert9OLuv9SaJkYpmoj5HA6/qWMNfXCii2VLcOzTM6N+ap0Mp1LdSferFgsr/oIr16O", "cOcQWHfwVgXOApzkeva/610QMlPEMRjzS6X6UIt3NmrYCIOOv+NWfqolfygzdh/feL/OH/c8k16zb3uX", "n5trox3ImoqyAf1Yl/1CpyxiIY185br8PwAA//96RTU+mhwAAA==", } // 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: %w", err) } zr, err := gzip.NewReader(bytes.NewReader(zipped)) if err != nil { return nil, fmt.Errorf("error decompressing spec: %w", err) } var buf bytes.Buffer _, err = buf.ReadFrom(zr) if err != nil { return nil, fmt.Errorf("error decompressing spec: %w", 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) { 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) { resolvePath := PathToRawSpec("") loader := openapi3.NewLoader() loader.IsExternalRefsAllowed = true loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) { 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 }