// Package api provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT.
package api

import (
	"bytes"
	"compress/gzip"
	"encoding/base64"
	"fmt"
	"net/http"
	"net/url"
	"path"
	"strings"
	"time"

	"github.com/getkin/kin-openapi/openapi3"
	"github.com/labstack/echo/v4"
	"github.com/oapi-codegen/runtime"
)

const (
	ApiKeyAuthScopes = "ApiKeyAuth.Scopes"
)

// Defines values for ErrorResponseCode.
const (
	BADREQUEST         ErrorResponseCode = "BAD_REQUEST"
	CONFLICT           ErrorResponseCode = "CONFLICT"
	FORBIDDEN          ErrorResponseCode = "FORBIDDEN"
	INTERNALERROR      ErrorResponseCode = "INTERNAL_ERROR"
	NOTFOUND           ErrorResponseCode = "NOT_FOUND"
	RATELIMITED        ErrorResponseCode = "RATE_LIMITED"
	SERVICEUNAVAILABLE ErrorResponseCode = "SERVICE_UNAVAILABLE"
	UNAUTHORIZED       ErrorResponseCode = "UNAUTHORIZED"
	VALIDATIONERROR    ErrorResponseCode = "VALIDATION_ERROR"
)

// Defines values for ExperimentStatus.
const (
	Active   ExperimentStatus = "active"
	Archived ExperimentStatus = "archived"
	Deleted  ExperimentStatus = "deleted"
)

// Defines values for HealthResponseStatus.
const (
	Degraded  HealthResponseStatus = "degraded"
	Healthy   HealthResponseStatus = "healthy"
	Unhealthy HealthResponseStatus = "unhealthy"
)

// Defines values for JupyterServiceStatus.
const (
	JupyterServiceStatusError    JupyterServiceStatus = "error"
	JupyterServiceStatusRunning  JupyterServiceStatus = "running"
	JupyterServiceStatusStarting JupyterServiceStatus = "starting"
	JupyterServiceStatusStopped  JupyterServiceStatus = "stopped"
	JupyterServiceStatusStopping JupyterServiceStatus = "stopping"
)

// Defines values for TaskStatus.
const (
	TaskStatusCollecting TaskStatus = "collecting"
	TaskStatusCompleted  TaskStatus = "completed"
	TaskStatusFailed     TaskStatus = "failed"
	TaskStatusPreparing  TaskStatus = "preparing"
	TaskStatusQueued     TaskStatus = "queued"
	TaskStatusRunning    TaskStatus = "running"
)

// Defines values for GetV1TasksParamsStatus.
const (
	Completed GetV1TasksParamsStatus = "completed"
	Failed    GetV1TasksParamsStatus = "failed"
	Queued    GetV1TasksParamsStatus = "queued"
	Running   GetV1TasksParamsStatus = "running"
)

// CreateExperimentRequest defines model for CreateExperimentRequest.
type CreateExperimentRequest struct {
	Description *string `json:"description,omitempty"`
	Name        string  `json:"name"`
}

// CreateTaskRequest defines model for CreateTaskRequest.
type CreateTaskRequest struct {
	// Args Command-line arguments for the training script
	Args *string `json:"args,omitempty"`

	// Cpu CPU cores requested
	Cpu          *int           `json:"cpu,omitempty"`
	DatasetSpecs *[]DatasetSpec `json:"dataset_specs,omitempty"`
	Datasets     *[]string      `json:"datasets,omitempty"`

	// Gpu GPUs requested
	Gpu *int `json:"gpu,omitempty"`

	// JobName Unique identifier for the job
	JobName string `json:"job_name"`

	// MemoryGb Memory (GB) requested
	MemoryGb *int               `json:"memory_gb,omitempty"`
	Metadata *map[string]string `json:"metadata,omitempty"`
	Priority *int               `json:"priority,omitempty"`

	// SnapshotId Reference to experiment snapshot
	SnapshotId *string `json:"snapshot_id,omitempty"`
}

// DatasetSpec defines model for DatasetSpec.
type DatasetSpec struct {
	MountPath *string `json:"mount_path,omitempty"`
	Name      *string `json:"name,omitempty"`
	Sha256    *string `json:"sha256,omitempty"`
	Source    *string `json:"source,omitempty"`
}

