391 lines
13 KiB
Go
391 lines
13 KiB
Go
// Package api provides primitives to interact with the openapi HTTP API.
|
|
//
|
|
// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.0.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"
|
|
)
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
|
|
// (GET /games)
|
|
GetGames(ctx echo.Context) error
|
|
|
|
// (GET /teams)
|
|
GetTeams(ctx echo.Context) error
|
|
|
|
// (POST /teams)
|
|
PostTeams(ctx echo.Context) error
|
|
|
|
// (DELETE /teams/{teamID})
|
|
DeleteTeamsTeamID(ctx echo.Context, teamID int) error
|
|
|
|
// (GET /teams/{teamID})
|
|
GetTeamsTeamID(ctx echo.Context, teamID int) error
|
|
|
|
// (DELETE /teams/{teamID}/members)
|
|
DeleteTeamsTeamIDMembers(ctx echo.Context, teamID int) error
|
|
|
|
// (POST /teams/{teamID}/members)
|
|
PostTeamsTeamIDMembers(ctx echo.Context, teamID int) error
|
|
|
|
// (POST /teams/{teamID}/requests)
|
|
PostTeamsTeamIDRequests(ctx echo.Context, teamID int) error
|
|
|
|
// (POST /teams/{teamID}/requests/{userID})
|
|
PostTeamsTeamIDRequestsUserID(ctx echo.Context, teamID int, userID int) 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
|
|
}
|
|
|
|
// GetGames converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetGames(ctx)
|
|
return err
|
|
}
|
|
|
|
// GetTeams converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetTeams(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetTeams(ctx)
|
|
return err
|
|
}
|
|
|
|
// PostTeams converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) PostTeams(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.PostTeams(ctx)
|
|
return err
|
|
}
|
|
|
|
// DeleteTeamsTeamID converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) DeleteTeamsTeamID(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "teamID" -------------
|
|
var teamID int
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "teamID", runtime.ParamLocationPath, ctx.Param("teamID"), &teamID)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter teamID: %s", err))
|
|
}
|
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.DeleteTeamsTeamID(ctx, teamID)
|
|
return err
|
|
}
|
|
|
|
// GetTeamsTeamID converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetTeamsTeamID(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "teamID" -------------
|
|
var teamID int
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "teamID", runtime.ParamLocationPath, ctx.Param("teamID"), &teamID)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter teamID: %s", err))
|
|
}
|
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetTeamsTeamID(ctx, teamID)
|
|
return err
|
|
}
|
|
|
|
// DeleteTeamsTeamIDMembers converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) DeleteTeamsTeamIDMembers(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "teamID" -------------
|
|
var teamID int
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "teamID", runtime.ParamLocationPath, ctx.Param("teamID"), &teamID)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter teamID: %s", err))
|
|
}
|
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.DeleteTeamsTeamIDMembers(ctx, teamID)
|
|
return err
|
|
}
|
|
|
|
// PostTeamsTeamIDMembers converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) PostTeamsTeamIDMembers(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "teamID" -------------
|
|
var teamID int
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "teamID", runtime.ParamLocationPath, ctx.Param("teamID"), &teamID)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter teamID: %s", err))
|
|
}
|
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.PostTeamsTeamIDMembers(ctx, teamID)
|
|
return err
|
|
}
|
|
|
|
// PostTeamsTeamIDRequests converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) PostTeamsTeamIDRequests(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "teamID" -------------
|
|
var teamID int
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "teamID", runtime.ParamLocationPath, ctx.Param("teamID"), &teamID)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter teamID: %s", err))
|
|
}
|
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.PostTeamsTeamIDRequests(ctx, teamID)
|
|
return err
|
|
}
|
|
|
|
// PostTeamsTeamIDRequestsUserID converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) PostTeamsTeamIDRequestsUserID(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "teamID" -------------
|
|
var teamID int
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "teamID", runtime.ParamLocationPath, ctx.Param("teamID"), &teamID)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter teamID: %s", err))
|
|
}
|
|
|
|
// ------------- Path parameter "userID" -------------
|
|
var userID int
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "userID", runtime.ParamLocationPath, ctx.Param("userID"), &userID)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter userID: %s", err))
|
|
}
|
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.PostTeamsTeamIDRequestsUserID(ctx, teamID, userID)
|
|
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
|
|
|
|
// 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+"/games", wrapper.GetGames)
|
|
router.GET(baseURL+"/teams", wrapper.GetTeams)
|
|
router.POST(baseURL+"/teams", wrapper.PostTeams)
|
|
router.DELETE(baseURL+"/teams/:teamID", wrapper.DeleteTeamsTeamID)
|
|
router.GET(baseURL+"/teams/:teamID", wrapper.GetTeamsTeamID)
|
|
router.DELETE(baseURL+"/teams/:teamID/members", wrapper.DeleteTeamsTeamIDMembers)
|
|
router.POST(baseURL+"/teams/:teamID/members", wrapper.PostTeamsTeamIDMembers)
|
|
router.POST(baseURL+"/teams/:teamID/requests", wrapper.PostTeamsTeamIDRequests)
|
|
router.POST(baseURL+"/teams/:teamID/requests/:userID", wrapper.PostTeamsTeamIDRequestsUserID)
|
|
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/+RZwW7cNhD9lYLtUbA2iU+6pQgQBE2A1nVyMfZAS+M10xXJkiMHhqF/L4YitZJFran1",
|
|
"ZmM0p8jkkHzz+OaR3DywUtVaSZBoWfHADPzbgMXfVSXANWzVRkj6KJVEkEifXOutKDkKJfOvVrluW95C",
|
|
"zelLG6XBoB8PNRdb+sB7DaxgFo2QG9ZmTHNrvylTRTrbzAERBipWXPk5BiPWWRihrr9CiawdD0HTgGvY",
|
|
"CItgTg1/1/k62ttYMJLX8HTmfWQ2JWG4ShIhrsVqJa3PzRhlLnzLMzgqVTVMRUiEDRh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zUx0Y8/O+D/ZgvQuQB+9Wv8nK2bNwwfhVercl3LJi74IuN2bKC5fSUa9ftfwEAAP//8qqL",
|
|
"tlEaAAA=",
|
|
}
|
|
|
|
// 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
|
|
}
|