// Package api provides primitives to interact with the openapi HTTP API. // // Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.4.1 DO NOT EDIT. package api import ( "bytes" "compress/gzip" "context" "encoding/base64" "encoding/json" "fmt" "net/http" "net/url" "path" "strings" "github.com/getkin/kin-openapi/openapi3" "github.com/labstack/echo/v4" "github.com/oapi-codegen/nullable" "github.com/oapi-codegen/runtime" strictecho "github.com/oapi-codegen/runtime/strictmiddleware/echo" ) // Defines values for ExecutionStatus. const ( InternalError ExecutionStatus = "internal_error" None ExecutionStatus = "none" Running ExecutionStatus = "running" RuntimeError ExecutionStatus = "runtime_error" Success ExecutionStatus = "success" Timeout ExecutionStatus = "timeout" WrongAnswer ExecutionStatus = "wrong_answer" ) // Defines values for GameGameType. const ( Multiplayer GameGameType = "multiplayer" N1V1 GameGameType = "1v1" ) // Error defines model for Error. type Error struct { Message string `json:"message"` } // ExecutionStatus defines model for ExecutionStatus. type ExecutionStatus string // Game defines model for Game. type Game struct { DisplayName string `json:"display_name"` DurationSeconds int `json:"duration_seconds"` GameID int `json:"game_id"` GameType GameGameType `json:"game_type"` IsPublic bool `json:"is_public"` MainPlayers []User `json:"main_players"` Problem Problem `json:"problem"` StartedAt *int64 `json:"started_at,omitempty"` } // GameGameType defines model for Game.GameType. type GameGameType string // LatestGameState defines model for LatestGameState. type LatestGameState struct { Code string `json:"code"` Score nullable.Nullable[int] `json:"score"` Status ExecutionStatus `json:"status"` } // Problem defines model for Problem. type Problem struct { Description string `json:"description"` ProblemID int `json:"problem_id"` SampleCode string `json:"sample_code"` Title string `json:"title"` } // RankingEntry defines model for RankingEntry. type RankingEntry struct { Player User `json:"player"` Score int `json:"score"` } // User defines model for User. type User struct { DisplayName string `json:"display_name"` IconPath *string `json:"icon_path,omitempty"` IsAdmin bool `json:"is_admin"` Label nullable.Nullable[string] `json:"label"` UserID int `json:"user_id"` Username string `json:"username"` } // HeaderAuthorization defines model for header_authorization. type HeaderAuthorization = string // PathGameID defines model for path_game_id. type PathGameID = int // BadRequest defines model for BadRequest. type BadRequest = Error // Forbidden defines model for Forbidden. type Forbidden = Error // NotFound defines model for NotFound. type NotFound = Error // Unauthorized defines model for Unauthorized. type Unauthorized = Error // GetGamesParams defines parameters for GetGames. type GetGamesParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // GetGameParams defines parameters for GetGame. type GetGameParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // PostGamePlayCodeJSONBody defines parameters for PostGamePlayCode. type PostGamePlayCodeJSONBody struct { Code string `json:"code"` } // PostGamePlayCodeParams defines parameters for PostGamePlayCode. type PostGamePlayCodeParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // GetGamePlayLatestStateParams defines parameters for GetGamePlayLatestState. type GetGamePlayLatestStateParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // PostGamePlaySubmitJSONBody defines parameters for PostGamePlaySubmit. type PostGamePlaySubmitJSONBody struct { Code string `json:"code"` } // PostGamePlaySubmitParams defines parameters for PostGamePlaySubmit. type PostGamePlaySubmitParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // GetGameWatchLatestStatesParams defines parameters for GetGameWatchLatestStates. type GetGameWatchLatestStatesParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // GetGameWatchRankingParams defines parameters for GetGameWatchRanking. type GetGameWatchRankingParams struct { Authorization HeaderAuthorization `json:"Authorization"` } // PostLoginJSONBody defines parameters for PostLogin. type PostLoginJSONBody struct { Password string `json:"password"` Username string `json:"username"` } // PostGamePlayCodeJSONRequestBody defines body for PostGamePlayCode for application/json ContentType. type PostGamePlayCodeJSONRequestBody PostGamePlayCodeJSONBody // PostGamePlaySubmitJSONRequestBody defines body for PostGamePlaySubmit for application/json ContentType. type PostGamePlaySubmitJSONRequestBody PostGamePlaySubmitJSONBody // PostLoginJSONRequestBody defines body for PostLogin for application/json ContentType. type PostLoginJSONRequestBody PostLoginJSONBody // ServerInterface represents all server handlers. type ServerInterface interface { // List games // (GET /games) GetGames(ctx echo.Context, params GetGamesParams) error // Get a game // (GET /games/{game_id}) GetGame(ctx echo.Context, gameID PathGameID, params GetGameParams) error // Post the latest code // (POST /games/{game_id}/play/code) PostGamePlayCode(ctx echo.Context, gameID PathGameID, params PostGamePlayCodeParams) error // Get the latest execution result for player // (GET /games/{game_id}/play/latest_state) GetGamePlayLatestState(ctx echo.Context, gameID PathGameID, params GetGamePlayLatestStateParams) error // Submit the answer // (POST /games/{game_id}/play/submit) PostGamePlaySubmit(ctx echo.Context, gameID PathGameID, params PostGamePlaySubmitParams) error // Get all the latest game states of the main players // (GET /games/{game_id}/watch/latest_states) GetGameWatchLatestStates(ctx echo.Context, gameID PathGameID, params GetGameWatchLatestStatesParams) error // Get the latest player ranking // (GET /games/{game_id}/watch/ranking) GetGameWatchRanking(ctx echo.Context, gameID PathGameID, params GetGameWatchRankingParams) error // User login // (POST /login) PostLogin(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 // Parameter object where we will unmarshal all parameters from the context var params GetGamesParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetGames(ctx, params) return err } // GetGame converts echo context to params. func (w *ServerInterfaceWrapper) GetGame(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params GetGameParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetGame(ctx, gameID, params) return err } // PostGamePlayCode converts echo context to params. func (w *ServerInterfaceWrapper) PostGamePlayCode(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params PostGamePlayCodeParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.PostGamePlayCode(ctx, gameID, params) return err } // GetGamePlayLatestState converts echo context to params. func (w *ServerInterfaceWrapper) GetGamePlayLatestState(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params GetGamePlayLatestStateParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetGamePlayLatestState(ctx, gameID, params) return err } // PostGamePlaySubmit converts echo context to params. func (w *ServerInterfaceWrapper) PostGamePlaySubmit(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params PostGamePlaySubmitParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.PostGamePlaySubmit(ctx, gameID, params) return err } // GetGameWatchLatestStates converts echo context to params. func (w *ServerInterfaceWrapper) GetGameWatchLatestStates(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params GetGameWatchLatestStatesParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetGameWatchLatestStates(ctx, gameID, params) return err } // GetGameWatchRanking converts echo context to params. func (w *ServerInterfaceWrapper) GetGameWatchRanking(ctx echo.Context) error { var err error // ------------- Path parameter "game_id" ------------- var gameID PathGameID err = runtime.BindStyledParameterWithOptions("simple", "game_id", ctx.Param("game_id"), &gameID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter game_id: %s", err)) } // Parameter object where we will unmarshal all parameters from the context var params GetGameWatchRankingParams headers := ctx.Request().Header // ------------- Required header parameter "Authorization" ------------- if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { var Authorization HeaderAuthorization n := len(valueList) if n != 1 { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) } err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) if err != nil { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) } params.Authorization = Authorization } else { return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) } // Invoke the callback with all the unmarshaled arguments err = w.Handler.GetGameWatchRanking(ctx, gameID, params) return err } // PostLogin converts echo context to params. func (w *ServerInterfaceWrapper) PostLogin(ctx echo.Context) error { var err error // Invoke the callback with all the unmarshaled arguments err = w.Handler.PostLogin(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+"/games/:game_id", wrapper.GetGame) router.POST(baseURL+"/games/:game_id/play/code", wrapper.PostGamePlayCode) router.GET(baseURL+"/games/:game_id/play/latest_state", wrapper.GetGamePlayLatestState) router.POST(baseURL+"/games/:game_id/play/submit", wrapper.PostGamePlaySubmit) router.GET(baseURL+"/games/:game_id/watch/latest_states", wrapper.GetGameWatchLatestStates) router.GET(baseURL+"/games/:game_id/watch/ranking", wrapper.GetGameWatchRanking) router.POST(baseURL+"/login", wrapper.PostLogin) } type BadRequestJSONResponse Error type ForbiddenJSONResponse Error type NotFoundJSONResponse Error type UnauthorizedJSONResponse Error type GetGamesRequestObject struct { Params GetGamesParams } type GetGamesResponseObject interface { VisitGetGamesResponse(w http.ResponseWriter) error } type GetGames200JSONResponse struct { Games []Game `json:"games"` } func (response GetGames200JSONResponse) VisitGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type GetGames401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGames401JSONResponse) VisitGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type GetGames403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGames403JSONResponse) VisitGetGamesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type GetGameRequestObject struct { GameID PathGameID `json:"game_id"` Params GetGameParams } type GetGameResponseObject interface { VisitGetGameResponse(w http.ResponseWriter) error } type GetGame200JSONResponse struct { Game Game `json:"game"` } func (response GetGame200JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type GetGame401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGame401JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type GetGame403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGame403JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type GetGame404JSONResponse struct{ NotFoundJSONResponse } func (response GetGame404JSONResponse) VisitGetGameResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type PostGamePlayCodeRequestObject struct { GameID PathGameID `json:"game_id"` Params PostGamePlayCodeParams Body *PostGamePlayCodeJSONRequestBody } type PostGamePlayCodeResponseObject interface { VisitPostGamePlayCodeResponse(w http.ResponseWriter) error } type PostGamePlayCode200Response struct { } func (response PostGamePlayCode200Response) VisitPostGamePlayCodeResponse(w http.ResponseWriter) error { w.WriteHeader(200) return nil } type PostGamePlayCode401JSONResponse struct{ UnauthorizedJSONResponse } func (response PostGamePlayCode401JSONResponse) VisitPostGamePlayCodeResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type PostGamePlayCode403JSONResponse struct{ ForbiddenJSONResponse } func (response PostGamePlayCode403JSONResponse) VisitPostGamePlayCodeResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type PostGamePlayCode404JSONResponse struct{ NotFoundJSONResponse } func (response PostGamePlayCode404JSONResponse) VisitPostGamePlayCodeResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type GetGamePlayLatestStateRequestObject struct { GameID PathGameID `json:"game_id"` Params GetGamePlayLatestStateParams } type GetGamePlayLatestStateResponseObject interface { VisitGetGamePlayLatestStateResponse(w http.ResponseWriter) error } type GetGamePlayLatestState200JSONResponse struct { State LatestGameState `json:"state"` } func (response GetGamePlayLatestState200JSONResponse) VisitGetGamePlayLatestStateResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type GetGamePlayLatestState401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGamePlayLatestState401JSONResponse) VisitGetGamePlayLatestStateResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type GetGamePlayLatestState403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGamePlayLatestState403JSONResponse) VisitGetGamePlayLatestStateResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type GetGamePlayLatestState404JSONResponse struct{ NotFoundJSONResponse } func (response GetGamePlayLatestState404JSONResponse) VisitGetGamePlayLatestStateResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type PostGamePlaySubmitRequestObject struct { GameID PathGameID `json:"game_id"` Params PostGamePlaySubmitParams Body *PostGamePlaySubmitJSONRequestBody } type PostGamePlaySubmitResponseObject interface { VisitPostGamePlaySubmitResponse(w http.ResponseWriter) error } type PostGamePlaySubmit200Response struct { } func (response PostGamePlaySubmit200Response) VisitPostGamePlaySubmitResponse(w http.ResponseWriter) error { w.WriteHeader(200) return nil } type PostGamePlaySubmit401JSONResponse struct{ UnauthorizedJSONResponse } func (response PostGamePlaySubmit401JSONResponse) VisitPostGamePlaySubmitResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type PostGamePlaySubmit403JSONResponse struct{ ForbiddenJSONResponse } func (response PostGamePlaySubmit403JSONResponse) VisitPostGamePlaySubmitResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type PostGamePlaySubmit404JSONResponse struct{ NotFoundJSONResponse } func (response PostGamePlaySubmit404JSONResponse) VisitPostGamePlaySubmitResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type GetGameWatchLatestStatesRequestObject struct { GameID PathGameID `json:"game_id"` Params GetGameWatchLatestStatesParams } type GetGameWatchLatestStatesResponseObject interface { VisitGetGameWatchLatestStatesResponse(w http.ResponseWriter) error } type GetGameWatchLatestStates200JSONResponse struct { States map[string]LatestGameState `json:"states"` } func (response GetGameWatchLatestStates200JSONResponse) VisitGetGameWatchLatestStatesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type GetGameWatchLatestStates401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGameWatchLatestStates401JSONResponse) VisitGetGameWatchLatestStatesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type GetGameWatchLatestStates403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGameWatchLatestStates403JSONResponse) VisitGetGameWatchLatestStatesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type GetGameWatchLatestStates404JSONResponse struct{ NotFoundJSONResponse } func (response GetGameWatchLatestStates404JSONResponse) VisitGetGameWatchLatestStatesResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type GetGameWatchRankingRequestObject struct { GameID PathGameID `json:"game_id"` Params GetGameWatchRankingParams } type GetGameWatchRankingResponseObject interface { VisitGetGameWatchRankingResponse(w http.ResponseWriter) error } type GetGameWatchRanking200JSONResponse struct { Ranking []RankingEntry `json:"ranking"` } func (response GetGameWatchRanking200JSONResponse) VisitGetGameWatchRankingResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type GetGameWatchRanking401JSONResponse struct{ UnauthorizedJSONResponse } func (response GetGameWatchRanking401JSONResponse) VisitGetGameWatchRankingResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } type GetGameWatchRanking403JSONResponse struct{ ForbiddenJSONResponse } func (response GetGameWatchRanking403JSONResponse) VisitGetGameWatchRankingResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(403) return json.NewEncoder(w).Encode(response) } type GetGameWatchRanking404JSONResponse struct{ NotFoundJSONResponse } func (response GetGameWatchRanking404JSONResponse) VisitGetGameWatchRankingResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(404) return json.NewEncoder(w).Encode(response) } type PostLoginRequestObject struct { Body *PostLoginJSONRequestBody } type PostLoginResponseObject interface { VisitPostLoginResponse(w http.ResponseWriter) error } type PostLogin200JSONResponse struct { Token string `json:"token"` } func (response PostLogin200JSONResponse) VisitPostLoginResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) return json.NewEncoder(w).Encode(response) } type PostLogin401JSONResponse struct{ UnauthorizedJSONResponse } func (response PostLogin401JSONResponse) VisitPostLoginResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(401) return json.NewEncoder(w).Encode(response) } // StrictServerInterface represents all server handlers. type StrictServerInterface interface { // List games // (GET /games) GetGames(ctx context.Context, request GetGamesRequestObject) (GetGamesResponseObject, error) // Get a game // (GET /games/{game_id}) GetGame(ctx context.Context, request GetGameRequestObject) (GetGameResponseObject, error) // Post the latest code // (POST /games/{game_id}/play/code) PostGamePlayCode(ctx context.Context, request PostGamePlayCodeRequestObject) (PostGamePlayCodeResponseObject, error) // Get the latest execution result for player // (GET /games/{game_id}/play/latest_state) GetGamePlayLatestState(ctx context.Context, request GetGamePlayLatestStateRequestObject) (GetGamePlayLatestStateResponseObject, error) // Submit the answer // (POST /games/{game_id}/play/submit) PostGamePlaySubmit(ctx context.Context, request PostGamePlaySubmitRequestObject) (PostGamePlaySubmitResponseObject, error) // Get all the latest game states of the main players // (GET /games/{game_id}/watch/latest_states) GetGameWatchLatestStates(ctx context.Context, request GetGameWatchLatestStatesRequestObject) (GetGameWatchLatestStatesResponseObject, error) // Get the latest player ranking // (GET /games/{game_id}/watch/ranking) GetGameWatchRanking(ctx context.Context, request GetGameWatchRankingRequestObject) (GetGameWatchRankingResponseObject, error) // User login // (POST /login) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) } type StrictHandlerFunc = strictecho.StrictEchoHandlerFunc type StrictMiddlewareFunc = strictecho.StrictEchoMiddlewareFunc func NewStrictHandler(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc) ServerInterface { return &strictHandler{ssi: ssi, middlewares: middlewares} } type strictHandler struct { ssi StrictServerInterface middlewares []StrictMiddlewareFunc } // GetGames operation middleware func (sh *strictHandler) GetGames(ctx echo.Context, params GetGamesParams) error { var request GetGamesRequestObject request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.GetGames(ctx.Request().Context(), request.(GetGamesRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "GetGames") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(GetGamesResponseObject); ok { return validResponse.VisitGetGamesResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // GetGame operation middleware func (sh *strictHandler) GetGame(ctx echo.Context, gameID PathGameID, params GetGameParams) error { var request GetGameRequestObject request.GameID = gameID request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.GetGame(ctx.Request().Context(), request.(GetGameRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "GetGame") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(GetGameResponseObject); ok { return validResponse.VisitGetGameResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // PostGamePlayCode operation middleware func (sh *strictHandler) PostGamePlayCode(ctx echo.Context, gameID PathGameID, params PostGamePlayCodeParams) error { var request PostGamePlayCodeRequestObject request.GameID = gameID request.Params = params var body PostGamePlayCodeJSONRequestBody if err := ctx.Bind(&body); err != nil { return err } request.Body = &body handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.PostGamePlayCode(ctx.Request().Context(), request.(PostGamePlayCodeRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "PostGamePlayCode") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(PostGamePlayCodeResponseObject); ok { return validResponse.VisitPostGamePlayCodeResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // GetGamePlayLatestState operation middleware func (sh *strictHandler) GetGamePlayLatestState(ctx echo.Context, gameID PathGameID, params GetGamePlayLatestStateParams) error { var request GetGamePlayLatestStateRequestObject request.GameID = gameID request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.GetGamePlayLatestState(ctx.Request().Context(), request.(GetGamePlayLatestStateRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "GetGamePlayLatestState") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(GetGamePlayLatestStateResponseObject); ok { return validResponse.VisitGetGamePlayLatestStateResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // PostGamePlaySubmit operation middleware func (sh *strictHandler) PostGamePlaySubmit(ctx echo.Context, gameID PathGameID, params PostGamePlaySubmitParams) error { var request PostGamePlaySubmitRequestObject request.GameID = gameID request.Params = params var body PostGamePlaySubmitJSONRequestBody if err := ctx.Bind(&body); err != nil { return err } request.Body = &body handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.PostGamePlaySubmit(ctx.Request().Context(), request.(PostGamePlaySubmitRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "PostGamePlaySubmit") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(PostGamePlaySubmitResponseObject); ok { return validResponse.VisitPostGamePlaySubmitResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // GetGameWatchLatestStates operation middleware func (sh *strictHandler) GetGameWatchLatestStates(ctx echo.Context, gameID PathGameID, params GetGameWatchLatestStatesParams) error { var request GetGameWatchLatestStatesRequestObject request.GameID = gameID request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.GetGameWatchLatestStates(ctx.Request().Context(), request.(GetGameWatchLatestStatesRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "GetGameWatchLatestStates") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(GetGameWatchLatestStatesResponseObject); ok { return validResponse.VisitGetGameWatchLatestStatesResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // GetGameWatchRanking operation middleware func (sh *strictHandler) GetGameWatchRanking(ctx echo.Context, gameID PathGameID, params GetGameWatchRankingParams) error { var request GetGameWatchRankingRequestObject request.GameID = gameID request.Params = params handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.GetGameWatchRanking(ctx.Request().Context(), request.(GetGameWatchRankingRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "GetGameWatchRanking") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(GetGameWatchRankingResponseObject); ok { return validResponse.VisitGetGameWatchRankingResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // PostLogin operation middleware func (sh *strictHandler) PostLogin(ctx echo.Context) error { var request PostLoginRequestObject var body PostLoginJSONRequestBody if err := ctx.Bind(&body); err != nil { return err } request.Body = &body handler := func(ctx echo.Context, request interface{}) (interface{}, error) { return sh.ssi.PostLogin(ctx.Request().Context(), request.(PostLoginRequestObject)) } for _, middleware := range sh.middlewares { handler = middleware(handler, "PostLogin") } response, err := handler(ctx, request) if err != nil { return err } else if validResponse, ok := response.(PostLoginResponseObject); ok { return validResponse.VisitPostLoginResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } return nil } // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ "H4sIAAAAAAAC/+xYXW/bNhf+KwTfF+iNGttNEHTZVbq1RYeiMNoVw1AUAi0d20wpUiWpOl6h/z4cUl+U", "5FpJm24plovAInm+Hz485GeaqCxXEqQ19OIzzZlmGVjQ7msLLAUds8JuleZ/McuVxHEu6UU1SSMqWQb0", "gl4GqyKq4WPBNaT0wuoCImqSLWQMxe0+RwFjNZcbWpYRzZndxhuWQczTxgAOturr2QmKubSwAU1LVK3B", "5EoacAE9Yelr+FiAsfiVKGlBup8szwVPnOuzK+OjbPX+X8OaXtD/zdpkzfysmT3VWlWmUjCJ5rnPEtoi", "ujJWRvSZ0iuepiDv3nJrqozoK2WfqUKmd2/2lbJk7UyVEX0ra9TAdzAdWMPpSgIVeiHEtlY5aMs9FDIw", "hm0Af8I1y3KByHkhPzHB27pFI1ht4feuUfK+WahWV5C4gj+9hqRA/95YZgtnE2SRoZhUEhDIhZSoNaKm", "SBIwhkZ0p5XcxEyandtblmegCusX40cMLpzIgVxLJqqB91EnjFZdz/2IPne7qZ+MlJtcsH0sq9lWFa4n", "izFNaaFdDWMDiZKpCeROz+fRYDtGtLPFm6WLgwv9cJu2xSd0JCuE5egt9KL20wM/uYnzYiV4Elj11FEt", "XiklgLntkjEuY6/dRcQtZOYYLt8a73WljmnN9vida7USkB0TX1bLELeWaQtpzGzg7U9n5+ePzx7Ph0mN", "6PXDjXrYjp6fDVDaUmeb1m5eorD+I6VtQ+llaAz4L5kFYxE4iPwRtCUq7aEMkq0iD7YghCI7pUX64Oex", "UppE6VBygSmRhRBsNahqB06m2YJfpJfeju3n0flde9EoHUvBsi18b6N1aaubgd+33BBuCCNtpgfxV1OT", "dpBxk/Gtc225FT3JKqoxOuhlquNorSmk7NC/sRS+ZvIDl5un0ur9MI/V/p+4Lw/gZtAu9ILwNmrxMSed", "gRuw6W9qK8mvCkZ5KlEydj1PIDLjGduAmV2prTy5yjcHKI6lGQ8htWbCjFKcYCsQoRFj2XpND+6k1lJh", "QA/g9+h0DIC4dJgBDOMofGorHSUDjmpirgMa1gfVcrlWrjX0cKaXYsWsVsaQ+gAlO1iRy+ULGtFPoI1v", "KOYni5M5RqFykCzn9IKensxP5tT3qq7MM2RT92sDjq4RA443X6R4coLjQEeena763Thk2yWz0a67fN9r", "ZR/N5zfqq0KINq5POt9c0zA430ZOGXOgCmG39pIbS9SaeIkyomfzxSEXmphnYY+HQqfHhTqtMPJAkWUM", "6cS7UNkvo6qUs8/VSVkeK+o3qml0VC64GN0BBqZVfqTSkwp96VL83SqMEmfHJZobUQiJ52AJqxwegcQM", "yWdWH6e5MiPoWCrf9ywF2//im4V/DCbuAvNEpfuvQMgtm4extmkcLuFVvhyHd4ipN/5usy6E2JMiT5mt", "wfKvRxjCg9gtEOE6ZOIScxhrflVs6ib6S4SEiPN9t++5fwR+agL/EkH1Lxt98HklU8jqT1XoujIYEfGi", "94e8OsiC+iZDNJhCWLJWmlT97GHAmWKVcTuN3t74tf8R3N0SnC/J/aE4DwsHxeoNaxRuO2aTbUBwR/vo", "P1CkQ3Hmx+E494ulKUcRJpbBihuR3xCDI2w4rUm/FKLLKC0jGmzdcSZjXJL6Iege9Xg3DOwwfrV/opiE", "3Oo544cAbSfuSdfH4Cnn2DWyVj4Fo0tXI1KL3MujOu/FgHATauMfcw6fwy/dkm91DubMmJ3S4btOM7p4", "dEoPvAV9xQOPrO/RlemvOEBvGbVVH6D3DHuNfyed/0dD8UqmoDU42BGBIC26euvDPYDVWwOaeOCUZVn+", "HQAA//+TXFqx2R0AAA==", } // 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 }