// ErrorResponse defines model for ErrorResponse.
type ErrorResponse struct {
	Code ErrorResponseCode `json:"code"`

	// Error Sanitized error message
	Error string `json:"error"`

	// TraceId Support correlation ID
	TraceId string `json:"trace_id"`
}

// ErrorResponseCode defines model for ErrorResponse.Code.
type ErrorResponseCode string

// Experiment defines model for Experiment.
type Experiment struct {
	CommitId  *string           `json:"commit_id,omitempty"`
	CreatedAt *time.Time        `json:"created_at,omitempty"`
	Id        *string           `json:"id,omitempty"`
	Name      *string           `json:"name,omitempty"`
	Status    *ExperimentStatus `json:"status,omitempty"`
}

// ExperimentStatus defines model for Experiment.Status.
type ExperimentStatus string

// HealthResponse defines model for HealthResponse.
type HealthResponse struct {
	Status    *HealthResponseStatus `json:"status,omitempty"`
	Timestamp *time.Time            `json:"timestamp,omitempty"`
	Version   *string               `json:"version,omitempty"`
}

// HealthResponseStatus defines model for HealthResponse.Status.
type HealthResponseStatus string

// JupyterService defines model for JupyterService.
type JupyterService struct {
	CreatedAt *time.Time            `json:"created_at,omitempty"`
	Id        *string               `json:"id,omitempty"`
	Name      *string               `json:"name,omitempty"`
	Status    *JupyterServiceStatus `json:"status,omitempty"`
	Token     *string               `json:"token,omitempty"`
	Url       *string               `json:"url,omitempty"`
}

// JupyterServiceStatus defines model for JupyterService.Status.
type JupyterServiceStatus string

// QueueStats defines model for QueueStats.
type QueueStats struct {
	// Completed Tasks completed today
	Completed *int `json:"completed,omitempty"`

	// Failed Tasks failed today
	Failed *int `json:"failed,omitempty"`

	// Queued Tasks waiting to run
	Queued *int `json:"queued,omitempty"`

	// Running Tasks currently executing
	Running *int `json:"running,omitempty"`

	// Workers Active workers
	Workers *int `json:"workers,omitempty"`
}

// StartJupyterRequest defines model for StartJupyterRequest.
type StartJupyterRequest struct {
	Image     *string `json:"image,omitempty"`
	Name      string  `json:"name"`
	Workspace *string `json:"workspace,omitempty"`
}

// Task defines model for Task.
type Task struct {
	Cpu       *int       `json:"cpu,omitempty"`
	CreatedAt *time.Time `json:"created_at,omitempty"`
	Datasets  *[]string  `json:"datasets,omitempty"`
	EndedAt   *time.Time `json:"ended_at,omitempty"`
	Error     *string    `json:"error,omitempty"`
	Gpu       *int       `json:"gpu,omitempty"`

	// Id Unique task identifier
	Id         *string     `json:"id,omitempty"`
	JobName    *string     `json:"job_name,omitempty"`
	MaxRetries *int        `json:"max_retries,omitempty"`
	MemoryGb   *int        `json:"memory_gb,omitempty"`
	Output     *string     `json:"output,omitempty"`
	Priority   *int        `json:"priority,omitempty"`
	RetryCount *int        `json:"retry_count,omitempty"`
	SnapshotId *string     `json:"snapshot_id,omitempty"`
	StartedAt  *time.Time  `json:"started_at,omitempty"`
	Status     *TaskStatus `json:"status,omitempty"`
	UserId     *string     `json:"user_id,omitempty"`
	WorkerId   *string     `json:"worker_id,omitempty"`
}

// TaskStatus defines model for Task.Status.
type TaskStatus string

// TaskList defines model for TaskList.
type TaskList struct {
	Limit  *int    `json:"limit,omitempty"`
	Offset *int    `json:"offset,omitempty"`
	Tasks  *[]Task `json:"tasks,omitempty"`
	Total  *int    `json:"total,omitempty"`
}

// BadRequest defines model for BadRequest.
type BadRequest = ErrorResponse

// NotFound defines model for NotFound.
type NotFound = ErrorResponse

