// 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 ExportStatus. const ( Completed ExportStatus = "completed" Failed ExportStatus = "failed" InProgress ExportStatus = "in_progress" ) // Defines values for FieldFilterCondition. const ( ClosedInterval FieldFilterCondition = "closed_interval" Exclude FieldFilterCondition = "exclude" GreaterThan FieldFilterCondition = "greater_than" Include FieldFilterCondition = "include" LeftClosedInterval FieldFilterCondition = "left_closed_interval" LessThan FieldFilterCondition = "less_than" OpenInterval FieldFilterCondition = "open_interval" RightClosedInterval FieldFilterCondition = "right_closed_interval" ) // Defines values for QueryType. const ( CONTEXTFULL QueryType = "CONTEXT_FULL" JSONEXTRACTOR QueryType = "JSON_EXTRACTOR" ) // ClientCreate defines model for ClientCreate. type ClientCreate struct { // Name The client name Name string `json:"name"` } // ClientUpdate defines model for ClientUpdate. type ClientUpdate struct { // CanSync If the client is allowing active syncs CanSync *bool `json:"can_sync,omitempty"` // Name The client name Name *string `json:"name,omitempty"` } // ExportDetails Payload for export trigger response. type ExportDetails struct { // JobId The job id relative to the export. JobId *string `json:"job_id,omitempty"` // OutputLocation The location in which the export zip file will be found. OutputLocation *string `json:"output_location,omitempty"` // Status The possible export job states. Status ExportStatus `json:"status"` } // ExportStatus The possible export job states. type ExportStatus string // ExportTrigger Payload for triggering an export. type ExportTrigger struct { // FieldFilters Filter the scope based on field output values. FieldFilters *[]FieldFilter `json:"field_filters,omitempty"` // IngestionFilters Filter the scope based on ingestion parameters. IngestionFilters *struct { // EndDate The last date of ingestion. EndDate *string `json:"end_date,omitempty"` // StartDate This first date of ingestion. StartDate *string `json:"start_date,omitempty"` } `json:"ingestion_filters,omitempty"` // JobId The job id of the query results to be exported. JobId string `json:"job_id"` } // FieldFilter Filtering a column type FieldFilter struct { // Condition The possible field filtering conditions. Condition FieldFilterCondition `json:"condition"` // FieldName The name of the field in question. FieldName string `json:"field_name"` // Values The values useful to the filter. Values []string `json:"values"` } // FieldFilterCondition The possible field filtering conditions. type FieldFilterCondition string // IdMessage defines model for IdMessage. type IdMessage struct { // Id Unique identifier for entity. Id string `json:"id"` } // JobClient defines model for JobClient. type JobClient struct { // CanSync If the client is allowing active syncs CanSync bool `json:"can_sync"` // Id The client id Id string `json:"id"` // Name The client name Name string `json:"name"` } // JobCollector JobCollector model. type JobCollector struct { // ActiveVersion The active version of the collector. ActiveVersion int32 `json:"active_version"` // Fields The fields in the job collector. Fields []JobCollectorField `json:"fields"` // JobId The ID of the associated job. JobId string `json:"job_id"` // LatestVersion The latest version of the collector. LatestVersion int32 `json:"latest_version"` // MinimumCleanerVersion The minimum version for the document cleaner. MinimumCleanerVersion int32 `json:"minimum_cleaner_version"` // MinimumTextVersion The minimum version for the text parser. MinimumTextVersion int32 `json:"minimum_text_version"` } // JobCollectorField The field properties for the job collector. type JobCollectorField struct { // Name The output field name. Name string `json:"name"` // QueryId The query id that will populate the result. QueryId string `json:"query_id"` } // JobCollectorUpdate Payload for updating a JobCollector. type JobCollectorUpdate struct { // ActiveVersion The active version of the collector. ActiveVersion *int32 `json:"active_version,omitempty"` // Fields The fields in the job collector. Fields *[]JobCollectorField `json:"fields,omitempty"` // MinimumCleanerVersion The minimum version for the document cleaner. MinimumCleanerVersion *int32 `json:"minimum_cleaner_version,omitempty"` // MinimumTextVersion The minimum version for the text parser. MinimumTextVersion *int32 `json:"minimum_text_version,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,omitempty"` // 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"` } // CreateClientJSONRequestBody defines body for CreateClient for application/json ContentType. type CreateClientJSONRequestBody = ClientCreate // UpdateClientJSONRequestBody defines body for UpdateClient for application/json ContentType. type UpdateClientJSONRequestBody = ClientUpdate // TriggerExportJSONRequestBody defines body for TriggerExport for application/json ContentType. type TriggerExportJSONRequestBody = ExportTrigger // UpdateJobCollectorByJobIdJSONRequestBody defines body for UpdateJobCollectorByJobId for application/json ContentType. type UpdateJobCollectorByJobIdJSONRequestBody = 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 { // Create a new client // (POST /clients) CreateClient(ctx echo.Context) error // Get a client by ID // (GET /clients/{id}) GetClient(ctx echo.Context, id string) error // Update a client // (PATCH /clients/{id}) UpdateClient(ctx echo.Context, id string) error // Trigger an export // (POST /job/export) TriggerExport(ctx echo.Context) error // Check export state. // (GET /job/export/{id}) ExportState(ctx echo.Context, id string) error // Get a job collector by ID // (GET /job/{id}/collector) GetJobCollectorByJobId(ctx echo.Context, id string) error // Update a job collector // (PATCH /job/{id}/collector) UpdateJobCollectorByJobId(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 // Get a query by ID // (GET /queries/{id}) GetQuery(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 } // CreateClient converts echo context to params. func (w *ServerInterfaceWrapper) CreateClient(ctx echo.Context) error { var err error // Invoke the callback with all the unmarshaled arguments err = w.Handler.CreateClient(ctx) return err } // GetClient converts echo context to params. func (w *ServerInterfaceWrapper) GetClient(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.GetClient(ctx, id) return err } // UpdateClient converts echo context to params. func (w *ServerInterfaceWrapper) UpdateClient(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.UpdateClient(ctx, id) return err } // 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 } // ExportState converts echo context to params. func (w *ServerInterfaceWrapper) ExportState(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.ExportState(ctx, id) return err } // GetJobCollectorByJobId converts echo context to params. func (w *ServerInterfaceWrapper) GetJobCollectorByJobId(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.GetJobCollectorByJobId(ctx, id) return err } // UpdateJobCollectorByJobId converts echo context to params. func (w *ServerInterfaceWrapper) UpdateJobCollectorByJobId(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.UpdateJobCollectorByJobId(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 } // GetQuery converts echo context to params. func (w *ServerInterfaceWrapper) GetQuery(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.GetQuery(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+"/clients", wrapper.CreateClient) router.GET(baseURL+"/clients/:id", wrapper.GetClient) router.PATCH(baseURL+"/clients/:id", wrapper.UpdateClient) router.POST(baseURL+"/job/export", wrapper.TriggerExport) router.GET(baseURL+"/job/export/:id", wrapper.ExportState) router.GET(baseURL+"/job/:id/collector", wrapper.GetJobCollectorByJobId) router.PATCH(baseURL+"/job/:id/collector", wrapper.UpdateJobCollectorByJobId) router.GET(baseURL+"/queries", wrapper.ListQueries) router.POST(baseURL+"/queries", wrapper.CreateQuery) router.GET(baseURL+"/queries/:id", wrapper.GetQuery) 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/+RbW2/buBL+K4TOeTTsdLtPfusm6cJFz6anSQ8WWAQGTY5sZilSISmn3sD//YAX3SzR", "UpxkkWKfGlvkDDnfNxfNuI8JkVkuBQijk/ljoskGMuz+POcMhDlXgA3Yz7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NHRZuzKJxFSEHPigwjGXNAGH+BijMD4eNOrmZ+DhPPFAvBDHP0aUxPcyXtzbps", "CdM/Pwp8pcTQnjO+pcxw2ZqGvxIDPslVPGAEq9RT1QYDwnA4woDjOeR8A+RPTwFSKGUp6KbG1tdbE9w2", "Hep5NDwtdtQC33bmaP9UIk6JDdZoBSBQNVmPA3xZT+ajODs8Sm90SExHIG0hnpHm0GR8wdDq/Q3UDc2O", "3y+7T3K1oGPgtyoWF1XV3O40vvkCojJrDws+tYzXLiUiLl4vH6gOOsC0ioTmyU4sFdoKxlYMJ3KgDgFt", "tT9GFdEzDRiVnwY58JolxUi2VaVFC5hBqtnY03hZHww4vN3Qbv6ox/2shihmQDHc5V2zgf6Kvt5U0+Pq", "Hw5v8LJvDL5FEAXJtSvvKyOU0LhdLfcf0RXwDZMnNwX8XOB1/KvZGH5LhZ9H5ZU7AvfBsBFQG452Qj/A", "g308rZfIPiGIV73fH6cZECZjMZBfpQ8w4NU+0VcQtRJ817XHZ/aGh4/I6M+B/wfI3c0m+akNAI/jaybr", "AaZUSfqJwWJmyuFRb2K4/A6k8JnBDYdU4aY7OJoj2r9vPegRgH5WKCmnMG+bSc2h3Hg6vbT+MPTqiWY3", "DsfwS5jn5CgnaJhwdg+obT/SX5SkBanmImDLykLxZJ5sjMn1fDbDOZuGX+ZPicxm23eJhS9oO5R3VRJO", "+/9VANQSp5yKVHRp98T2k3FiWvVvQ1pf/TtWZl2yBWEt842V4vsBDSntRsD+dv//AAAA///KtJqFMTMA", "AA==", } // 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 }