Files
query-orchestration/api/queryService/api.gen.go
T
Jay Brown 174644b63c Merged in jb/openapi (pull request #22)
add openapi infra

* add openapi infra

Includes generated stubs and all deps

* generatetolocation

* basesetupoffunctionsandclient

* round1controllertests

* passintegrationtests

* cleanupfromfullsuite

* storedjson

* fixjsonyaml

* fixtests


Approved-by: Michael McGuinness
2025-01-15 19:45:51 +00:00

458 lines
16 KiB
Go

// Package queryservice provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version 2.4.1 DO NOT EDIT.
package queryservice
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"
)
// Defines values for QueryType.
const (
CONTEXTFULL QueryType = "CONTEXT_FULL"
JSONEXTRACTOR QueryType = "JSON_EXTRACTOR"
)
// ExportTrigger Payload for triggering an export.
type ExportTrigger struct {
// ExampleProperty Example property for ExportTrigger.
ExampleProperty *string `json:"example_property,omitempty"`
}
// IdMessage defines model for IdMessage.
type IdMessage struct {
// Id Unique identifier.
Id string `json:"id"`
}
// JobCollector JobCollector model.
type JobCollector struct {
// ExampleProperty Example property for JobCollector.
ExampleProperty *string `json:"example_property,omitempty"`
}
// JobCollectorCreate Payload for creating a JobCollector.
type JobCollectorCreate struct {
// ExampleProperty Example property for JobCollectorCreate.
ExampleProperty *string `json:"example_property,omitempty"`
}
// JobCollectorUpdate Payload for updating a JobCollector.
type JobCollectorUpdate struct {
// ExampleProperty Example property for JobCollectorUpdate.
ExampleProperty *string `json:"example_property,omitempty"`
}
// ListQueries defines model for ListQueries.
type ListQueries struct {
// Queries List of queries.
Queries []Query `json:"queries"`
}
// Query defines model for Query.
type Query struct {
// ActiveVersion The active version of the query.
ActiveVersion int32 `json:"active_version"`
// Config Configuration for the query.
Config *string `json:"config,omitempty"`
// Id Unique identifier for the query.
Id string `json:"id"`
// LatestVersion The latest version of the query.
LatestVersion int32 `json:"latest_version"`
// RequiredQueries List of required query IDs.
RequiredQueries []string `json:"required_queries"`
// Type Specifies the type of the query.
Type QueryType `json:"type"`
}
// QueryCreate defines model for QueryCreate.
type QueryCreate struct {
// Config Configuration for the new query.
Config *string `json:"config,omitempty"`
// RequiredQueries List of required query IDs.
RequiredQueries *[]string `json:"required_queries,omitempty"`
// Type Specifies the type of the query.
Type QueryType `json:"type"`
}
// QueryTestRequest defines model for QueryTestRequest.
type QueryTestRequest struct {
// DocumentId ID of the document to test against.
DocumentId string `json:"document_id"`
// QueryVersion Version of the query to use for testing.
QueryVersion int32 `json:"query_version"`
}
// QueryTestResponse defines model for QueryTestResponse.
type QueryTestResponse struct {
// Value Result of the query test.
Value string `json:"value"`
}
// QueryType Specifies the type of the query.
type QueryType string
// QueryUpdate defines model for QueryUpdate.
type QueryUpdate struct {
// ActiveVersion Updated active version.
ActiveVersion *int32 `json:"active_version,omitempty"`
// Config Updated configuration for the query.
Config *string `json:"config,omitempty"`
// RequiredQueries Updated list of required query IDs.
RequiredQueries *[]string `json:"required_queries,omitempty"`
}
// TriggerExportJSONRequestBody defines body for TriggerExport for application/json ContentType.
type TriggerExportJSONRequestBody = ExportTrigger
// CreateJobCollectorJSONRequestBody defines body for CreateJobCollector for application/json ContentType.
type CreateJobCollectorJSONRequestBody = JobCollectorCreate
// UpdateJobCollectorJSONRequestBody defines body for UpdateJobCollector for application/json ContentType.
type UpdateJobCollectorJSONRequestBody = JobCollectorUpdate
// CreateQueryJSONRequestBody defines body for CreateQuery for application/json ContentType.
type CreateQueryJSONRequestBody = QueryCreate
// UpdateQueryJSONRequestBody defines body for UpdateQuery for application/json ContentType.
type UpdateQueryJSONRequestBody = QueryUpdate
// TestQueryJSONRequestBody defines body for TestQuery for application/json ContentType.
type TestQueryJSONRequestBody = QueryTestRequest
// ServerInterface represents all server handlers.
type ServerInterface interface {
// Trigger an export
// (POST /exports/trigger)
TriggerExport(ctx echo.Context) error
// Create a job collector
// (POST /job-collectors)
CreateJobCollector(ctx echo.Context) error
// Get a job collector by ID
// (GET /job-collectors/{id})
GetJobCollectorById(ctx echo.Context, id string) error
// Update a job collector
// (PUT /job-collectors/{id})
UpdateJobCollector(ctx echo.Context, id string) error
// List queries
// (GET /queries)
ListQueries(ctx echo.Context) error
// Create a new query
// (POST /queries)
CreateQuery(ctx echo.Context) error
// Deprecate a query
// (DELETE /queries/{id})
DeprecateQuery(ctx echo.Context, id string) error
// Get a query by ID
// (GET /queries/{id})
GetQueryById(ctx echo.Context, id string) error
// Update a query
// (PATCH /queries/{id})
UpdateQuery(ctx echo.Context, id string) error
// Test a query
// (POST /queries/{id}/test)
TestQuery(ctx echo.Context, id string) error
}
// ServerInterfaceWrapper converts echo contexts to parameters.
type ServerInterfaceWrapper struct {
Handler ServerInterface
}
// TriggerExport converts echo context to params.
func (w *ServerInterfaceWrapper) TriggerExport(ctx echo.Context) error {
var err error
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.TriggerExport(ctx)
return err
}
// CreateJobCollector converts echo context to params.
func (w *ServerInterfaceWrapper) CreateJobCollector(ctx echo.Context) error {
var err error
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.CreateJobCollector(ctx)
return err
}
// GetJobCollectorById converts echo context to params.
func (w *ServerInterfaceWrapper) GetJobCollectorById(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetJobCollectorById(ctx, id)
return err
}
// UpdateJobCollector converts echo context to params.
func (w *ServerInterfaceWrapper) UpdateJobCollector(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.UpdateJobCollector(ctx, id)
return err
}
// ListQueries converts echo context to params.
func (w *ServerInterfaceWrapper) ListQueries(ctx echo.Context) error {
var err error
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.ListQueries(ctx)
return err
}
// CreateQuery converts echo context to params.
func (w *ServerInterfaceWrapper) CreateQuery(ctx echo.Context) error {
var err error
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.CreateQuery(ctx)
return err
}
// DeprecateQuery converts echo context to params.
func (w *ServerInterfaceWrapper) DeprecateQuery(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.DeprecateQuery(ctx, id)
return err
}
// GetQueryById converts echo context to params.
func (w *ServerInterfaceWrapper) GetQueryById(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetQueryById(ctx, id)
return err
}
// UpdateQuery converts echo context to params.
func (w *ServerInterfaceWrapper) UpdateQuery(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.UpdateQuery(ctx, id)
return err
}
// TestQuery converts echo context to params.
func (w *ServerInterfaceWrapper) TestQuery(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id string
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.TestQuery(ctx, id)
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.POST(baseURL+"/exports/trigger", wrapper.TriggerExport)
router.POST(baseURL+"/job-collectors", wrapper.CreateJobCollector)
router.GET(baseURL+"/job-collectors/:id", wrapper.GetJobCollectorById)
router.PUT(baseURL+"/job-collectors/:id", wrapper.UpdateJobCollector)
router.GET(baseURL+"/queries", wrapper.ListQueries)
router.POST(baseURL+"/queries", wrapper.CreateQuery)
router.DELETE(baseURL+"/queries/:id", wrapper.DeprecateQuery)
router.GET(baseURL+"/queries/:id", wrapper.GetQueryById)
router.PATCH(baseURL+"/queries/:id", wrapper.UpdateQuery)
router.POST(baseURL+"/queries/:id/test", wrapper.TestQuery)
}
// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{
"H4sIAAAAAAAC/9RZS2/bOBD+KwR3j17bfZx8S5Ns4aLbZFN3UaAIAloc2wwkUSFHbo3C/31BUm9RkVzb",
"RXtrZHKe33wznH6ngYwSGUOMms6+Ux1sIGL2n9ffEqlwocR6Dcp84KADJRIUMqYzest2oWScrKQi6A6J",
"eE1YTMBeHNMRTZRMQKEAKxC+sSgJ4SH7umvLvHYnSH7CCq/ZYaTiLgE6oxqNQrrfF1/k8hECpPsRnfN/",
"QGu2BqOjboXgbb2fYvGUAhEcYhQr0aVGwVMqFHA6+2LE3HsUv5PLSxmGEKD0xKz6K4kkh/BkUaqKHhik",
"6pVLBQzh+SwH5ozNcUvbyV1w9vyAI58S3utIas78JEecPQMdeS80/puCytTXjXkqf6jbYG4RuSLZAaNL",
"IET25J8KVnRG/5iUZT7JanxiNO1oaQdTiu1aQM/V+tDuJLQsZQGKLTxsQWlrYdPgxQaIO0OyM8Z83IB1",
"YWccWEkVMaQzKmJ89bKMnogRDB3tRzSQ8Uqs29Iv7fdUMfO3o6eq5EYaRsMIYYCckCFofN5rd+YYr/PU",
"PPTCIT/pxJP5VR0ZLfvrKMj/HgChhTno4cdMxKiJh1aoPF51oq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reY4PoPPiKc9zIWft5r78FJrP",
"w6M9pVkEj7C+VI4OGMt6k/YWLF3tDp/DipT9PvNXtq7uqtD6wPVzKNkNZ0WaakNZm5cZBpth81iFngfM",
"YcdU7G8weFXXVIMaQydJnGTS8g9OBxL4BPOtrLdZX3+DIHUMbreuKrVrU9bZt6tYbq1nwA01PwqRfL35",
"awOkuu0ejpJT68+2yR6SWtg82u3xkUshu4bvBZy5A2rrz/StkjwNioUjmFE/VSGd0Q1iomeTCUvEOPvf",
"z3Ego8n2BTXpy7Q15d3kgNNEQWhrDGVlVs3gUrNxPxompfYkqQjzPUmGyswWoaWw+jZtf7//PwAA///0",
"wy/PGCEAAA==",
}
// 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
}