// RateLimited defines model for RateLimited.
type RateLimited = ErrorResponse

// Unauthorized defines model for Unauthorized.
type Unauthorized = ErrorResponse

// ValidationError defines model for ValidationError.
type ValidationError = ErrorResponse

// GetV1TasksParams defines parameters for GetV1Tasks.
type GetV1TasksParams struct {
	Status *GetV1TasksParamsStatus `form:"status,omitempty" json:"status,omitempty"`
	Limit  *int                    `form:"limit,omitempty" json:"limit,omitempty"`
	Offset *int                    `form:"offset,omitempty" json:"offset,omitempty"`
}

// GetV1TasksParamsStatus defines parameters for GetV1Tasks.
type GetV1TasksParamsStatus string

// PostV1ExperimentsJSONRequestBody defines body for PostV1Experiments for application/json ContentType.
type PostV1ExperimentsJSONRequestBody = CreateExperimentRequest

// PostV1JupyterServicesJSONRequestBody defines body for PostV1JupyterServices for application/json ContentType.
type PostV1JupyterServicesJSONRequestBody = StartJupyterRequest

// PostV1TasksJSONRequestBody defines body for PostV1Tasks for application/json ContentType.
type PostV1TasksJSONRequestBody = CreateTaskRequest

// ServerInterface represents all server handlers.
type ServerInterface interface {
	// Health check
	// (GET /health)
	GetHealth(ctx echo.Context) error
	// List experiments
	// (GET /v1/experiments)
	GetV1Experiments(ctx echo.Context) error
	// Create experiment
	// (POST /v1/experiments)
	PostV1Experiments(ctx echo.Context) error
	// List Jupyter services
	// (GET /v1/jupyter/services)
	GetV1JupyterServices(ctx echo.Context) error
	// Start Jupyter service
	// (POST /v1/jupyter/services)
	PostV1JupyterServices(ctx echo.Context) error
	// Stop Jupyter service
	// (DELETE /v1/jupyter/services/{serviceId})
	DeleteV1JupyterServicesServiceId(ctx echo.Context, serviceId string) error
	// Queue status
	// (GET /v1/queue)
	GetV1Queue(ctx echo.Context) error
	// List tasks
	// (GET /v1/tasks)
	GetV1Tasks(ctx echo.Context, params GetV1TasksParams) error
	// Create task
	// (POST /v1/tasks)
	PostV1Tasks(ctx echo.Context) error
	// Cancel/delete task
	// (DELETE /v1/tasks/{taskId})
	DeleteV1TasksTaskId(ctx echo.Context, taskId string) error
	// Get task details
	// (GET /v1/tasks/{taskId})
	GetV1TasksTaskId(ctx echo.Context, taskId string) error
	// WebSocket connection
	// (GET /ws)
	GetWs(ctx echo.Context) error
}

// ServerInterfaceWrapper converts echo contexts to parameters.
type ServerInterfaceWrapper struct {
	Handler ServerInterface
}

// GetHealth converts echo context to params.
func (w *ServerInterfaceWrapper) GetHealth(ctx echo.Context) error {
	var err error

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.GetHealth(ctx)
	return err
}

// GetV1Experiments converts echo context to params.
func (w *ServerInterfaceWrapper) GetV1Experiments(ctx echo.Context) error {
	var err error

	ctx.Set(ApiKeyAuthScopes, []string{})

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.GetV1Experiments(ctx)
	return err
}

// PostV1Experiments converts echo context to params.
func (w *ServerInterfaceWrapper) PostV1Experiments(ctx echo.Context) error {
	var err error

	ctx.Set(ApiKeyAuthScopes, []string{})

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.PostV1Experiments(ctx)
	return err
}

// GetV1JupyterServices converts echo context to params.
func (w *ServerInterfaceWrapper) GetV1JupyterServices(ctx echo.Context) error {
	var err error

	ctx.Set(ApiKeyAuthScopes, []string{})

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.GetV1JupyterServices(ctx)
	return err
}

// PostV1JupyterServices converts echo context to params.
func (w *ServerInterfaceWrapper) PostV1JupyterServices(ctx echo.Context) error {
	var err error

	ctx.Set(ApiKeyAuthScopes, []string{})

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.PostV1JupyterServices(ctx)
	return err
}

