2023-11-01 23:21:12 +03:00
|
|
|
// Package api provides primitives to interact with the openapi HTTP API.
|
|
|
|
//
|
2024-04-29 23:01:24 +03:00
|
|
|
// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.1.0 DO NOT EDIT.
|
2023-11-01 23:21:12 +03:00
|
|
|
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"
|
2024-01-06 08:44:26 +03:00
|
|
|
openapi_types "github.com/oapi-codegen/runtime/types"
|
2023-11-01 23:21:12 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// ServerInterface represents all server handlers.
|
|
|
|
type ServerInterface interface {
|
|
|
|
|
2024-04-29 23:01:24 +03:00
|
|
|
// (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
|
2024-01-28 22:19:41 +03:00
|
|
|
|
2024-01-25 01:45:09 +03:00
|
|
|
// (GET /admin/games)
|
2024-01-28 22:19:41 +03:00
|
|
|
AdminListGames(ctx echo.Context) error
|
2024-01-25 01:45:09 +03:00
|
|
|
|
|
|
|
// (POST /admin/games)
|
2024-01-28 22:19:41 +03:00
|
|
|
AdminEditGame(ctx echo.Context) error
|
2024-01-25 01:45:09 +03:00
|
|
|
|
|
|
|
// (GET /admin/games/{uid})
|
2024-01-28 22:19:41 +03:00
|
|
|
AdminGetGame(ctx echo.Context, uid openapi_types.UUID) error
|
2024-01-25 01:45:09 +03:00
|
|
|
|
2024-01-05 03:50:33 +03:00
|
|
|
// (GET /engine/{uid})
|
2024-01-06 08:44:26 +03:00
|
|
|
GameEngine(ctx echo.Context, uid openapi_types.UUID) error
|
2024-01-05 03:50:33 +03:00
|
|
|
|
|
|
|
// (POST /engine/{uid}/code)
|
2024-01-06 08:44:26 +03:00
|
|
|
EnterCode(ctx echo.Context, uid openapi_types.UUID) error
|
2023-11-19 22:54:54 +03:00
|
|
|
|
2024-05-05 22:26:52 +03:00
|
|
|
// (GET /file/{uid})
|
|
|
|
GetFile(ctx echo.Context, uid openapi_types.UUID) error
|
|
|
|
|
2023-11-02 01:21:13 +03:00
|
|
|
// (GET /games)
|
|
|
|
GetGames(ctx echo.Context) error
|
|
|
|
|
2023-11-01 23:21:12 +03:00
|
|
|
// (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
|
2024-05-09 15:58:19 +03:00
|
|
|
|
|
|
|
// (GET /users)
|
|
|
|
GetUsers(ctx echo.Context) error
|
|
|
|
|
|
|
|
// (GET /users/{uid})
|
|
|
|
GetUserInfo(ctx echo.Context, uid openapi_types.UUID) error
|
2023-11-01 23:21:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ServerInterfaceWrapper converts echo contexts to parameters.
|
|
|
|
type ServerInterfaceWrapper struct {
|
|
|
|
Handler ServerInterface
|
|
|
|
}
|
|
|
|
|
2024-04-29 23:01:24 +03:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2024-01-28 22:19:41 +03:00
|
|
|
// AdminUploadFile converts echo context to params.
|
|
|
|
func (w *ServerInterfaceWrapper) AdminUploadFile(ctx echo.Context) error {
|
2024-01-25 01:45:09 +03:00
|
|
|
var err error
|
2024-04-29 23:01:24 +03:00
|
|
|
// ------------- 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))
|
|
|
|
}
|
2024-01-25 01:45:09 +03:00
|
|
|
|
2024-01-28 22:19:41 +03:00
|
|
|
ctx.Set(CookieAuthScopes, []string{"creator", "admin"})
|
2024-01-25 01:45:09 +03:00
|
|
|
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
2024-04-29 23:01:24 +03:00
|
|
|
err = w.Handler.AdminUploadFile(ctx, quest)
|
2024-01-25 01:45:09 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-01-28 22:19:41 +03:00
|
|
|
// AdminListGames converts echo context to params.
|
|
|
|
func (w *ServerInterfaceWrapper) AdminListGames(ctx echo.Context) error {
|
2024-01-25 01:45:09 +03:00
|
|
|
var err error
|
|
|
|
|
2024-01-28 22:19:41 +03:00
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
2024-01-25 01:45:09 +03:00
|
|
|
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
2024-01-28 22:19:41 +03:00
|
|
|
err = w.Handler.AdminListGames(ctx)
|
2024-01-25 01:45:09 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-01-28 22:19:41 +03:00
|
|
|
// AdminEditGame converts echo context to params.
|
|
|
|
func (w *ServerInterfaceWrapper) AdminEditGame(ctx echo.Context) error {
|
2024-01-25 01:45:09 +03:00
|
|
|
var err error
|
|
|
|
|
|
|
|
ctx.Set(CookieAuthScopes, []string{"creator", "admin"})
|
|
|
|
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
2024-01-28 22:19:41 +03:00
|
|
|
err = w.Handler.AdminEditGame(ctx)
|
2024-01-25 01:45:09 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-01-28 22:19:41 +03:00
|
|
|
// AdminGetGame converts echo context to params.
|
|
|
|
func (w *ServerInterfaceWrapper) AdminGetGame(ctx echo.Context) error {
|
2024-01-25 01:45:09 +03:00
|
|
|
var err error
|
|
|
|
// ------------- Path parameter "uid" -------------
|
|
|
|
var uid openapi_types.UUID
|
|
|
|
|
2024-04-29 23:01:24 +03:00
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "uid", ctx.Param("uid"), &uid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
2024-01-25 01:45:09 +03:00
|
|
|
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
|
2024-01-28 22:19:41 +03:00
|
|
|
err = w.Handler.AdminGetGame(ctx, uid)
|
2024-01-25 01:45:09 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-01-05 03:50:33 +03:00
|
|
|
// GameEngine converts echo context to params.
|
|
|
|
func (w *ServerInterfaceWrapper) GameEngine(ctx echo.Context) error {
|
2023-11-01 23:21:12 +03:00
|
|
|
var err error
|
2024-01-05 03:50:33 +03:00
|
|
|
// ------------- Path parameter "uid" -------------
|
2024-01-06 08:44:26 +03:00
|
|
|
var uid openapi_types.UUID
|
2023-11-01 23:21:12 +03:00
|
|
|
|
2024-04-29 23:01:24 +03:00
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "uid", ctx.Param("uid"), &uid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
2023-11-01 23:21:12 +03:00
|
|
|
if err != nil {
|
2024-01-05 03:50:33 +03:00
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter uid: %s", err))
|
2023-11-01 23:21:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
2024-01-05 03:50:33 +03:00
|
|
|
err = w.Handler.GameEngine(ctx, uid)
|
2023-11-01 23:21:12 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-01-05 03:50:33 +03:00
|
|
|
// EnterCode converts echo context to params.
|
|
|
|
func (w *ServerInterfaceWrapper) EnterCode(ctx echo.Context) error {
|
2023-11-01 23:21:12 +03:00
|
|
|
var err error
|
2024-01-05 03:50:33 +03:00
|
|
|
// ------------- Path parameter "uid" -------------
|
2024-01-06 08:44:26 +03:00
|
|
|
var uid openapi_types.UUID
|
2023-11-01 23:21:12 +03:00
|
|
|
|
2024-04-29 23:01:24 +03:00
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "uid", ctx.Param("uid"), &uid, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
2023-11-01 23:21:12 +03:00
|
|
|
if err != nil {
|
2024-01-05 03:50:33 +03:00
|
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter uid: %s", err))
|
2023-11-01 23:21:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
2024-01-05 03:50:33 +03:00
|
|
|
err = w.Handler.EnterCode(ctx, uid)
|
2023-11-01 23:21:12 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-05-05 22:26:52 +03:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2024-01-05 03:50:33 +03:00
|
|
|
// GetGames converts echo context to params.
|
|
|
|
func (w *ServerInterfaceWrapper) GetGames(ctx echo.Context) error {
|
2023-11-12 23:22:58 +03:00
|
|
|
var err error
|
|
|
|
|
2024-01-21 02:20:59 +03:00
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
|
2023-11-12 23:22:58 +03:00
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
2024-01-05 03:50:33 +03:00
|
|
|
err = w.Handler.GetGames(ctx)
|
2023-11-12 23:22:58 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-11-01 23:21:12 +03:00
|
|
|
// 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
|
|
|
|
|
2024-01-21 02:20:59 +03:00
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
|
2023-11-01 23:21:12 +03:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2024-05-09 15:58:19 +03:00
|
|
|
// GetUsers converts echo context to params.
|
|
|
|
func (w *ServerInterfaceWrapper) GetUsers(ctx echo.Context) error {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
ctx.Set(CookieAuthScopes, []string{})
|
|
|
|
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
|
|
err = w.Handler.GetUsers(ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetUserInfo converts echo context to params.
|
|
|
|
func (w *ServerInterfaceWrapper) GetUserInfo(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.GetUserInfo(ctx, uid)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-11-01 23:21:12 +03:00
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
|
2024-04-29 23:01:24 +03:00
|
|
|
router.GET(baseURL+"/admin/file/:quest", wrapper.AdminListFiles)
|
|
|
|
router.POST(baseURL+"/admin/file/:quest/upload", wrapper.AdminUploadFile)
|
2024-01-28 22:19:41 +03:00
|
|
|
router.GET(baseURL+"/admin/games", wrapper.AdminListGames)
|
|
|
|
router.POST(baseURL+"/admin/games", wrapper.AdminEditGame)
|
|
|
|
router.GET(baseURL+"/admin/games/:uid", wrapper.AdminGetGame)
|
2024-01-05 03:50:33 +03:00
|
|
|
router.GET(baseURL+"/engine/:uid", wrapper.GameEngine)
|
|
|
|
router.POST(baseURL+"/engine/:uid/code", wrapper.EnterCode)
|
2024-05-05 22:26:52 +03:00
|
|
|
router.GET(baseURL+"/file/:uid", wrapper.GetFile)
|
2023-11-02 01:21:13 +03:00
|
|
|
router.GET(baseURL+"/games", wrapper.GetGames)
|
2023-11-01 23:21:12 +03:00
|
|
|
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)
|
2024-05-09 15:58:19 +03:00
|
|
|
router.GET(baseURL+"/users", wrapper.GetUsers)
|
|
|
|
router.GET(baseURL+"/users/:uid", wrapper.GetUserInfo)
|
2023-11-01 23:21:12 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Base64 encoded, gzipped, json marshaled Swagger object
|
|
|
|
var swaggerSpec = []string{
|
|
|
|
|
2024-05-09 15:58:19 +03:00
|
|
|
"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",
|
2023-11-01 23:21:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|