datastore/internal/api/server.gen.go

313 lines
11 KiB
Go

// Package api provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.1.0 DO NOT EDIT.
package api
import (
"bytes"
"compress/gzip"
"encoding/base64"
"errors"
"fmt"
"net/http"
"net/url"
"path"
"strings"
"time"
"github.com/getkin/kin-openapi/openapi3"
"github.com/labstack/echo/v4"
"github.com/oapi-codegen/runtime"
openapi_types "github.com/oapi-codegen/runtime/types"
)
// Bank defines model for Bank.
type Bank struct {
Id string `json:"id"`
Name string `json:"name"`
NordigenId *openapi_types.UUID `json:"nordigenId,omitempty"`
}
// Banks defines model for Banks.
type Banks = []Bank
// Manually added date time that implements the Scanner interface
type ScannableDate struct {
openapi_types.Date
}
func (d *ScannableDate) Scan(src any) error {
switch s := src.(type) {
case time.Time:
d.Time = s
return nil
}
return errors.New("column is not convertible to date")
}
// Transaction defines model for Transaction.
type Transaction struct {
Category *string `json:"category,omitempty"`
Date ScannableDate `json:"date"`
Description string `json:"description"`
Id int64 `json:"id"`
Value float32 `json:"value"`
}
// Transactions defines model for Transactions.
type Transactions = []Transaction
// GetTransactionsParams defines parameters for GetTransactions.
type GetTransactionsParams struct {
// Category filter by transaction category
Category *string `form:"category,omitempty" json:"category,omitempty"`
// Limit number of transactions to return
Limit *int32 `form:"limit,omitempty" json:"limit,omitempty"`
// Offset offset from where to retrieve transactions
Offset *int32 `form:"offset,omitempty" json:"offset,omitempty"`
// Bank ID of the bank
Bank *string `form:"bank,omitempty" json:"bank,omitempty"`
// Sort field name by which to sort
Sort *string `form:"sort,omitempty" json:"sort,omitempty"`
}
// ServerInterface represents all server handlers.
type ServerInterface interface {
// Retrieve existing banks
// (GET /banks)
GetBanks(ctx echo.Context) error
// Find bank by ID
// (GET /banks/{bankId})
GetBanksById(ctx echo.Context, bankId int64) error
// Retrieve existing transactions
// (GET /transactions)
GetTransactions(ctx echo.Context, params GetTransactionsParams) error
// Find transaction by ID
// (GET /transactions/{transactionId})
GetTransactionsById(ctx echo.Context, transactionId int64) error
}
// ServerInterfaceWrapper converts echo contexts to parameters.
type ServerInterfaceWrapper struct {
Handler ServerInterface
}
// GetBanks converts echo context to params.
func (w *ServerInterfaceWrapper) GetBanks(ctx echo.Context) error {
var err error
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetBanks(ctx)
return err
}
// GetBanksById converts echo context to params.
func (w *ServerInterfaceWrapper) GetBanksById(ctx echo.Context) error {
var err error
// ------------- Path parameter "bankId" -------------
var bankId int64
err = runtime.BindStyledParameterWithOptions("simple", "bankId", ctx.Param("bankId"), &bankId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter bankId: %s", err))
}
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetBanksById(ctx, bankId)
return err
}
// GetTransactions converts echo context to params.
func (w *ServerInterfaceWrapper) GetTransactions(ctx echo.Context) error {
var err error
// Parameter object where we will unmarshal all parameters from the context
var params GetTransactionsParams
// ------------- Optional query parameter "category" -------------
err = runtime.BindQueryParameter("form", true, false, "category", ctx.QueryParams(), &params.Category)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter category: %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))
}
// ------------- Optional query parameter "bank" -------------
err = runtime.BindQueryParameter("form", true, false, "bank", ctx.QueryParams(), &params.Bank)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter bank: %s", err))
}
// ------------- Optional query parameter "sort" -------------
err = runtime.BindQueryParameter("form", true, false, "sort", ctx.QueryParams(), &params.Sort)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter sort: %s", err))
}
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetTransactions(ctx, params)
return err
}
// GetTransactionsById converts echo context to params.
func (w *ServerInterfaceWrapper) GetTransactionsById(ctx echo.Context) error {
var err error
// ------------- Path parameter "transactionId" -------------
var transactionId int64
err = runtime.BindStyledParameterWithOptions("simple", "transactionId", ctx.Param("transactionId"), &transactionId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter transactionId: %s", err))
}
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetTransactionsById(ctx, transactionId)
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+"/banks", wrapper.GetBanks)
router.GET(baseURL+"/banks/:bankId", wrapper.GetBanksById)
router.GET(baseURL+"/transactions", wrapper.GetTransactions)
router.GET(baseURL+"/transactions/:transactionId", wrapper.GetTransactionsById)
}
// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{
"H4sIAAAAAAAC/8xWX2/bNhD/KgS3R0VS6mAPetqKoIGBoQvW7anrAy2dZHb8o5JHZ0bg7z4cKTuSJdcZ",
"sA57iSXzePf7c3fOM6+t7q0Bg55Xz9zXW9AiPr4V5k/67J3twaGE+K1s6C/ue+AV9+ik6fgh40ZoWD6w",
"rpEdmHW811qnBfKKhyAbnp2HHzLu4EuQDhpefeQxJGb+dAq1m89QI2UmfAkSgo4P3ztoecW/K144FQOh",
"IrI5nNII58Se3n9zwnhRo7RmTrYWCJ11+0VmjUCYcIpfZAuB4Gsn+2OJ2bmcSiMN/nDHM66lkTpoXpWn",
"nNIgdODo0k6oMC3fKivwpb4JekOhS5oOSMfAjhmXlB5p9HrBx8LOdCdU0rQ2imwNihrpEbSQiqhII0wN",
"P+rgUOQN7GYy8kdw3hqh2LsUyz6A24H7g5goWYPxUZ3Ul/zh/e/sAQw4odhj2ChZs59TENut8pJZx5RA",
"cDzjwRGCLWLvq6J4enrKOxNy67piSOuLrlc3q7y88ShMI5Q1kG9Rq0hTooIleDfslx7MT49rtspLUhuc",
"T0zKvMxv6a7twYhe8oqv8jJf8Yz3ArdR6GJzbPYOolLUpYKkoLniD4BpGshr31tCSVFvyvKoMJh4T/S9",
"knW8WXz2qSGTY68ZIJ+cmzrxIdQ1eN8GxU6oiM5deUc5p8HvLdsMiTLug9aCpov/Cugk7IDBX9KjNN0o",
"KnEvnulj3RyuivB2v26idk5oQHCeVx/PYazvmW1jDYaWOcDgqHEknZHox71T8VSVj4cIXYBspNpscs+n",
"9fDpG/vyz2wp57aszU4o2bD1PfOBoEBz0UIqyIxF1tpgmjMj30nTJF03e7a+Twbi2f64ZN9kz1xxsJUK",
"wVGVUXZ2WtiDl18CxJfBzNHxi7gmKCU2NLXJ2Nlv0nnptFmpgcbE5o10VlxJLXFSuYFWBIW8ui3LbNJG",
"qzdXfgDmqGzbekDWOqvZ0xYcDIDSXOFU2iV8KcEywJvbBXzXMaUxwy3ElrhQdzh6qXrVgFaCahhdJ/+f",
"trLeEllvHV6oMRxdrvEtJ3TS1v/CAsVpvq/v0VnwZBqL59HbleU6pvH6HTueziurdgLlf7xxJ//Z/IeL",
"d1T36/t3rPlxDR8OfwcAAP//XTQsSusLAAA=",
}
// 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
}