// DeleteV1JupyterServicesServiceId converts echo context to params.
func (w *ServerInterfaceWrapper) DeleteV1JupyterServicesServiceId(ctx echo.Context) error {
	var err error
	// ------------- Path parameter "serviceId" -------------
	var serviceId string

	err = runtime.BindStyledParameterWithOptions("simple", "serviceId", ctx.Param("serviceId"), &serviceId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
	if err != nil {
		return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter serviceId: %s", err))
	}

	ctx.Set(ApiKeyAuthScopes, []string{})

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.DeleteV1JupyterServicesServiceId(ctx, serviceId)
	return err
}

// GetV1Queue converts echo context to params.
func (w *ServerInterfaceWrapper) GetV1Queue(ctx echo.Context) error {
	var err error

	ctx.Set(ApiKeyAuthScopes, []string{})

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.GetV1Queue(ctx)
	return err
}

// GetV1Tasks converts echo context to params.
func (w *ServerInterfaceWrapper) GetV1Tasks(ctx echo.Context) error {
	var err error

	ctx.Set(ApiKeyAuthScopes, []string{})

	// Parameter object where we will unmarshal all parameters from the context
	var params GetV1TasksParams
	// ------------- Optional query parameter "status" -------------

	err = runtime.BindQueryParameter("form", true, false, "status", ctx.QueryParams(), &params.Status)
	if err != nil {
		return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter status: %s", err))
	}

	// ------------- Optional query parameter "limit" -------------

	err = runtime.BindQueryParameter("form", true, false, "limit", ctx.QueryParams(), &params.Limit)
	if err != nil {
		return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter limit: %s", err))
	}

	// ------------- Optional query parameter "offset" -------------

	err = runtime.BindQueryParameter("form", true, false, "offset", ctx.QueryParams(), &params.Offset)
	if err != nil {
		return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter offset: %s", err))
	}

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.GetV1Tasks(ctx, params)
	return err
}

// PostV1Tasks converts echo context to params.
func (w *ServerInterfaceWrapper) PostV1Tasks(ctx echo.Context) error {
	var err error

	ctx.Set(ApiKeyAuthScopes, []string{})

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.PostV1Tasks(ctx)
	return err
}

// DeleteV1TasksTaskId converts echo context to params.
func (w *ServerInterfaceWrapper) DeleteV1TasksTaskId(ctx echo.Context) error {
	var err error
	// ------------- Path parameter "taskId" -------------
	var taskId string

	err = runtime.BindStyledParameterWithOptions("simple", "taskId", ctx.Param("taskId"), &taskId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
	if err != nil {
		return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter taskId: %s", err))
	}

	ctx.Set(ApiKeyAuthScopes, []string{})

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.DeleteV1TasksTaskId(ctx, taskId)
	return err
}

// GetV1TasksTaskId converts echo context to params.
func (w *ServerInterfaceWrapper) GetV1TasksTaskId(ctx echo.Context) error {
	var err error
	// ------------- Path parameter "taskId" -------------
	var taskId string

	err = runtime.BindStyledParameterWithOptions("simple", "taskId", ctx.Param("taskId"), &taskId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
	if err != nil {
		return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter taskId: %s", err))
	}

	ctx.Set(ApiKeyAuthScopes, []string{})

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.GetV1TasksTaskId(ctx, taskId)
	return err
}

// GetWs converts echo context to params.
func (w *ServerInterfaceWrapper) GetWs(ctx echo.Context) error {
	var err error

	ctx.Set(ApiKeyAuthScopes, []string{})

	// Invoke the callback with all the unmarshaled arguments
	err = w.Handler.GetWs(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+"/health", wrapper.GetHealth)
	router.GET(baseURL+"/v1/experiments", wrapper.GetV1Experiments)
	router.POST(baseURL+"/v1/experiments", wrapper.PostV1Experiments)
	router.GET(baseURL+"/v1/jupyter/services", wrapper.GetV1JupyterServices)
	router.POST(baseURL+"/v1/jupyter/services", wrapper.PostV1JupyterServices)
	router.DELETE(baseURL+"/v1/jupyter/services/:serviceId", wrapper.DeleteV1JupyterServicesServiceId)
	router.GET(baseURL+"/v1/queue", wrapper.GetV1Queue)
	router.GET(baseURL+"/v1/tasks", wrapper.GetV1Tasks)
	router.POST(baseURL+"/v1/tasks", wrapper.PostV1Tasks)
	router.DELETE(baseURL+"/v1/tasks/:taskId", wrapper.DeleteV1TasksTaskId)
	router.GET(baseURL+"/v1/tasks/:taskId", wrapper.GetV1TasksTaskId)
	router.GET(baseURL+"/ws", wrapper.GetWs)

}

// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{

	"H4sIAAAAAAAC/8RaW1fbuhL+K1ra+6FdxyFAL2c3bwHSNqfh0gTaszbhBGFPEoEtqZIMZLPy38+SZCe+",
	"yEDphSdIJI1nPn2a+TTOHQ55IjgDphXu3GEJSnCmwH7YIdEQvqWgtPkUcqaB2X+JEDENiaactS8VZ+Y7",
	"uCWJiMHNjAB38E53bzLsfT7pjY5xgEFKLnEH99k1iWmEpLOMplwmROMAa0lCmNAIdzDZutgOX0WvW/Bm",
	"+rb177/ebbbIRRi1YLq1/er1m7fmG7wMsArnkBDzyD8lTHEH/9Feh9N2o6rdM08eZoHh5XIZ4AhUKKkw",
	"AdRdMpYPuH7PUxY9KfCDw+PJ+8OTg71C2ENQPJUhIMZNzMb0c4bscWcZ4CHRMKAJ1fC0wIfd495k0N/v",
	"H/dKsRMNKDZ2EdyGABE8b/DHnKOEsEW+4QoHeA4kAmlpPwQtF63uVIM0H8trRxByFimUMk1jJNeRSVBg",
	"La2d1AthUKFMwwyk8WQZ4BNGUj3nkv7zRJBPDronxx8Ph/2/SyDnJOYSJVQpymaoe9RHV7B4Vqy7qZ4D",
	"01lYFnEqwbLti/HXft1zMTwBjC/dQX+ve9w/PJj0hsPDYQGQtXk0JTR+Zs7VvVmujFvW7UogGnq3AiRN",
	"gOlC5hWSC5CauqxcsrsimdKSsplxmJHEIpSQ2wGwmZ7jztb2X0F14jLAq83onLpVZ6tZ/OISQpsJnV/H",
	"RF01ekTkrO4Z3uVJQljUiikDROQsNVEpk++RngPSklBmWOrW4KAeSShSj9mjExRyCSo/vW5jK0ctwBHR",
	"RIGeKAGh9Y5qSNRD+7jnVo0EhMZIZpZISR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fKDdLV8rNTV/z",
	"xG81uwN5zfrMnP1Cjqwucfeka7frywC/dg/22Vs52C78vsMu2Xp4SenttVm0/e7hRcWfFXjqx8ppv5wZ",
	"pRcJ1ZmcqV+cGmRNztJfJ2iKr0R/c2FxF2rPDxuIusrlC1JpGIJS0zSOF7+XEtsPL6q++/9xKmX6TDto",
	"CkmwfWf+PLIYWtoc2/mPqn86n/qTi5/bScJCiOMMVjftfnhWP1uqYGMNtV3wGUTBPRr1WVDY/D3HIwJN",
	"aKx+FFIjInTJnuHcTXPJ/QoXIx5egV61b2xLSAKJbaPRWUtFRPS677Pv2hroeCFAjVkLnZtZEzfrvINs",
	"RK7KonBO2Kw4K6+n+bwpZVTNIbIzBGWz8w76BCBaJKbXgF64mCOnBs4FZ7Pzl7YFUmPI19q1ZctliqaQ",
	"Q84YhLZzAUqTi9g6Um0JlBt6p2fLUo/AZ83t8kMmbCvCkbdSNnlIYhTBNcRcuBf/di7O3nThudai027H",
	"Zt6cK915ZwI1aqFs6EjyKHXxeSyoTrtNBN2Ygg7nSbyR/YxpI+QJXp4t/x8AAP//HXQa3YQpAAA=",
}

// 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
}
