All checks were successful
Go / build (1.23) (pull_request) Successful in 19s
Go / build (1.22) (pull_request) Successful in 21s
Lint PR / commitlint (pull_request) Successful in 23s
Go / build (1.24) (pull_request) Successful in 25s
Go / build (1.23) (push) Successful in 13s
Go / build (1.22) (push) Successful in 15s
Go / build (1.24) (push) Successful in 20s
Fix ILIKE to use %?% for partial matching as expected.
381 lines
14 KiB
Go
381 lines
14 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"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
|
|
"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
|
|
|
|
// Category defines model for Category.
|
|
type Category struct {
|
|
Group *CategoryGroup `json:"group,omitempty"`
|
|
Name CategoryName `json:"name"`
|
|
}
|
|
|
|
// CategoryGroup defines model for CategoryGroup.
|
|
type CategoryGroup struct {
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
// CategoryName defines model for CategoryName.
|
|
type CategoryName = string
|
|
|
|
// Transaction defines model for Transaction.
|
|
type Transaction struct {
|
|
Category *CategoryName `json:"category,omitempty"`
|
|
Date openapi_types.Date `json:"date"`
|
|
Description string `json:"description"`
|
|
Id *int64 `json:"id,omitempty"`
|
|
Value float32 `json:"value"`
|
|
}
|
|
|
|
// Transactions defines model for Transactions.
|
|
type Transactions = []Transaction
|
|
|
|
// GetTransactionsParams defines parameters for GetTransactions.
|
|
type GetTransactionsParams struct {
|
|
// Description filter by transaction description
|
|
Description *string `form:"description,omitempty" json:"description,omitempty"`
|
|
|
|
// Category filter by transaction category
|
|
Category *CategoryName `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"`
|
|
}
|
|
|
|
// UpdateTransactionJSONBody defines parameters for UpdateTransaction.
|
|
type UpdateTransactionJSONBody struct {
|
|
Category *CategoryName `json:"category,omitempty"`
|
|
}
|
|
|
|
// CreateTransactionJSONRequestBody defines body for CreateTransaction for application/json ContentType.
|
|
type CreateTransactionJSONRequestBody = Transaction
|
|
|
|
// UpdateTransactionJSONRequestBody defines body for UpdateTransaction for application/json ContentType.
|
|
type UpdateTransactionJSONRequestBody UpdateTransactionJSONBody
|
|
|
|
// 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})
|
|
GetBankById(ctx echo.Context, bankId string) error
|
|
// Retrive existing categories
|
|
// (GET /categories)
|
|
GetCategories(ctx echo.Context) error
|
|
// Retrieve existing transactions
|
|
// (GET /transactions)
|
|
GetTransactions(ctx echo.Context, params GetTransactionsParams) error
|
|
// Create a new transaction
|
|
// (POST /transactions)
|
|
CreateTransaction(ctx echo.Context) error
|
|
// Find transaction by ID
|
|
// (GET /transactions/{transactionId})
|
|
GetTransactionById(ctx echo.Context, transactionId int64) error
|
|
// Update an existing transaction
|
|
// (PUT /transactions/{transactionId})
|
|
UpdateTransaction(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
|
|
}
|
|
|
|
// GetBankById converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetBankById(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "bankId" -------------
|
|
var bankId string
|
|
|
|
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.GetBankById(ctx, bankId)
|
|
return err
|
|
}
|
|
|
|
// GetCategories converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetCategories(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetCategories(ctx)
|
|
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 "description" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "description", ctx.QueryParams(), ¶ms.Description)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter description: %s", err))
|
|
}
|
|
|
|
// ------------- Optional query parameter "category" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "category", ctx.QueryParams(), ¶ms.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(), ¶ms.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(), ¶ms.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(), ¶ms.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(), ¶ms.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
|
|
}
|
|
|
|
// CreateTransaction converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) CreateTransaction(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.CreateTransaction(ctx)
|
|
return err
|
|
}
|
|
|
|
// GetTransactionById converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetTransactionById(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.GetTransactionById(ctx, transactionId)
|
|
return err
|
|
}
|
|
|
|
// UpdateTransaction converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) UpdateTransaction(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.UpdateTransaction(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.GetBankById)
|
|
router.GET(baseURL+"/categories", wrapper.GetCategories)
|
|
router.GET(baseURL+"/transactions", wrapper.GetTransactions)
|
|
router.POST(baseURL+"/transactions", wrapper.CreateTransaction)
|
|
router.GET(baseURL+"/transactions/:transactionId", wrapper.GetTransactionById)
|
|
router.PUT(baseURL+"/transactions/:transactionId", wrapper.UpdateTransaction)
|
|
|
|
}
|
|
|
|
// Base64 encoded, gzipped, json marshaled Swagger object
|
|
var swaggerSpec = []string{
|
|
|
|
"H4sIAAAAAAAC/8RXTW/jNhD9KwTboyJp46AHndok2MBAkQbdLFBguwdaGtncUqSWHNo1Av/3gqRs6zN2",
|
|
"mia92LI5nHnzZviGeqK5qmolQaKh2RM1+Qoq5h+vmfzLfdda1aCRg/+XF+4TtzXQjBrUXC7pLqKSVTC+",
|
|
"oHTBlyDnfl+pdMWQZtRaXtCob76LqIbvlmsoaPaFehPv+evBVC2+QY7Os8MXICFU/uFHDSXN6A/JMaek",
|
|
"SSjx2ewObpjWbOt+3zCEpdLbYaZLrWx9yu1++503bhFxzqZ7Z9tPejLfbqgB3IkKvNT7/VQhHzWThuXI",
|
|
"lRwGz1ssnp95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fv8+05bj09cezpInr39DN5YBk37",
|
|
"Tmf1Xa9F/dpP3o7anDeXpIjWdqSqn+ticNheXlRbN+9271HUf6cE/8WL927wljomGycKF7gqiDl0idhO",
|
|
"dse9wpVXzgPHr+mNUGzC5Kgk+2z+CQAA//8HPSQ02RIAAA==",
|
|
}
|
|
|
|
// 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
|
|
}
|