diff --git a/clients/algoliasearch-client-go/algolia/abtesting/api_abtesting.go b/clients/algoliasearch-client-go/algolia/abtesting/api_abtesting.go index a410cbc66b..0a4482f16c 100644 --- a/clients/algoliasearch-client-go/algolia/abtesting/api_abtesting.go +++ b/clients/algoliasearch-client-go/algolia/abtesting/api_abtesting.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "github.com/algolia/algoliasearch-client-go/v4/algolia/call" + "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" ) type Option struct { @@ -105,8 +105,9 @@ func (c *APIClient) AddABTestsWithContext(ctx context.Context, r ApiAddABTestsRe headers := make(map[string]string) queryParams := url.Values{} + if r.addABTestsRequest == nil { - return returnValue, reportError("addABTestsRequest is required and must be specified") + return returnValue, reportError("Parameter `addABTestsRequest` is required when calling `AddABTests`.") } // optional params if any @@ -126,7 +127,7 @@ func (c *APIClient) AddABTestsWithContext(ctx context.Context, r ApiAddABTestsRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -245,12 +246,15 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomDelete`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -271,7 +275,7 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -390,12 +394,15 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomGet`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -416,7 +423,7 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -553,12 +560,15 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPost`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -575,7 +585,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -585,7 +595,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -722,12 +732,15 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPut`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -744,7 +757,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -754,7 +767,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -857,7 +870,7 @@ func (c *APIClient) DeleteABTestWithContext(ctx context.Context, r ApiDeleteABTe ) requestPath := "/2/abtests/{id}" - requestPath = strings.ReplaceAll(requestPath, "{"+"id"+"}", url.PathEscape(parameterToString(r.id))) + requestPath = strings.ReplaceAll(requestPath, "{id}", url.PathEscape(parameterToString(r.id))) headers := make(map[string]string) queryParams := url.Values{} @@ -877,7 +890,7 @@ func (c *APIClient) DeleteABTestWithContext(ctx context.Context, r ApiDeleteABTe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -980,7 +993,7 @@ func (c *APIClient) GetABTestWithContext(ctx context.Context, r ApiGetABTestRequ ) requestPath := "/2/abtests/{id}" - requestPath = strings.ReplaceAll(requestPath, "{"+"id"+"}", url.PathEscape(parameterToString(r.id))) + requestPath = strings.ReplaceAll(requestPath, "{id}", url.PathEscape(parameterToString(r.id))) headers := make(map[string]string) queryParams := url.Values{} @@ -1000,7 +1013,7 @@ func (c *APIClient) GetABTestWithContext(ctx context.Context, r ApiGetABTestRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1163,16 +1176,16 @@ func (c *APIClient) ListABTestsWithContext(ctx context.Context, r ApiListABTests headers := make(map[string]string) queryParams := url.Values{} - if !isNilorEmpty(r.offset) { + if !utils.IsNilOrEmpty(r.offset) { queryParams.Set("offset", parameterToString(r.offset)) } - if !isNilorEmpty(r.limit) { + if !utils.IsNilOrEmpty(r.limit) { queryParams.Set("limit", parameterToString(r.limit)) } - if !isNilorEmpty(r.indexPrefix) { + if !utils.IsNilOrEmpty(r.indexPrefix) { queryParams.Set("indexPrefix", parameterToString(r.indexPrefix)) } - if !isNilorEmpty(r.indexSuffix) { + if !utils.IsNilOrEmpty(r.indexSuffix) { queryParams.Set("indexSuffix", parameterToString(r.indexSuffix)) } @@ -1191,7 +1204,7 @@ func (c *APIClient) ListABTestsWithContext(ctx context.Context, r ApiListABTests return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1296,7 +1309,7 @@ func (c *APIClient) StopABTestWithContext(ctx context.Context, r ApiStopABTestRe ) requestPath := "/2/abtests/{id}/stop" - requestPath = strings.ReplaceAll(requestPath, "{"+"id"+"}", url.PathEscape(parameterToString(r.id))) + requestPath = strings.ReplaceAll(requestPath, "{id}", url.PathEscape(parameterToString(r.id))) headers := make(map[string]string) queryParams := url.Values{} @@ -1316,7 +1329,7 @@ func (c *APIClient) StopABTestWithContext(ctx context.Context, r ApiStopABTestRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } diff --git a/clients/algoliasearch-client-go/algolia/abtesting/client.go b/clients/algoliasearch-client-go/algolia/abtesting/client.go index 54b32ece2c..e0cfbca192 100644 --- a/clients/algoliasearch-client-go/algolia/abtesting/client.go +++ b/clients/algoliasearch-client-go/algolia/abtesting/client.go @@ -16,6 +16,7 @@ import ( "reflect" "regexp" "runtime" + "slices" "strings" "time" @@ -23,7 +24,7 @@ import ( "github.com/algolia/algoliasearch-client-go/v4/algolia/call" "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/transport" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) var jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) @@ -37,31 +38,33 @@ type APIClient struct { } // NewClient creates a new API client with appID, apiKey and region. -func NewClient(appID, apiKey string, region Region) *APIClient { +func NewClient(appID, apiKey string, region Region) (*APIClient, error) { return NewClientWithConfig(Configuration{ - AppID: appID, - ApiKey: apiKey, - Region: region, - DefaultHeader: make(map[string]string), - UserAgent: getUserAgent(), - Debug: false, - Requester: newDefaultRequester(), + Configuration: transport.Configuration{ + AppID: appID, + ApiKey: apiKey, + DefaultHeader: make(map[string]string), + UserAgent: getUserAgent(), + Debug: false, + Requester: transport.NewDefaultRequester(nil), + }, + Region: region, }) } // NewClientWithConfig creates a new API client with the given configuration to fully customize the client behaviour. -func NewClientWithConfig(cfg Configuration) *APIClient { +func NewClientWithConfig(cfg Configuration) (*APIClient, error) { var hosts []*transport.StatefulHost if cfg.AppID == "" { - panic("appID is required") + return nil, errors.New("`appId` is missing.") } if cfg.ApiKey == "" { - panic("apiKey is required") + return nil, errors.New("`apiKey` is missing.") } if len(cfg.Hosts) == 0 { - if cfg.Region == "" { - panic("region is required") + if cfg.Region != "" && !slices.Contains(allowedRegions[:], string(cfg.Region)) { + return nil, fmt.Errorf("`region` must be one of the following: %s", strings.Join(allowedRegions[:], ", ")) } hosts = getDefaultHosts(cfg.Region) } else { @@ -70,7 +73,7 @@ func NewClientWithConfig(cfg Configuration) *APIClient { } } if cfg.Requester == nil { - cfg.Requester = newDefaultRequester() + cfg.Requester = transport.NewDefaultRequester(&cfg.ConnectTimeout) } if cfg.UserAgent == "" { cfg.UserAgent = getUserAgent() @@ -84,20 +87,18 @@ func NewClientWithConfig(cfg Configuration) *APIClient { cfg.Requester, cfg.ReadTimeout, cfg.WriteTimeout, + cfg.ConnectTimeout, cfg.Compression, ), - } + }, nil } func getDefaultHosts(r Region) []*transport.StatefulHost { - hosts := []*transport.StatefulHost{} - switch r { - case DE, US: - hosts = append(hosts, transport.NewStatefulHost(strings.ReplaceAll("analytics.{region}.algolia.com", "{region}", string(r)), call.IsReadWrite)) - default: - hosts = append(hosts, transport.NewStatefulHost("analytics.algolia.com", call.IsReadWrite)) + if r == "" { + return []*transport.StatefulHost{transport.NewStatefulHost("analytics.algolia.com", call.IsReadWrite)} } - return hosts + + return []*transport.StatefulHost{transport.NewStatefulHost(strings.ReplaceAll("analytics.{region}.algolia.com", "{region}", string(r)), call.IsReadWrite)} } func getUserAgent() string { @@ -121,7 +122,7 @@ func (c *APIClient) AddDefaultHeader(key string, value string) { } // callAPI do the request. -func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Response, error) { +func (c *APIClient) callAPI(request *http.Request, useReadTransporter bool) (*http.Response, error) { if c.cfg.Debug { dump, err := httputil.DumpRequestOut(request, true) if err != nil { @@ -130,7 +131,12 @@ func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Respon log.Printf("\n%s\n", string(dump)) } - resp, err := c.transport.Request(request.Context(), request, kind) + callKind := call.Write + if useReadTransporter || request.Method == http.MethodGet { + callKind = call.Read + } + + resp, err := c.transport.Request(request.Context(), request, callKind) if err != nil { return nil, err } diff --git a/clients/algoliasearch-client-go/algolia/abtesting/configuration.go b/clients/algoliasearch-client-go/algolia/abtesting/configuration.go index 25a2c4a118..d110ddd63c 100644 --- a/clients/algoliasearch-client-go/algolia/abtesting/configuration.go +++ b/clients/algoliasearch-client-go/algolia/abtesting/configuration.go @@ -2,29 +2,10 @@ package abtesting import ( - "net/http" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -type Requester interface { - Request(*http.Request) (*http.Response, error) -} - -type defaultRequester struct { - client *http.Client -} - -func newDefaultRequester() *defaultRequester { - return &defaultRequester{ - client: http.DefaultClient, - } -} - -func (r *defaultRequester) Request(req *http.Request) (*http.Response, error) { - return r.client.Do(req) -} +var allowedRegions = [...]string{"de", "us"} type Region string @@ -35,16 +16,7 @@ const ( // Configuration stores the configuration of the API client. type Configuration struct { - AppID string - ApiKey string - Region Region + transport.Configuration - Hosts []string `json:"host,omitempty"` - DefaultHeader map[string]string `json:"defaultHeader,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Debug bool `json:"debug,omitempty"` - Requester Requester - ReadTimeout time.Duration - WriteTimeout time.Duration - Compression compression.Compression + Region Region } diff --git a/clients/algoliasearch-client-go/algolia/abtesting/response.go b/clients/algoliasearch-client-go/algolia/abtesting/response.go deleted file mode 100644 index 9532a9921e..0000000000 --- a/clients/algoliasearch-client-go/algolia/abtesting/response.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -A/B Testing API - -API powering the A/B Testing feature of Algolia. - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package abtesting - -import ( - "net/http" -) - -// APIResponse stores the API response returned by the server. -type APIResponse struct { - *http.Response `json:"-"` - Message string `json:"message,omitempty"` - // Operation is the name of the OpenAPI operation. - Operation string `json:"operation,omitempty"` - // RequestURL is the request URL. This value is always available, even if the - // embedded *http.Response is nil. - RequestURL string `json:"url,omitempty"` - // Method is the HTTP method used for the request. This value is always - // available, even if the embedded *http.Response is nil. - Method string `json:"method,omitempty"` - // Payload holds the contents of the response body (which may be nil or empty). - // This is provided here as the raw response.Body() reader will have already - // been drained. - Payload []byte `json:"-"` -} - -// NewAPIResponse returns a new APIResponse object. -func NewAPIResponse(r *http.Response) *APIResponse { - - response := &APIResponse{Response: r} - return response -} - -// NewAPIResponseWithError returns a new APIResponse object with the provided error message. -func NewAPIResponseWithError(errorMessage string) *APIResponse { - - response := &APIResponse{Message: errorMessage} - return response -} diff --git a/clients/algoliasearch-client-go/algolia/analytics/api_analytics.go b/clients/algoliasearch-client-go/algolia/analytics/api_analytics.go index 7b0c3a1b93..8697090c71 100644 --- a/clients/algoliasearch-client-go/algolia/analytics/api_analytics.go +++ b/clients/algoliasearch-client-go/algolia/analytics/api_analytics.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "github.com/algolia/algoliasearch-client-go/v4/algolia/call" + "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" ) type Option struct { @@ -115,12 +115,15 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomDelete`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -141,7 +144,7 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -260,12 +263,15 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomGet`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -286,7 +292,7 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -423,12 +429,15 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPost`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -445,7 +454,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -455,7 +464,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -592,12 +601,15 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPut`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -614,7 +626,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -624,7 +636,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -785,17 +797,17 @@ func (c *APIClient) GetAverageClickPositionWithContext(ctx context.Context, r Ap headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetAverageClickPosition`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -814,7 +826,7 @@ func (c *APIClient) GetAverageClickPositionWithContext(ctx context.Context, r Ap return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -977,17 +989,17 @@ func (c *APIClient) GetClickPositionsWithContext(ctx context.Context, r ApiGetCl headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetClickPositions`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -1006,7 +1018,7 @@ func (c *APIClient) GetClickPositionsWithContext(ctx context.Context, r ApiGetCl return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1165,17 +1177,17 @@ func (c *APIClient) GetClickThroughRateWithContext(ctx context.Context, r ApiGet headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetClickThroughRate`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -1194,7 +1206,7 @@ func (c *APIClient) GetClickThroughRateWithContext(ctx context.Context, r ApiGet return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1353,17 +1365,17 @@ func (c *APIClient) GetConversationRateWithContext(ctx context.Context, r ApiGet headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetConversationRate`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -1382,7 +1394,7 @@ func (c *APIClient) GetConversationRateWithContext(ctx context.Context, r ApiGet return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1541,17 +1553,17 @@ func (c *APIClient) GetNoClickRateWithContext(ctx context.Context, r ApiGetNoCli headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetNoClickRate`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -1570,7 +1582,7 @@ func (c *APIClient) GetNoClickRateWithContext(ctx context.Context, r ApiGetNoCli return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1729,17 +1741,17 @@ func (c *APIClient) GetNoResultsRateWithContext(ctx context.Context, r ApiGetNoR headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetNoResultsRate`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -1758,7 +1770,7 @@ func (c *APIClient) GetNoResultsRateWithContext(ctx context.Context, r ApiGetNoR return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1917,17 +1929,17 @@ func (c *APIClient) GetSearchesCountWithContext(ctx context.Context, r ApiGetSea headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetSearchesCount`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -1946,7 +1958,7 @@ func (c *APIClient) GetSearchesCountWithContext(ctx context.Context, r ApiGetSea return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2141,23 +2153,23 @@ func (c *APIClient) GetSearchesNoClicksWithContext(ctx context.Context, r ApiGet headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetSearchesNoClicks`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.limit) { + if !utils.IsNilOrEmpty(r.limit) { queryParams.Set("limit", parameterToString(r.limit)) } - if !isNilorEmpty(r.offset) { + if !utils.IsNilOrEmpty(r.offset) { queryParams.Set("offset", parameterToString(r.offset)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -2176,7 +2188,7 @@ func (c *APIClient) GetSearchesNoClicksWithContext(ctx context.Context, r ApiGet return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2371,23 +2383,23 @@ func (c *APIClient) GetSearchesNoResultsWithContext(ctx context.Context, r ApiGe headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetSearchesNoResults`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.limit) { + if !utils.IsNilOrEmpty(r.limit) { queryParams.Set("limit", parameterToString(r.limit)) } - if !isNilorEmpty(r.offset) { + if !utils.IsNilOrEmpty(r.offset) { queryParams.Set("offset", parameterToString(r.offset)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -2406,7 +2418,7 @@ func (c *APIClient) GetSearchesNoResultsWithContext(ctx context.Context, r ApiGe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2513,7 +2525,7 @@ func (c *APIClient) GetStatusWithContext(ctx context.Context, r ApiGetStatusRequ headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetStatus`.") } queryParams.Set("index", parameterToString(r.index)) @@ -2533,7 +2545,7 @@ func (c *APIClient) GetStatusWithContext(ctx context.Context, r ApiGetStatusRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2728,23 +2740,23 @@ func (c *APIClient) GetTopCountriesWithContext(ctx context.Context, r ApiGetTopC headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetTopCountries`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.limit) { + if !utils.IsNilOrEmpty(r.limit) { queryParams.Set("limit", parameterToString(r.limit)) } - if !isNilorEmpty(r.offset) { + if !utils.IsNilOrEmpty(r.offset) { queryParams.Set("offset", parameterToString(r.offset)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -2763,7 +2775,7 @@ func (c *APIClient) GetTopCountriesWithContext(ctx context.Context, r ApiGetTopC return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2976,26 +2988,26 @@ func (c *APIClient) GetTopFilterAttributesWithContext(ctx context.Context, r Api headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetTopFilterAttributes`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.search) { + if !utils.IsNilOrEmpty(r.search) { queryParams.Set("search", parameterToString(r.search)) } - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.limit) { + if !utils.IsNilOrEmpty(r.limit) { queryParams.Set("limit", parameterToString(r.limit)) } - if !isNilorEmpty(r.offset) { + if !utils.IsNilOrEmpty(r.offset) { queryParams.Set("offset", parameterToString(r.offset)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -3014,7 +3026,7 @@ func (c *APIClient) GetTopFilterAttributesWithContext(ctx context.Context, r Api return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3236,31 +3248,34 @@ func (c *APIClient) GetTopFilterForAttributeWithContext(ctx context.Context, r A ) requestPath := "/2/filters/{attribute}" - requestPath = strings.ReplaceAll(requestPath, "{"+"attribute"+"}", url.PathEscape(parameterToString(r.attribute))) + requestPath = strings.ReplaceAll(requestPath, "{attribute}", url.PathEscape(parameterToString(r.attribute))) headers := make(map[string]string) queryParams := url.Values{} + if r.attribute == "" { + return returnValue, reportError("Parameter `attribute` is required when calling `GetTopFilterForAttribute`.") + } if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetTopFilterForAttribute`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.search) { + if !utils.IsNilOrEmpty(r.search) { queryParams.Set("search", parameterToString(r.search)) } - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.limit) { + if !utils.IsNilOrEmpty(r.limit) { queryParams.Set("limit", parameterToString(r.limit)) } - if !isNilorEmpty(r.offset) { + if !utils.IsNilOrEmpty(r.offset) { queryParams.Set("offset", parameterToString(r.offset)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -3279,7 +3294,7 @@ func (c *APIClient) GetTopFilterForAttributeWithContext(ctx context.Context, r A return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3492,26 +3507,26 @@ func (c *APIClient) GetTopFiltersNoResultsWithContext(ctx context.Context, r Api headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetTopFiltersNoResults`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.search) { + if !utils.IsNilOrEmpty(r.search) { queryParams.Set("search", parameterToString(r.search)) } - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.limit) { + if !utils.IsNilOrEmpty(r.limit) { queryParams.Set("limit", parameterToString(r.limit)) } - if !isNilorEmpty(r.offset) { + if !utils.IsNilOrEmpty(r.offset) { queryParams.Set("offset", parameterToString(r.offset)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -3530,7 +3545,7 @@ func (c *APIClient) GetTopFiltersNoResultsWithContext(ctx context.Context, r Api return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3761,29 +3776,29 @@ func (c *APIClient) GetTopHitsWithContext(ctx context.Context, r ApiGetTopHitsRe headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetTopHits`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.search) { + if !utils.IsNilOrEmpty(r.search) { queryParams.Set("search", parameterToString(r.search)) } - if !isNilorEmpty(r.clickAnalytics) { + if !utils.IsNilOrEmpty(r.clickAnalytics) { queryParams.Set("clickAnalytics", parameterToString(r.clickAnalytics)) } - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.limit) { + if !utils.IsNilOrEmpty(r.limit) { queryParams.Set("limit", parameterToString(r.limit)) } - if !isNilorEmpty(r.offset) { + if !utils.IsNilOrEmpty(r.offset) { queryParams.Set("offset", parameterToString(r.offset)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -3802,7 +3817,7 @@ func (c *APIClient) GetTopHitsWithContext(ctx context.Context, r ApiGetTopHitsRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4051,32 +4066,32 @@ func (c *APIClient) GetTopSearchesWithContext(ctx context.Context, r ApiGetTopSe headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetTopSearches`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.clickAnalytics) { + if !utils.IsNilOrEmpty(r.clickAnalytics) { queryParams.Set("clickAnalytics", parameterToString(r.clickAnalytics)) } - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.orderBy) { + if !utils.IsNilOrEmpty(r.orderBy) { queryParams.Set("orderBy", parameterToString(r.orderBy)) } - if !isNilorEmpty(r.direction) { + if !utils.IsNilOrEmpty(r.direction) { queryParams.Set("direction", parameterToString(r.direction)) } - if !isNilorEmpty(r.limit) { + if !utils.IsNilOrEmpty(r.limit) { queryParams.Set("limit", parameterToString(r.limit)) } - if !isNilorEmpty(r.offset) { + if !utils.IsNilOrEmpty(r.offset) { queryParams.Set("offset", parameterToString(r.offset)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -4095,7 +4110,7 @@ func (c *APIClient) GetTopSearchesWithContext(ctx context.Context, r ApiGetTopSe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4254,17 +4269,17 @@ func (c *APIClient) GetUsersCountWithContext(ctx context.Context, r ApiGetUsersC headers := make(map[string]string) queryParams := url.Values{} if r.index == "" { - return returnValue, reportError("index is required and must be specified") + return returnValue, reportError("Parameter `index` is required when calling `GetUsersCount`.") } queryParams.Set("index", parameterToString(r.index)) - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } - if !isNilorEmpty(r.tags) { + if !utils.IsNilOrEmpty(r.tags) { queryParams.Set("tags", parameterToString(r.tags)) } @@ -4283,7 +4298,7 @@ func (c *APIClient) GetUsersCountWithContext(ctx context.Context, r ApiGetUsersC return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } diff --git a/clients/algoliasearch-client-go/algolia/analytics/client.go b/clients/algoliasearch-client-go/algolia/analytics/client.go index 7fb95c07ec..cf9ea169e6 100644 --- a/clients/algoliasearch-client-go/algolia/analytics/client.go +++ b/clients/algoliasearch-client-go/algolia/analytics/client.go @@ -16,6 +16,7 @@ import ( "reflect" "regexp" "runtime" + "slices" "strings" "time" @@ -23,7 +24,7 @@ import ( "github.com/algolia/algoliasearch-client-go/v4/algolia/call" "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/transport" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) var jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) @@ -37,31 +38,33 @@ type APIClient struct { } // NewClient creates a new API client with appID, apiKey and region. -func NewClient(appID, apiKey string, region Region) *APIClient { +func NewClient(appID, apiKey string, region Region) (*APIClient, error) { return NewClientWithConfig(Configuration{ - AppID: appID, - ApiKey: apiKey, - Region: region, - DefaultHeader: make(map[string]string), - UserAgent: getUserAgent(), - Debug: false, - Requester: newDefaultRequester(), + Configuration: transport.Configuration{ + AppID: appID, + ApiKey: apiKey, + DefaultHeader: make(map[string]string), + UserAgent: getUserAgent(), + Debug: false, + Requester: transport.NewDefaultRequester(nil), + }, + Region: region, }) } // NewClientWithConfig creates a new API client with the given configuration to fully customize the client behaviour. -func NewClientWithConfig(cfg Configuration) *APIClient { +func NewClientWithConfig(cfg Configuration) (*APIClient, error) { var hosts []*transport.StatefulHost if cfg.AppID == "" { - panic("appID is required") + return nil, errors.New("`appId` is missing.") } if cfg.ApiKey == "" { - panic("apiKey is required") + return nil, errors.New("`apiKey` is missing.") } if len(cfg.Hosts) == 0 { - if cfg.Region == "" { - panic("region is required") + if cfg.Region != "" && !slices.Contains(allowedRegions[:], string(cfg.Region)) { + return nil, fmt.Errorf("`region` must be one of the following: %s", strings.Join(allowedRegions[:], ", ")) } hosts = getDefaultHosts(cfg.Region) } else { @@ -70,7 +73,7 @@ func NewClientWithConfig(cfg Configuration) *APIClient { } } if cfg.Requester == nil { - cfg.Requester = newDefaultRequester() + cfg.Requester = transport.NewDefaultRequester(&cfg.ConnectTimeout) } if cfg.UserAgent == "" { cfg.UserAgent = getUserAgent() @@ -84,20 +87,18 @@ func NewClientWithConfig(cfg Configuration) *APIClient { cfg.Requester, cfg.ReadTimeout, cfg.WriteTimeout, + cfg.ConnectTimeout, cfg.Compression, ), - } + }, nil } func getDefaultHosts(r Region) []*transport.StatefulHost { - hosts := []*transport.StatefulHost{} - switch r { - case DE, US: - hosts = append(hosts, transport.NewStatefulHost(strings.ReplaceAll("analytics.{region}.algolia.com", "{region}", string(r)), call.IsReadWrite)) - default: - hosts = append(hosts, transport.NewStatefulHost("analytics.algolia.com", call.IsReadWrite)) + if r == "" { + return []*transport.StatefulHost{transport.NewStatefulHost("analytics.algolia.com", call.IsReadWrite)} } - return hosts + + return []*transport.StatefulHost{transport.NewStatefulHost(strings.ReplaceAll("analytics.{region}.algolia.com", "{region}", string(r)), call.IsReadWrite)} } func getUserAgent() string { @@ -121,7 +122,7 @@ func (c *APIClient) AddDefaultHeader(key string, value string) { } // callAPI do the request. -func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Response, error) { +func (c *APIClient) callAPI(request *http.Request, useReadTransporter bool) (*http.Response, error) { if c.cfg.Debug { dump, err := httputil.DumpRequestOut(request, true) if err != nil { @@ -130,7 +131,12 @@ func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Respon log.Printf("\n%s\n", string(dump)) } - resp, err := c.transport.Request(request.Context(), request, kind) + callKind := call.Write + if useReadTransporter || request.Method == http.MethodGet { + callKind = call.Read + } + + resp, err := c.transport.Request(request.Context(), request, callKind) if err != nil { return nil, err } diff --git a/clients/algoliasearch-client-go/algolia/analytics/configuration.go b/clients/algoliasearch-client-go/algolia/analytics/configuration.go index ea620b0211..b75d46cf07 100644 --- a/clients/algoliasearch-client-go/algolia/analytics/configuration.go +++ b/clients/algoliasearch-client-go/algolia/analytics/configuration.go @@ -2,29 +2,10 @@ package analytics import ( - "net/http" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -type Requester interface { - Request(*http.Request) (*http.Response, error) -} - -type defaultRequester struct { - client *http.Client -} - -func newDefaultRequester() *defaultRequester { - return &defaultRequester{ - client: http.DefaultClient, - } -} - -func (r *defaultRequester) Request(req *http.Request) (*http.Response, error) { - return r.client.Do(req) -} +var allowedRegions = [...]string{"de", "us"} type Region string @@ -35,16 +16,7 @@ const ( // Configuration stores the configuration of the API client. type Configuration struct { - AppID string - ApiKey string - Region Region + transport.Configuration - Hosts []string `json:"host,omitempty"` - DefaultHeader map[string]string `json:"defaultHeader,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Debug bool `json:"debug,omitempty"` - Requester Requester - ReadTimeout time.Duration - WriteTimeout time.Duration - Compression compression.Compression + Region Region } diff --git a/clients/algoliasearch-client-go/algolia/analytics/response.go b/clients/algoliasearch-client-go/algolia/analytics/response.go deleted file mode 100644 index 9e611f6558..0000000000 --- a/clients/algoliasearch-client-go/algolia/analytics/response.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Analytics API - -The Analytics API lets you review your search, and click and conversion analytics. > **Note**: The API key in the `X-Algolia-API-Key` header requires the [`analytics` ACL](https://www.algolia.com/doc/guides/security/api-keys/#access-control-list-acl). - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package analytics - -import ( - "net/http" -) - -// APIResponse stores the API response returned by the server. -type APIResponse struct { - *http.Response `json:"-"` - Message string `json:"message,omitempty"` - // Operation is the name of the OpenAPI operation. - Operation string `json:"operation,omitempty"` - // RequestURL is the request URL. This value is always available, even if the - // embedded *http.Response is nil. - RequestURL string `json:"url,omitempty"` - // Method is the HTTP method used for the request. This value is always - // available, even if the embedded *http.Response is nil. - Method string `json:"method,omitempty"` - // Payload holds the contents of the response body (which may be nil or empty). - // This is provided here as the raw response.Body() reader will have already - // been drained. - Payload []byte `json:"-"` -} - -// NewAPIResponse returns a new APIResponse object. -func NewAPIResponse(r *http.Response) *APIResponse { - - response := &APIResponse{Response: r} - return response -} - -// NewAPIResponseWithError returns a new APIResponse object with the provided error message. -func NewAPIResponseWithError(errorMessage string) *APIResponse { - - response := &APIResponse{Message: errorMessage} - return response -} diff --git a/clients/algoliasearch-client-go/algolia/analytics/utils.go b/clients/algoliasearch-client-go/algolia/analytics/utils.go deleted file mode 100644 index fe1f1f3ca9..0000000000 --- a/clients/algoliasearch-client-go/algolia/analytics/utils.go +++ /dev/null @@ -1,385 +0,0 @@ -/* -Analytics API - -The Analytics API lets you review your search, and click and conversion analytics. > **Note**: The API key in the `X-Algolia-API-Key` header requires the [`analytics` ACL](https://www.algolia.com/doc/guides/security/api-keys/#access-control-list-acl). - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package analytics - -import ( - "encoding/json" - "reflect" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/errs" -) - -// PtrBool is a helper routine that returns a pointer to given boolean value. -func PtrBool(v bool) *bool { return &v } - -// PtrInt is a helper routine that returns a pointer to given integer value. -func PtrInt(v int) *int { return &v } - -// PtrInt32 is a helper routine that returns a pointer to given integer value. -func PtrInt32(v int32) *int32 { return &v } - -// PtrInt64 is a helper routine that returns a pointer to given integer value. -func PtrInt64(v int64) *int64 { return &v } - -// PtrFloat32 is a helper routine that returns a pointer to given float value. -func PtrFloat32(v float32) *float32 { return &v } - -// PtrFloat64 is a helper routine that returns a pointer to given float value. -func PtrFloat64(v float64) *float64 { return &v } - -// PtrString is a helper routine that returns a pointer to given string value. -func PtrString(v string) *string { return &v } - -// PtrTime is helper routine that returns a pointer to given Time value. -func PtrTime(v time.Time) *time.Time { return &v } - -type NullableBool struct { - value *bool - isSet bool -} - -func (v NullableBool) Get() *bool { - return v.value -} - -func (v *NullableBool) Set(val *bool) { - v.value = val - v.isSet = true -} - -func (v NullableBool) IsSet() bool { - return v.isSet -} - -func (v *NullableBool) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableBool(val *bool) *NullableBool { - return &NullableBool{value: val, isSet: true} -} - -func (v NullableBool) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableBool) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt struct { - value *int - isSet bool -} - -func (v NullableInt) Get() *int { - return v.value -} - -func (v *NullableInt) Set(val *int) { - v.value = val - v.isSet = true -} - -func (v NullableInt) IsSet() bool { - return v.isSet -} - -func (v *NullableInt) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt(val *int) *NullableInt { - return &NullableInt{value: val, isSet: true} -} - -func (v NullableInt) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt32 struct { - value *int32 - isSet bool -} - -func (v NullableInt32) Get() *int32 { - return v.value -} - -func (v *NullableInt32) Set(val *int32) { - v.value = val - v.isSet = true -} - -func (v NullableInt32) IsSet() bool { - return v.isSet -} - -func (v *NullableInt32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt32(val *int32) *NullableInt32 { - return &NullableInt32{value: val, isSet: true} -} - -func (v NullableInt32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt64 struct { - value *int64 - isSet bool -} - -func (v NullableInt64) Get() *int64 { - return v.value -} - -func (v *NullableInt64) Set(val *int64) { - v.value = val - v.isSet = true -} - -func (v NullableInt64) IsSet() bool { - return v.isSet -} - -func (v *NullableInt64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt64(val *int64) *NullableInt64 { - return &NullableInt64{value: val, isSet: true} -} - -func (v NullableInt64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat32 struct { - value *float32 - isSet bool -} - -func (v NullableFloat32) Get() *float32 { - return v.value -} - -func (v *NullableFloat32) Set(val *float32) { - v.value = val - v.isSet = true -} - -func (v NullableFloat32) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat32(val *float32) *NullableFloat32 { - return &NullableFloat32{value: val, isSet: true} -} - -func (v NullableFloat32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat64 struct { - value *float64 - isSet bool -} - -func (v NullableFloat64) Get() *float64 { - return v.value -} - -func (v *NullableFloat64) Set(val *float64) { - v.value = val - v.isSet = true -} - -func (v NullableFloat64) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat64(val *float64) *NullableFloat64 { - return &NullableFloat64{value: val, isSet: true} -} - -func (v NullableFloat64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableString struct { - value *string - isSet bool -} - -func (v NullableString) Get() *string { - return v.value -} - -func (v *NullableString) Set(val *string) { - v.value = val - v.isSet = true -} - -func (v NullableString) IsSet() bool { - return v.isSet -} - -func (v *NullableString) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableString(val *string) *NullableString { - return &NullableString{value: val, isSet: true} -} - -func (v NullableString) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableString) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableTime struct { - value *time.Time - isSet bool -} - -func (v NullableTime) Get() *time.Time { - return v.value -} - -func (v *NullableTime) Set(val *time.Time) { - v.value = val - v.isSet = true -} - -func (v NullableTime) IsSet() bool { - return v.isSet -} - -func (v *NullableTime) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableTime(val *time.Time) *NullableTime { - return &NullableTime{value: val, isSet: true} -} - -func (v NullableTime) MarshalJSON() ([]byte, error) { - return v.value.MarshalJSON() -} - -func (v *NullableTime) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// isNilorEmpty checks if an input is nil or empty -func isNilorEmpty(i any) bool { - if i == nil { - return true - } - switch reflect.TypeOf(i).Kind() { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: - return reflect.ValueOf(i).IsNil() - case reflect.Bool: - return false - default: - return reflect.ValueOf(i).IsZero() - } -} - -func RetryUntil[T any]( - retry func() (*T, error), - until func(*T, error) bool, - maxRetries *int, - initialDelay *time.Duration, - maxDelay *time.Duration, -) (*T, error) { - if maxRetries == nil { - maxRetries = new(int) - *maxRetries = 50 - } - - if initialDelay == nil { - initialDelay = new(time.Duration) - *initialDelay = 200 * time.Millisecond - } - - if maxDelay == nil { - maxDelay = new(time.Duration) - *maxDelay = 5 * time.Second - } - - for i := 0; i < *maxRetries; i++ { - res, err := retry() - - if ok := until(res, err); ok { - return res, nil - } - - time.Sleep(*initialDelay) - *initialDelay *= 2 - if *initialDelay > *maxDelay { - *initialDelay = *maxDelay - } - } - - return nil, &errs.WaitError{} -} diff --git a/clients/algoliasearch-client-go/algolia/ingestion/api_ingestion.go b/clients/algoliasearch-client-go/algolia/ingestion/api_ingestion.go index c7f1e02160..db218952a6 100644 --- a/clients/algoliasearch-client-go/algolia/ingestion/api_ingestion.go +++ b/clients/algoliasearch-client-go/algolia/ingestion/api_ingestion.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "github.com/algolia/algoliasearch-client-go/v4/algolia/call" + "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" ) type Option struct { @@ -105,8 +105,9 @@ func (c *APIClient) CreateAuthenticationWithContext(ctx context.Context, r ApiCr headers := make(map[string]string) queryParams := url.Values{} + if r.authenticationCreate == nil { - return returnValue, reportError("authenticationCreate is required and must be specified") + return returnValue, reportError("Parameter `authenticationCreate` is required when calling `CreateAuthentication`.") } // optional params if any @@ -126,7 +127,7 @@ func (c *APIClient) CreateAuthenticationWithContext(ctx context.Context, r ApiCr return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -235,8 +236,9 @@ func (c *APIClient) CreateDestinationWithContext(ctx context.Context, r ApiCreat headers := make(map[string]string) queryParams := url.Values{} + if r.destinationCreate == nil { - return returnValue, reportError("destinationCreate is required and must be specified") + return returnValue, reportError("Parameter `destinationCreate` is required when calling `CreateDestination`.") } // optional params if any @@ -256,7 +258,7 @@ func (c *APIClient) CreateDestinationWithContext(ctx context.Context, r ApiCreat return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -365,8 +367,9 @@ func (c *APIClient) CreateSourceWithContext(ctx context.Context, r ApiCreateSour headers := make(map[string]string) queryParams := url.Values{} + if r.sourceCreate == nil { - return returnValue, reportError("sourceCreate is required and must be specified") + return returnValue, reportError("Parameter `sourceCreate` is required when calling `CreateSource`.") } // optional params if any @@ -386,7 +389,7 @@ func (c *APIClient) CreateSourceWithContext(ctx context.Context, r ApiCreateSour return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -495,8 +498,9 @@ func (c *APIClient) CreateTaskWithContext(ctx context.Context, r ApiCreateTaskRe headers := make(map[string]string) queryParams := url.Values{} + if r.taskCreate == nil { - return returnValue, reportError("taskCreate is required and must be specified") + return returnValue, reportError("Parameter `taskCreate` is required when calling `CreateTask`.") } // optional params if any @@ -516,7 +520,7 @@ func (c *APIClient) CreateTaskWithContext(ctx context.Context, r ApiCreateTaskRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -635,12 +639,15 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomDelete`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -661,7 +668,7 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -780,12 +787,15 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomGet`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -806,7 +816,7 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -943,12 +953,15 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPost`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -965,7 +978,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -975,7 +988,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1112,12 +1125,15 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPut`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -1134,7 +1150,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -1144,7 +1160,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1245,10 +1261,13 @@ func (c *APIClient) DeleteAuthenticationWithContext(ctx context.Context, r ApiDe ) requestPath := "/1/authentications/{authenticationID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"authenticationID"+"}", url.PathEscape(parameterToString(r.authenticationID))) + requestPath = strings.ReplaceAll(requestPath, "{authenticationID}", url.PathEscape(parameterToString(r.authenticationID))) headers := make(map[string]string) queryParams := url.Values{} + if r.authenticationID == "" { + return returnValue, reportError("Parameter `authenticationID` is required when calling `DeleteAuthentication`.") + } // optional params if any for _, opt := range opts { @@ -1265,7 +1284,7 @@ func (c *APIClient) DeleteAuthenticationWithContext(ctx context.Context, r ApiDe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1366,10 +1385,13 @@ func (c *APIClient) DeleteDestinationWithContext(ctx context.Context, r ApiDelet ) requestPath := "/1/destinations/{destinationID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"destinationID"+"}", url.PathEscape(parameterToString(r.destinationID))) + requestPath = strings.ReplaceAll(requestPath, "{destinationID}", url.PathEscape(parameterToString(r.destinationID))) headers := make(map[string]string) queryParams := url.Values{} + if r.destinationID == "" { + return returnValue, reportError("Parameter `destinationID` is required when calling `DeleteDestination`.") + } // optional params if any for _, opt := range opts { @@ -1386,7 +1408,7 @@ func (c *APIClient) DeleteDestinationWithContext(ctx context.Context, r ApiDelet return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1487,10 +1509,13 @@ func (c *APIClient) DeleteSourceWithContext(ctx context.Context, r ApiDeleteSour ) requestPath := "/1/sources/{sourceID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"sourceID"+"}", url.PathEscape(parameterToString(r.sourceID))) + requestPath = strings.ReplaceAll(requestPath, "{sourceID}", url.PathEscape(parameterToString(r.sourceID))) headers := make(map[string]string) queryParams := url.Values{} + if r.sourceID == "" { + return returnValue, reportError("Parameter `sourceID` is required when calling `DeleteSource`.") + } // optional params if any for _, opt := range opts { @@ -1507,7 +1532,7 @@ func (c *APIClient) DeleteSourceWithContext(ctx context.Context, r ApiDeleteSour return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1608,10 +1633,13 @@ func (c *APIClient) DeleteTaskWithContext(ctx context.Context, r ApiDeleteTaskRe ) requestPath := "/1/tasks/{taskID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"taskID"+"}", url.PathEscape(parameterToString(r.taskID))) + requestPath = strings.ReplaceAll(requestPath, "{taskID}", url.PathEscape(parameterToString(r.taskID))) headers := make(map[string]string) queryParams := url.Values{} + if r.taskID == "" { + return returnValue, reportError("Parameter `taskID` is required when calling `DeleteTask`.") + } // optional params if any for _, opt := range opts { @@ -1628,7 +1656,7 @@ func (c *APIClient) DeleteTaskWithContext(ctx context.Context, r ApiDeleteTaskRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1729,10 +1757,13 @@ func (c *APIClient) DisableTaskWithContext(ctx context.Context, r ApiDisableTask ) requestPath := "/1/tasks/{taskID}/disable" - requestPath = strings.ReplaceAll(requestPath, "{"+"taskID"+"}", url.PathEscape(parameterToString(r.taskID))) + requestPath = strings.ReplaceAll(requestPath, "{taskID}", url.PathEscape(parameterToString(r.taskID))) headers := make(map[string]string) queryParams := url.Values{} + if r.taskID == "" { + return returnValue, reportError("Parameter `taskID` is required when calling `DisableTask`.") + } // optional params if any for _, opt := range opts { @@ -1749,7 +1780,7 @@ func (c *APIClient) DisableTaskWithContext(ctx context.Context, r ApiDisableTask return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1850,10 +1881,13 @@ func (c *APIClient) EnableTaskWithContext(ctx context.Context, r ApiEnableTaskRe ) requestPath := "/1/tasks/{taskID}/enable" - requestPath = strings.ReplaceAll(requestPath, "{"+"taskID"+"}", url.PathEscape(parameterToString(r.taskID))) + requestPath = strings.ReplaceAll(requestPath, "{taskID}", url.PathEscape(parameterToString(r.taskID))) headers := make(map[string]string) queryParams := url.Values{} + if r.taskID == "" { + return returnValue, reportError("Parameter `taskID` is required when calling `EnableTask`.") + } // optional params if any for _, opt := range opts { @@ -1870,7 +1904,7 @@ func (c *APIClient) EnableTaskWithContext(ctx context.Context, r ApiEnableTaskRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1971,10 +2005,13 @@ func (c *APIClient) GetAuthenticationWithContext(ctx context.Context, r ApiGetAu ) requestPath := "/1/authentications/{authenticationID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"authenticationID"+"}", url.PathEscape(parameterToString(r.authenticationID))) + requestPath = strings.ReplaceAll(requestPath, "{authenticationID}", url.PathEscape(parameterToString(r.authenticationID))) headers := make(map[string]string) queryParams := url.Values{} + if r.authenticationID == "" { + return returnValue, reportError("Parameter `authenticationID` is required when calling `GetAuthentication`.") + } // optional params if any for _, opt := range opts { @@ -1991,7 +2028,7 @@ func (c *APIClient) GetAuthenticationWithContext(ctx context.Context, r ApiGetAu return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2190,22 +2227,22 @@ func (c *APIClient) GetAuthenticationsWithContext(ctx context.Context, r ApiGetA headers := make(map[string]string) queryParams := url.Values{} - if !isNilorEmpty(r.itemsPerPage) { + if !utils.IsNilOrEmpty(r.itemsPerPage) { queryParams.Set("itemsPerPage", parameterToString(r.itemsPerPage)) } - if !isNilorEmpty(r.page) { + if !utils.IsNilOrEmpty(r.page) { queryParams.Set("page", parameterToString(r.page)) } - if !isNilorEmpty(r.type_) { + if !utils.IsNilOrEmpty(r.type_) { queryParams.Set("type", parameterToString(r.type_)) } - if !isNilorEmpty(r.platform) { + if !utils.IsNilOrEmpty(r.platform) { queryParams.Set("platform", parameterToString(r.platform)) } - if !isNilorEmpty(r.sort) { + if !utils.IsNilOrEmpty(r.sort) { queryParams.Set("sort", parameterToString(r.sort)) } - if !isNilorEmpty(r.order) { + if !utils.IsNilOrEmpty(r.order) { queryParams.Set("order", parameterToString(r.order)) } @@ -2224,7 +2261,7 @@ func (c *APIClient) GetAuthenticationsWithContext(ctx context.Context, r ApiGetA return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2325,10 +2362,13 @@ func (c *APIClient) GetDestinationWithContext(ctx context.Context, r ApiGetDesti ) requestPath := "/1/destinations/{destinationID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"destinationID"+"}", url.PathEscape(parameterToString(r.destinationID))) + requestPath = strings.ReplaceAll(requestPath, "{destinationID}", url.PathEscape(parameterToString(r.destinationID))) headers := make(map[string]string) queryParams := url.Values{} + if r.destinationID == "" { + return returnValue, reportError("Parameter `destinationID` is required when calling `GetDestination`.") + } // optional params if any for _, opt := range opts { @@ -2345,7 +2385,7 @@ func (c *APIClient) GetDestinationWithContext(ctx context.Context, r ApiGetDesti return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2544,22 +2584,22 @@ func (c *APIClient) GetDestinationsWithContext(ctx context.Context, r ApiGetDest headers := make(map[string]string) queryParams := url.Values{} - if !isNilorEmpty(r.itemsPerPage) { + if !utils.IsNilOrEmpty(r.itemsPerPage) { queryParams.Set("itemsPerPage", parameterToString(r.itemsPerPage)) } - if !isNilorEmpty(r.page) { + if !utils.IsNilOrEmpty(r.page) { queryParams.Set("page", parameterToString(r.page)) } - if !isNilorEmpty(r.type_) { + if !utils.IsNilOrEmpty(r.type_) { queryParams.Set("type", parameterToString(r.type_)) } - if !isNilorEmpty(r.authenticationID) { + if !utils.IsNilOrEmpty(r.authenticationID) { queryParams.Set("authenticationID", parameterToString(r.authenticationID)) } - if !isNilorEmpty(r.sort) { + if !utils.IsNilOrEmpty(r.sort) { queryParams.Set("sort", parameterToString(r.sort)) } - if !isNilorEmpty(r.order) { + if !utils.IsNilOrEmpty(r.order) { queryParams.Set("order", parameterToString(r.order)) } @@ -2578,7 +2618,7 @@ func (c *APIClient) GetDestinationsWithContext(ctx context.Context, r ApiGetDest return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2679,10 +2719,13 @@ func (c *APIClient) GetDockerSourceStreamsWithContext(ctx context.Context, r Api ) requestPath := "/1/sources/{sourceID}/discover" - requestPath = strings.ReplaceAll(requestPath, "{"+"sourceID"+"}", url.PathEscape(parameterToString(r.sourceID))) + requestPath = strings.ReplaceAll(requestPath, "{sourceID}", url.PathEscape(parameterToString(r.sourceID))) headers := make(map[string]string) queryParams := url.Values{} + if r.sourceID == "" { + return returnValue, reportError("Parameter `sourceID` is required when calling `GetDockerSourceStreams`.") + } // optional params if any for _, opt := range opts { @@ -2699,7 +2742,7 @@ func (c *APIClient) GetDockerSourceStreamsWithContext(ctx context.Context, r Api return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2813,11 +2856,17 @@ func (c *APIClient) GetEventWithContext(ctx context.Context, r ApiGetEventReques ) requestPath := "/1/runs/{runID}/events/{eventID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"runID"+"}", url.PathEscape(parameterToString(r.runID))) - requestPath = strings.ReplaceAll(requestPath, "{"+"eventID"+"}", url.PathEscape(parameterToString(r.eventID))) + requestPath = strings.ReplaceAll(requestPath, "{runID}", url.PathEscape(parameterToString(r.runID))) + requestPath = strings.ReplaceAll(requestPath, "{eventID}", url.PathEscape(parameterToString(r.eventID))) headers := make(map[string]string) queryParams := url.Values{} + if r.runID == "" { + return returnValue, reportError("Parameter `runID` is required when calling `GetEvent`.") + } + if r.eventID == "" { + return returnValue, reportError("Parameter `eventID` is required when calling `GetEvent`.") + } // optional params if any for _, opt := range opts { @@ -2834,7 +2883,7 @@ func (c *APIClient) GetEventWithContext(ctx context.Context, r ApiGetEventReques return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3079,33 +3128,36 @@ func (c *APIClient) GetEventsWithContext(ctx context.Context, r ApiGetEventsRequ ) requestPath := "/1/runs/{runID}/events" - requestPath = strings.ReplaceAll(requestPath, "{"+"runID"+"}", url.PathEscape(parameterToString(r.runID))) + requestPath = strings.ReplaceAll(requestPath, "{runID}", url.PathEscape(parameterToString(r.runID))) headers := make(map[string]string) queryParams := url.Values{} + if r.runID == "" { + return returnValue, reportError("Parameter `runID` is required when calling `GetEvents`.") + } - if !isNilorEmpty(r.itemsPerPage) { + if !utils.IsNilOrEmpty(r.itemsPerPage) { queryParams.Set("itemsPerPage", parameterToString(r.itemsPerPage)) } - if !isNilorEmpty(r.page) { + if !utils.IsNilOrEmpty(r.page) { queryParams.Set("page", parameterToString(r.page)) } - if !isNilorEmpty(r.status) { + if !utils.IsNilOrEmpty(r.status) { queryParams.Set("status", parameterToString(r.status)) } - if !isNilorEmpty(r.type_) { + if !utils.IsNilOrEmpty(r.type_) { queryParams.Set("type", parameterToString(r.type_)) } - if !isNilorEmpty(r.sort) { + if !utils.IsNilOrEmpty(r.sort) { queryParams.Set("sort", parameterToString(r.sort)) } - if !isNilorEmpty(r.order) { + if !utils.IsNilOrEmpty(r.order) { queryParams.Set("order", parameterToString(r.order)) } - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } @@ -3124,7 +3176,7 @@ func (c *APIClient) GetEventsWithContext(ctx context.Context, r ApiGetEventsRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3225,10 +3277,13 @@ func (c *APIClient) GetRunWithContext(ctx context.Context, r ApiGetRunRequest, o ) requestPath := "/1/runs/{runID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"runID"+"}", url.PathEscape(parameterToString(r.runID))) + requestPath = strings.ReplaceAll(requestPath, "{runID}", url.PathEscape(parameterToString(r.runID))) headers := make(map[string]string) queryParams := url.Values{} + if r.runID == "" { + return returnValue, reportError("Parameter `runID` is required when calling `GetRun`.") + } // optional params if any for _, opt := range opts { @@ -3245,7 +3300,7 @@ func (c *APIClient) GetRunWithContext(ctx context.Context, r ApiGetRunRequest, o return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3480,28 +3535,28 @@ func (c *APIClient) GetRunsWithContext(ctx context.Context, r ApiGetRunsRequest, headers := make(map[string]string) queryParams := url.Values{} - if !isNilorEmpty(r.itemsPerPage) { + if !utils.IsNilOrEmpty(r.itemsPerPage) { queryParams.Set("itemsPerPage", parameterToString(r.itemsPerPage)) } - if !isNilorEmpty(r.page) { + if !utils.IsNilOrEmpty(r.page) { queryParams.Set("page", parameterToString(r.page)) } - if !isNilorEmpty(r.status) { + if !utils.IsNilOrEmpty(r.status) { queryParams.Set("status", parameterToString(r.status)) } - if !isNilorEmpty(r.taskID) { + if !utils.IsNilOrEmpty(r.taskID) { queryParams.Set("taskID", parameterToString(r.taskID)) } - if !isNilorEmpty(r.sort) { + if !utils.IsNilOrEmpty(r.sort) { queryParams.Set("sort", parameterToString(r.sort)) } - if !isNilorEmpty(r.order) { + if !utils.IsNilOrEmpty(r.order) { queryParams.Set("order", parameterToString(r.order)) } - if !isNilorEmpty(r.startDate) { + if !utils.IsNilOrEmpty(r.startDate) { queryParams.Set("startDate", parameterToString(r.startDate)) } - if !isNilorEmpty(r.endDate) { + if !utils.IsNilOrEmpty(r.endDate) { queryParams.Set("endDate", parameterToString(r.endDate)) } @@ -3520,7 +3575,7 @@ func (c *APIClient) GetRunsWithContext(ctx context.Context, r ApiGetRunsRequest, return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3621,10 +3676,13 @@ func (c *APIClient) GetSourceWithContext(ctx context.Context, r ApiGetSourceRequ ) requestPath := "/1/sources/{sourceID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"sourceID"+"}", url.PathEscape(parameterToString(r.sourceID))) + requestPath = strings.ReplaceAll(requestPath, "{sourceID}", url.PathEscape(parameterToString(r.sourceID))) headers := make(map[string]string) queryParams := url.Values{} + if r.sourceID == "" { + return returnValue, reportError("Parameter `sourceID` is required when calling `GetSource`.") + } // optional params if any for _, opt := range opts { @@ -3641,7 +3699,7 @@ func (c *APIClient) GetSourceWithContext(ctx context.Context, r ApiGetSourceRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3840,22 +3898,22 @@ func (c *APIClient) GetSourcesWithContext(ctx context.Context, r ApiGetSourcesRe headers := make(map[string]string) queryParams := url.Values{} - if !isNilorEmpty(r.itemsPerPage) { + if !utils.IsNilOrEmpty(r.itemsPerPage) { queryParams.Set("itemsPerPage", parameterToString(r.itemsPerPage)) } - if !isNilorEmpty(r.page) { + if !utils.IsNilOrEmpty(r.page) { queryParams.Set("page", parameterToString(r.page)) } - if !isNilorEmpty(r.type_) { + if !utils.IsNilOrEmpty(r.type_) { queryParams.Set("type", parameterToString(r.type_)) } - if !isNilorEmpty(r.authenticationID) { + if !utils.IsNilOrEmpty(r.authenticationID) { queryParams.Set("authenticationID", parameterToString(r.authenticationID)) } - if !isNilorEmpty(r.sort) { + if !utils.IsNilOrEmpty(r.sort) { queryParams.Set("sort", parameterToString(r.sort)) } - if !isNilorEmpty(r.order) { + if !utils.IsNilOrEmpty(r.order) { queryParams.Set("order", parameterToString(r.order)) } @@ -3874,7 +3932,7 @@ func (c *APIClient) GetSourcesWithContext(ctx context.Context, r ApiGetSourcesRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3975,10 +4033,13 @@ func (c *APIClient) GetTaskWithContext(ctx context.Context, r ApiGetTaskRequest, ) requestPath := "/1/tasks/{taskID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"taskID"+"}", url.PathEscape(parameterToString(r.taskID))) + requestPath = strings.ReplaceAll(requestPath, "{taskID}", url.PathEscape(parameterToString(r.taskID))) headers := make(map[string]string) queryParams := url.Values{} + if r.taskID == "" { + return returnValue, reportError("Parameter `taskID` is required when calling `GetTask`.") + } // optional params if any for _, opt := range opts { @@ -3995,7 +4056,7 @@ func (c *APIClient) GetTaskWithContext(ctx context.Context, r ApiGetTaskRequest, return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4248,31 +4309,31 @@ func (c *APIClient) GetTasksWithContext(ctx context.Context, r ApiGetTasksReques headers := make(map[string]string) queryParams := url.Values{} - if !isNilorEmpty(r.itemsPerPage) { + if !utils.IsNilOrEmpty(r.itemsPerPage) { queryParams.Set("itemsPerPage", parameterToString(r.itemsPerPage)) } - if !isNilorEmpty(r.page) { + if !utils.IsNilOrEmpty(r.page) { queryParams.Set("page", parameterToString(r.page)) } - if !isNilorEmpty(r.action) { + if !utils.IsNilOrEmpty(r.action) { queryParams.Set("action", parameterToString(r.action)) } - if !isNilorEmpty(r.enabled) { + if !utils.IsNilOrEmpty(r.enabled) { queryParams.Set("enabled", parameterToString(r.enabled)) } - if !isNilorEmpty(r.sourceID) { + if !utils.IsNilOrEmpty(r.sourceID) { queryParams.Set("sourceID", parameterToString(r.sourceID)) } - if !isNilorEmpty(r.destinationID) { + if !utils.IsNilOrEmpty(r.destinationID) { queryParams.Set("destinationID", parameterToString(r.destinationID)) } - if !isNilorEmpty(r.triggerType) { + if !utils.IsNilOrEmpty(r.triggerType) { queryParams.Set("triggerType", parameterToString(r.triggerType)) } - if !isNilorEmpty(r.sort) { + if !utils.IsNilOrEmpty(r.sort) { queryParams.Set("sort", parameterToString(r.sort)) } - if !isNilorEmpty(r.order) { + if !utils.IsNilOrEmpty(r.order) { queryParams.Set("order", parameterToString(r.order)) } @@ -4291,7 +4352,7 @@ func (c *APIClient) GetTasksWithContext(ctx context.Context, r ApiGetTasksReques return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4392,10 +4453,13 @@ func (c *APIClient) RunTaskWithContext(ctx context.Context, r ApiRunTaskRequest, ) requestPath := "/1/tasks/{taskID}/run" - requestPath = strings.ReplaceAll(requestPath, "{"+"taskID"+"}", url.PathEscape(parameterToString(r.taskID))) + requestPath = strings.ReplaceAll(requestPath, "{taskID}", url.PathEscape(parameterToString(r.taskID))) headers := make(map[string]string) queryParams := url.Values{} + if r.taskID == "" { + return returnValue, reportError("Parameter `taskID` is required when calling `RunTask`.") + } // optional params if any for _, opt := range opts { @@ -4412,7 +4476,7 @@ func (c *APIClient) RunTaskWithContext(ctx context.Context, r ApiRunTaskRequest, return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4521,8 +4585,9 @@ func (c *APIClient) SearchAuthenticationsWithContext(ctx context.Context, r ApiS headers := make(map[string]string) queryParams := url.Values{} + if r.authenticationSearch == nil { - return returnValue, reportError("authenticationSearch is required and must be specified") + return returnValue, reportError("Parameter `authenticationSearch` is required when calling `SearchAuthentications`.") } // optional params if any @@ -4542,7 +4607,7 @@ func (c *APIClient) SearchAuthenticationsWithContext(ctx context.Context, r ApiS return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4651,8 +4716,9 @@ func (c *APIClient) SearchDestinationsWithContext(ctx context.Context, r ApiSear headers := make(map[string]string) queryParams := url.Values{} + if r.destinationSearch == nil { - return returnValue, reportError("destinationSearch is required and must be specified") + return returnValue, reportError("Parameter `destinationSearch` is required when calling `SearchDestinations`.") } // optional params if any @@ -4672,7 +4738,7 @@ func (c *APIClient) SearchDestinationsWithContext(ctx context.Context, r ApiSear return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4781,8 +4847,9 @@ func (c *APIClient) SearchSourcesWithContext(ctx context.Context, r ApiSearchSou headers := make(map[string]string) queryParams := url.Values{} + if r.sourceSearch == nil { - return returnValue, reportError("sourceSearch is required and must be specified") + return returnValue, reportError("Parameter `sourceSearch` is required when calling `SearchSources`.") } // optional params if any @@ -4802,7 +4869,7 @@ func (c *APIClient) SearchSourcesWithContext(ctx context.Context, r ApiSearchSou return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4911,8 +4978,9 @@ func (c *APIClient) SearchTasksWithContext(ctx context.Context, r ApiSearchTasks headers := make(map[string]string) queryParams := url.Values{} + if r.taskSearch == nil { - return returnValue, reportError("taskSearch is required and must be specified") + return returnValue, reportError("Parameter `taskSearch` is required when calling `SearchTasks`.") } // optional params if any @@ -4932,7 +5000,7 @@ func (c *APIClient) SearchTasksWithContext(ctx context.Context, r ApiSearchTasks return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5033,10 +5101,13 @@ func (c *APIClient) TriggerDockerSourceDiscoverWithContext(ctx context.Context, ) requestPath := "/1/sources/{sourceID}/discover" - requestPath = strings.ReplaceAll(requestPath, "{"+"sourceID"+"}", url.PathEscape(parameterToString(r.sourceID))) + requestPath = strings.ReplaceAll(requestPath, "{sourceID}", url.PathEscape(parameterToString(r.sourceID))) headers := make(map[string]string) queryParams := url.Values{} + if r.sourceID == "" { + return returnValue, reportError("Parameter `sourceID` is required when calling `TriggerDockerSourceDiscover`.") + } // optional params if any for _, opt := range opts { @@ -5053,7 +5124,7 @@ func (c *APIClient) TriggerDockerSourceDiscoverWithContext(ctx context.Context, return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5172,12 +5243,16 @@ func (c *APIClient) UpdateAuthenticationWithContext(ctx context.Context, r ApiUp ) requestPath := "/1/authentications/{authenticationID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"authenticationID"+"}", url.PathEscape(parameterToString(r.authenticationID))) + requestPath = strings.ReplaceAll(requestPath, "{authenticationID}", url.PathEscape(parameterToString(r.authenticationID))) headers := make(map[string]string) queryParams := url.Values{} + if r.authenticationID == "" { + return returnValue, reportError("Parameter `authenticationID` is required when calling `UpdateAuthentication`.") + } + if r.authenticationUpdate == nil { - return returnValue, reportError("authenticationUpdate is required and must be specified") + return returnValue, reportError("Parameter `authenticationUpdate` is required when calling `UpdateAuthentication`.") } // optional params if any @@ -5197,7 +5272,7 @@ func (c *APIClient) UpdateAuthenticationWithContext(ctx context.Context, r ApiUp return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5316,12 +5391,16 @@ func (c *APIClient) UpdateDestinationWithContext(ctx context.Context, r ApiUpdat ) requestPath := "/1/destinations/{destinationID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"destinationID"+"}", url.PathEscape(parameterToString(r.destinationID))) + requestPath = strings.ReplaceAll(requestPath, "{destinationID}", url.PathEscape(parameterToString(r.destinationID))) headers := make(map[string]string) queryParams := url.Values{} + if r.destinationID == "" { + return returnValue, reportError("Parameter `destinationID` is required when calling `UpdateDestination`.") + } + if r.destinationUpdate == nil { - return returnValue, reportError("destinationUpdate is required and must be specified") + return returnValue, reportError("Parameter `destinationUpdate` is required when calling `UpdateDestination`.") } // optional params if any @@ -5341,7 +5420,7 @@ func (c *APIClient) UpdateDestinationWithContext(ctx context.Context, r ApiUpdat return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5460,12 +5539,16 @@ func (c *APIClient) UpdateSourceWithContext(ctx context.Context, r ApiUpdateSour ) requestPath := "/1/sources/{sourceID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"sourceID"+"}", url.PathEscape(parameterToString(r.sourceID))) + requestPath = strings.ReplaceAll(requestPath, "{sourceID}", url.PathEscape(parameterToString(r.sourceID))) headers := make(map[string]string) queryParams := url.Values{} + if r.sourceID == "" { + return returnValue, reportError("Parameter `sourceID` is required when calling `UpdateSource`.") + } + if r.sourceUpdate == nil { - return returnValue, reportError("sourceUpdate is required and must be specified") + return returnValue, reportError("Parameter `sourceUpdate` is required when calling `UpdateSource`.") } // optional params if any @@ -5485,7 +5568,7 @@ func (c *APIClient) UpdateSourceWithContext(ctx context.Context, r ApiUpdateSour return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5604,12 +5687,16 @@ func (c *APIClient) UpdateTaskWithContext(ctx context.Context, r ApiUpdateTaskRe ) requestPath := "/1/tasks/{taskID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"taskID"+"}", url.PathEscape(parameterToString(r.taskID))) + requestPath = strings.ReplaceAll(requestPath, "{taskID}", url.PathEscape(parameterToString(r.taskID))) headers := make(map[string]string) queryParams := url.Values{} + if r.taskID == "" { + return returnValue, reportError("Parameter `taskID` is required when calling `UpdateTask`.") + } + if r.taskUpdate == nil { - return returnValue, reportError("taskUpdate is required and must be specified") + return returnValue, reportError("Parameter `taskUpdate` is required when calling `UpdateTask`.") } // optional params if any @@ -5629,7 +5716,7 @@ func (c *APIClient) UpdateTaskWithContext(ctx context.Context, r ApiUpdateTaskRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } diff --git a/clients/algoliasearch-client-go/algolia/ingestion/client.go b/clients/algoliasearch-client-go/algolia/ingestion/client.go index 5381a42817..bf976c9175 100644 --- a/clients/algoliasearch-client-go/algolia/ingestion/client.go +++ b/clients/algoliasearch-client-go/algolia/ingestion/client.go @@ -16,6 +16,7 @@ import ( "reflect" "regexp" "runtime" + "slices" "strings" "time" @@ -23,7 +24,7 @@ import ( "github.com/algolia/algoliasearch-client-go/v4/algolia/call" "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/transport" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) var jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) @@ -37,31 +38,33 @@ type APIClient struct { } // NewClient creates a new API client with appID, apiKey and region. -func NewClient(appID, apiKey string, region Region) *APIClient { +func NewClient(appID, apiKey string, region Region) (*APIClient, error) { return NewClientWithConfig(Configuration{ - AppID: appID, - ApiKey: apiKey, - Region: region, - DefaultHeader: make(map[string]string), - UserAgent: getUserAgent(), - Debug: false, - Requester: newDefaultRequester(), + Configuration: transport.Configuration{ + AppID: appID, + ApiKey: apiKey, + DefaultHeader: make(map[string]string), + UserAgent: getUserAgent(), + Debug: false, + Requester: transport.NewDefaultRequester(nil), + }, + Region: region, }) } // NewClientWithConfig creates a new API client with the given configuration to fully customize the client behaviour. -func NewClientWithConfig(cfg Configuration) *APIClient { +func NewClientWithConfig(cfg Configuration) (*APIClient, error) { var hosts []*transport.StatefulHost if cfg.AppID == "" { - panic("appID is required") + return nil, errors.New("`appId` is missing.") } if cfg.ApiKey == "" { - panic("apiKey is required") + return nil, errors.New("`apiKey` is missing.") } if len(cfg.Hosts) == 0 { - if cfg.Region == "" { - panic("region is required") + if cfg.Region == "" || (cfg.Region != "" && !slices.Contains(allowedRegions[:], string(cfg.Region))) { + return nil, fmt.Errorf("`region` is required and must be one of the following: %s", strings.Join(allowedRegions[:], ", ")) } hosts = getDefaultHosts(cfg.Region) } else { @@ -70,7 +73,7 @@ func NewClientWithConfig(cfg Configuration) *APIClient { } } if cfg.Requester == nil { - cfg.Requester = newDefaultRequester() + cfg.Requester = transport.NewDefaultRequester(&cfg.ConnectTimeout) } if cfg.UserAgent == "" { cfg.UserAgent = getUserAgent() @@ -84,18 +87,14 @@ func NewClientWithConfig(cfg Configuration) *APIClient { cfg.Requester, cfg.ReadTimeout, cfg.WriteTimeout, + cfg.ConnectTimeout, cfg.Compression, ), - } + }, nil } func getDefaultHosts(r Region) []*transport.StatefulHost { - hosts := []*transport.StatefulHost{} - switch r { - case EU, US: - hosts = append(hosts, transport.NewStatefulHost(strings.ReplaceAll("data.{region}.algolia.com", "{region}", string(r)), call.IsReadWrite)) - } - return hosts + return []*transport.StatefulHost{transport.NewStatefulHost(strings.ReplaceAll("data.{region}.algolia.com", "{region}", string(r)), call.IsReadWrite)} } func getUserAgent() string { @@ -119,7 +118,7 @@ func (c *APIClient) AddDefaultHeader(key string, value string) { } // callAPI do the request. -func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Response, error) { +func (c *APIClient) callAPI(request *http.Request, useReadTransporter bool) (*http.Response, error) { if c.cfg.Debug { dump, err := httputil.DumpRequestOut(request, true) if err != nil { @@ -128,7 +127,12 @@ func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Respon log.Printf("\n%s\n", string(dump)) } - resp, err := c.transport.Request(request.Context(), request, kind) + callKind := call.Write + if useReadTransporter || request.Method == http.MethodGet { + callKind = call.Read + } + + resp, err := c.transport.Request(request.Context(), request, callKind) if err != nil { return nil, err } diff --git a/clients/algoliasearch-client-go/algolia/ingestion/configuration.go b/clients/algoliasearch-client-go/algolia/ingestion/configuration.go index adf9660c80..9ebaf7980e 100644 --- a/clients/algoliasearch-client-go/algolia/ingestion/configuration.go +++ b/clients/algoliasearch-client-go/algolia/ingestion/configuration.go @@ -2,29 +2,10 @@ package ingestion import ( - "net/http" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -type Requester interface { - Request(*http.Request) (*http.Response, error) -} - -type defaultRequester struct { - client *http.Client -} - -func newDefaultRequester() *defaultRequester { - return &defaultRequester{ - client: http.DefaultClient, - } -} - -func (r *defaultRequester) Request(req *http.Request) (*http.Response, error) { - return r.client.Do(req) -} +var allowedRegions = [...]string{"eu", "us"} type Region string @@ -35,16 +16,7 @@ const ( // Configuration stores the configuration of the API client. type Configuration struct { - AppID string - ApiKey string - Region Region + transport.Configuration - Hosts []string `json:"host,omitempty"` - DefaultHeader map[string]string `json:"defaultHeader,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Debug bool `json:"debug,omitempty"` - Requester Requester - ReadTimeout time.Duration - WriteTimeout time.Duration - Compression compression.Compression + Region Region } diff --git a/clients/algoliasearch-client-go/algolia/ingestion/response.go b/clients/algoliasearch-client-go/algolia/ingestion/response.go deleted file mode 100644 index 402727ab49..0000000000 --- a/clients/algoliasearch-client-go/algolia/ingestion/response.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Ingestion API - -API powering the Data Ingestion connectors of Algolia. - -API version: 1.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package ingestion - -import ( - "net/http" -) - -// APIResponse stores the API response returned by the server. -type APIResponse struct { - *http.Response `json:"-"` - Message string `json:"message,omitempty"` - // Operation is the name of the OpenAPI operation. - Operation string `json:"operation,omitempty"` - // RequestURL is the request URL. This value is always available, even if the - // embedded *http.Response is nil. - RequestURL string `json:"url,omitempty"` - // Method is the HTTP method used for the request. This value is always - // available, even if the embedded *http.Response is nil. - Method string `json:"method,omitempty"` - // Payload holds the contents of the response body (which may be nil or empty). - // This is provided here as the raw response.Body() reader will have already - // been drained. - Payload []byte `json:"-"` -} - -// NewAPIResponse returns a new APIResponse object. -func NewAPIResponse(r *http.Response) *APIResponse { - - response := &APIResponse{Response: r} - return response -} - -// NewAPIResponseWithError returns a new APIResponse object with the provided error message. -func NewAPIResponseWithError(errorMessage string) *APIResponse { - - response := &APIResponse{Message: errorMessage} - return response -} diff --git a/clients/algoliasearch-client-go/algolia/ingestion/utils.go b/clients/algoliasearch-client-go/algolia/ingestion/utils.go deleted file mode 100644 index f87fdd7041..0000000000 --- a/clients/algoliasearch-client-go/algolia/ingestion/utils.go +++ /dev/null @@ -1,385 +0,0 @@ -/* -Ingestion API - -API powering the Data Ingestion connectors of Algolia. - -API version: 1.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package ingestion - -import ( - "encoding/json" - "reflect" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/errs" -) - -// PtrBool is a helper routine that returns a pointer to given boolean value. -func PtrBool(v bool) *bool { return &v } - -// PtrInt is a helper routine that returns a pointer to given integer value. -func PtrInt(v int) *int { return &v } - -// PtrInt32 is a helper routine that returns a pointer to given integer value. -func PtrInt32(v int32) *int32 { return &v } - -// PtrInt64 is a helper routine that returns a pointer to given integer value. -func PtrInt64(v int64) *int64 { return &v } - -// PtrFloat32 is a helper routine that returns a pointer to given float value. -func PtrFloat32(v float32) *float32 { return &v } - -// PtrFloat64 is a helper routine that returns a pointer to given float value. -func PtrFloat64(v float64) *float64 { return &v } - -// PtrString is a helper routine that returns a pointer to given string value. -func PtrString(v string) *string { return &v } - -// PtrTime is helper routine that returns a pointer to given Time value. -func PtrTime(v time.Time) *time.Time { return &v } - -type NullableBool struct { - value *bool - isSet bool -} - -func (v NullableBool) Get() *bool { - return v.value -} - -func (v *NullableBool) Set(val *bool) { - v.value = val - v.isSet = true -} - -func (v NullableBool) IsSet() bool { - return v.isSet -} - -func (v *NullableBool) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableBool(val *bool) *NullableBool { - return &NullableBool{value: val, isSet: true} -} - -func (v NullableBool) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableBool) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt struct { - value *int - isSet bool -} - -func (v NullableInt) Get() *int { - return v.value -} - -func (v *NullableInt) Set(val *int) { - v.value = val - v.isSet = true -} - -func (v NullableInt) IsSet() bool { - return v.isSet -} - -func (v *NullableInt) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt(val *int) *NullableInt { - return &NullableInt{value: val, isSet: true} -} - -func (v NullableInt) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt32 struct { - value *int32 - isSet bool -} - -func (v NullableInt32) Get() *int32 { - return v.value -} - -func (v *NullableInt32) Set(val *int32) { - v.value = val - v.isSet = true -} - -func (v NullableInt32) IsSet() bool { - return v.isSet -} - -func (v *NullableInt32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt32(val *int32) *NullableInt32 { - return &NullableInt32{value: val, isSet: true} -} - -func (v NullableInt32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt64 struct { - value *int64 - isSet bool -} - -func (v NullableInt64) Get() *int64 { - return v.value -} - -func (v *NullableInt64) Set(val *int64) { - v.value = val - v.isSet = true -} - -func (v NullableInt64) IsSet() bool { - return v.isSet -} - -func (v *NullableInt64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt64(val *int64) *NullableInt64 { - return &NullableInt64{value: val, isSet: true} -} - -func (v NullableInt64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat32 struct { - value *float32 - isSet bool -} - -func (v NullableFloat32) Get() *float32 { - return v.value -} - -func (v *NullableFloat32) Set(val *float32) { - v.value = val - v.isSet = true -} - -func (v NullableFloat32) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat32(val *float32) *NullableFloat32 { - return &NullableFloat32{value: val, isSet: true} -} - -func (v NullableFloat32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat64 struct { - value *float64 - isSet bool -} - -func (v NullableFloat64) Get() *float64 { - return v.value -} - -func (v *NullableFloat64) Set(val *float64) { - v.value = val - v.isSet = true -} - -func (v NullableFloat64) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat64(val *float64) *NullableFloat64 { - return &NullableFloat64{value: val, isSet: true} -} - -func (v NullableFloat64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableString struct { - value *string - isSet bool -} - -func (v NullableString) Get() *string { - return v.value -} - -func (v *NullableString) Set(val *string) { - v.value = val - v.isSet = true -} - -func (v NullableString) IsSet() bool { - return v.isSet -} - -func (v *NullableString) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableString(val *string) *NullableString { - return &NullableString{value: val, isSet: true} -} - -func (v NullableString) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableString) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableTime struct { - value *time.Time - isSet bool -} - -func (v NullableTime) Get() *time.Time { - return v.value -} - -func (v *NullableTime) Set(val *time.Time) { - v.value = val - v.isSet = true -} - -func (v NullableTime) IsSet() bool { - return v.isSet -} - -func (v *NullableTime) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableTime(val *time.Time) *NullableTime { - return &NullableTime{value: val, isSet: true} -} - -func (v NullableTime) MarshalJSON() ([]byte, error) { - return v.value.MarshalJSON() -} - -func (v *NullableTime) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// isNilorEmpty checks if an input is nil or empty -func isNilorEmpty(i any) bool { - if i == nil { - return true - } - switch reflect.TypeOf(i).Kind() { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: - return reflect.ValueOf(i).IsNil() - case reflect.Bool: - return false - default: - return reflect.ValueOf(i).IsZero() - } -} - -func RetryUntil[T any]( - retry func() (*T, error), - until func(*T, error) bool, - maxRetries *int, - initialDelay *time.Duration, - maxDelay *time.Duration, -) (*T, error) { - if maxRetries == nil { - maxRetries = new(int) - *maxRetries = 50 - } - - if initialDelay == nil { - initialDelay = new(time.Duration) - *initialDelay = 200 * time.Millisecond - } - - if maxDelay == nil { - maxDelay = new(time.Duration) - *maxDelay = 5 * time.Second - } - - for i := 0; i < *maxRetries; i++ { - res, err := retry() - - if ok := until(res, err); ok { - return res, nil - } - - time.Sleep(*initialDelay) - *initialDelay *= 2 - if *initialDelay > *maxDelay { - *initialDelay = *maxDelay - } - } - - return nil, &errs.WaitError{} -} diff --git a/clients/algoliasearch-client-go/algolia/insights/api_insights.go b/clients/algoliasearch-client-go/algolia/insights/api_insights.go index 6ebfbc692e..77c0b84d3c 100644 --- a/clients/algoliasearch-client-go/algolia/insights/api_insights.go +++ b/clients/algoliasearch-client-go/algolia/insights/api_insights.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "github.com/algolia/algoliasearch-client-go/v4/algolia/call" + "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" ) type Option struct { @@ -115,12 +115,15 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomDelete`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -141,7 +144,7 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -260,12 +263,15 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomGet`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -286,7 +292,7 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -423,12 +429,15 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPost`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -445,7 +454,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -455,7 +464,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -592,12 +601,15 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPut`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -614,7 +626,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -624,7 +636,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -722,10 +734,13 @@ func (c *APIClient) DeleteUserTokenWithContext(ctx context.Context, r ApiDeleteU var postBody any requestPath := "/1/usertokens/{userToken}" - requestPath = strings.ReplaceAll(requestPath, "{"+"userToken"+"}", url.PathEscape(parameterToString(r.userToken))) + requestPath = strings.ReplaceAll(requestPath, "{userToken}", url.PathEscape(parameterToString(r.userToken))) headers := make(map[string]string) queryParams := url.Values{} + if r.userToken == "" { + return reportError("Parameter `userToken` is required when calling `DeleteUserToken`.") + } if len(r.userToken) < 1 { return reportError("userToken must have at least 1 elements") } @@ -748,7 +763,7 @@ func (c *APIClient) DeleteUserTokenWithContext(ctx context.Context, r ApiDeleteU return err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return err } @@ -858,8 +873,9 @@ func (c *APIClient) PushEventsWithContext(ctx context.Context, r ApiPushEventsRe headers := make(map[string]string) queryParams := url.Values{} + if r.insightsEvents == nil { - return returnValue, reportError("insightsEvents is required and must be specified") + return returnValue, reportError("Parameter `insightsEvents` is required when calling `PushEvents`.") } // optional params if any @@ -879,7 +895,7 @@ func (c *APIClient) PushEventsWithContext(ctx context.Context, r ApiPushEventsRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } diff --git a/clients/algoliasearch-client-go/algolia/insights/client.go b/clients/algoliasearch-client-go/algolia/insights/client.go index 83cf7591b4..58b684bd93 100644 --- a/clients/algoliasearch-client-go/algolia/insights/client.go +++ b/clients/algoliasearch-client-go/algolia/insights/client.go @@ -16,6 +16,7 @@ import ( "reflect" "regexp" "runtime" + "slices" "strings" "time" @@ -23,7 +24,7 @@ import ( "github.com/algolia/algoliasearch-client-go/v4/algolia/call" "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/transport" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) var jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) @@ -37,31 +38,33 @@ type APIClient struct { } // NewClient creates a new API client with appID, apiKey and region. -func NewClient(appID, apiKey string, region Region) *APIClient { +func NewClient(appID, apiKey string, region Region) (*APIClient, error) { return NewClientWithConfig(Configuration{ - AppID: appID, - ApiKey: apiKey, - Region: region, - DefaultHeader: make(map[string]string), - UserAgent: getUserAgent(), - Debug: false, - Requester: newDefaultRequester(), + Configuration: transport.Configuration{ + AppID: appID, + ApiKey: apiKey, + DefaultHeader: make(map[string]string), + UserAgent: getUserAgent(), + Debug: false, + Requester: transport.NewDefaultRequester(nil), + }, + Region: region, }) } // NewClientWithConfig creates a new API client with the given configuration to fully customize the client behaviour. -func NewClientWithConfig(cfg Configuration) *APIClient { +func NewClientWithConfig(cfg Configuration) (*APIClient, error) { var hosts []*transport.StatefulHost if cfg.AppID == "" { - panic("appID is required") + return nil, errors.New("`appId` is missing.") } if cfg.ApiKey == "" { - panic("apiKey is required") + return nil, errors.New("`apiKey` is missing.") } if len(cfg.Hosts) == 0 { - if cfg.Region == "" { - panic("region is required") + if cfg.Region != "" && !slices.Contains(allowedRegions[:], string(cfg.Region)) { + return nil, fmt.Errorf("`region` must be one of the following: %s", strings.Join(allowedRegions[:], ", ")) } hosts = getDefaultHosts(cfg.Region) } else { @@ -70,7 +73,7 @@ func NewClientWithConfig(cfg Configuration) *APIClient { } } if cfg.Requester == nil { - cfg.Requester = newDefaultRequester() + cfg.Requester = transport.NewDefaultRequester(&cfg.ConnectTimeout) } if cfg.UserAgent == "" { cfg.UserAgent = getUserAgent() @@ -84,20 +87,18 @@ func NewClientWithConfig(cfg Configuration) *APIClient { cfg.Requester, cfg.ReadTimeout, cfg.WriteTimeout, + cfg.ConnectTimeout, cfg.Compression, ), - } + }, nil } func getDefaultHosts(r Region) []*transport.StatefulHost { - hosts := []*transport.StatefulHost{} - switch r { - case DE, US: - hosts = append(hosts, transport.NewStatefulHost(strings.ReplaceAll("insights.{region}.algolia.io", "{region}", string(r)), call.IsReadWrite)) - default: - hosts = append(hosts, transport.NewStatefulHost("insights.algolia.io", call.IsReadWrite)) + if r == "" { + return []*transport.StatefulHost{transport.NewStatefulHost("insights.algolia.io", call.IsReadWrite)} } - return hosts + + return []*transport.StatefulHost{transport.NewStatefulHost(strings.ReplaceAll("insights.{region}.algolia.io", "{region}", string(r)), call.IsReadWrite)} } func getUserAgent() string { @@ -121,7 +122,7 @@ func (c *APIClient) AddDefaultHeader(key string, value string) { } // callAPI do the request. -func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Response, error) { +func (c *APIClient) callAPI(request *http.Request, useReadTransporter bool) (*http.Response, error) { if c.cfg.Debug { dump, err := httputil.DumpRequestOut(request, true) if err != nil { @@ -130,7 +131,12 @@ func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Respon log.Printf("\n%s\n", string(dump)) } - resp, err := c.transport.Request(request.Context(), request, kind) + callKind := call.Write + if useReadTransporter || request.Method == http.MethodGet { + callKind = call.Read + } + + resp, err := c.transport.Request(request.Context(), request, callKind) if err != nil { return nil, err } diff --git a/clients/algoliasearch-client-go/algolia/insights/configuration.go b/clients/algoliasearch-client-go/algolia/insights/configuration.go index f6954b1b8d..97f982afdd 100644 --- a/clients/algoliasearch-client-go/algolia/insights/configuration.go +++ b/clients/algoliasearch-client-go/algolia/insights/configuration.go @@ -2,29 +2,10 @@ package insights import ( - "net/http" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -type Requester interface { - Request(*http.Request) (*http.Response, error) -} - -type defaultRequester struct { - client *http.Client -} - -func newDefaultRequester() *defaultRequester { - return &defaultRequester{ - client: http.DefaultClient, - } -} - -func (r *defaultRequester) Request(req *http.Request) (*http.Response, error) { - return r.client.Do(req) -} +var allowedRegions = [...]string{"de", "us"} type Region string @@ -35,16 +16,7 @@ const ( // Configuration stores the configuration of the API client. type Configuration struct { - AppID string - ApiKey string - Region Region + transport.Configuration - Hosts []string `json:"host,omitempty"` - DefaultHeader map[string]string `json:"defaultHeader,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Debug bool `json:"debug,omitempty"` - Requester Requester - ReadTimeout time.Duration - WriteTimeout time.Duration - Compression compression.Compression + Region Region } diff --git a/clients/algoliasearch-client-go/algolia/insights/response.go b/clients/algoliasearch-client-go/algolia/insights/response.go deleted file mode 100644 index d9a5b89a1a..0000000000 --- a/clients/algoliasearch-client-go/algolia/insights/response.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Insights API - -The Algolia Insights API lets you collect events related to your search and discovery experience. Events represent actions that users take on your app or website. They unlock powerful features, such as recommendations, personalization, smarter search results, and analytics that help you optimize your user experience. - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package insights - -import ( - "net/http" -) - -// APIResponse stores the API response returned by the server. -type APIResponse struct { - *http.Response `json:"-"` - Message string `json:"message,omitempty"` - // Operation is the name of the OpenAPI operation. - Operation string `json:"operation,omitempty"` - // RequestURL is the request URL. This value is always available, even if the - // embedded *http.Response is nil. - RequestURL string `json:"url,omitempty"` - // Method is the HTTP method used for the request. This value is always - // available, even if the embedded *http.Response is nil. - Method string `json:"method,omitempty"` - // Payload holds the contents of the response body (which may be nil or empty). - // This is provided here as the raw response.Body() reader will have already - // been drained. - Payload []byte `json:"-"` -} - -// NewAPIResponse returns a new APIResponse object. -func NewAPIResponse(r *http.Response) *APIResponse { - - response := &APIResponse{Response: r} - return response -} - -// NewAPIResponseWithError returns a new APIResponse object with the provided error message. -func NewAPIResponseWithError(errorMessage string) *APIResponse { - - response := &APIResponse{Message: errorMessage} - return response -} diff --git a/clients/algoliasearch-client-go/algolia/insights/utils.go b/clients/algoliasearch-client-go/algolia/insights/utils.go deleted file mode 100644 index 29d50f1650..0000000000 --- a/clients/algoliasearch-client-go/algolia/insights/utils.go +++ /dev/null @@ -1,385 +0,0 @@ -/* -Insights API - -The Algolia Insights API lets you collect events related to your search and discovery experience. Events represent actions that users take on your app or website. They unlock powerful features, such as recommendations, personalization, smarter search results, and analytics that help you optimize your user experience. - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package insights - -import ( - "encoding/json" - "reflect" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/errs" -) - -// PtrBool is a helper routine that returns a pointer to given boolean value. -func PtrBool(v bool) *bool { return &v } - -// PtrInt is a helper routine that returns a pointer to given integer value. -func PtrInt(v int) *int { return &v } - -// PtrInt32 is a helper routine that returns a pointer to given integer value. -func PtrInt32(v int32) *int32 { return &v } - -// PtrInt64 is a helper routine that returns a pointer to given integer value. -func PtrInt64(v int64) *int64 { return &v } - -// PtrFloat32 is a helper routine that returns a pointer to given float value. -func PtrFloat32(v float32) *float32 { return &v } - -// PtrFloat64 is a helper routine that returns a pointer to given float value. -func PtrFloat64(v float64) *float64 { return &v } - -// PtrString is a helper routine that returns a pointer to given string value. -func PtrString(v string) *string { return &v } - -// PtrTime is helper routine that returns a pointer to given Time value. -func PtrTime(v time.Time) *time.Time { return &v } - -type NullableBool struct { - value *bool - isSet bool -} - -func (v NullableBool) Get() *bool { - return v.value -} - -func (v *NullableBool) Set(val *bool) { - v.value = val - v.isSet = true -} - -func (v NullableBool) IsSet() bool { - return v.isSet -} - -func (v *NullableBool) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableBool(val *bool) *NullableBool { - return &NullableBool{value: val, isSet: true} -} - -func (v NullableBool) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableBool) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt struct { - value *int - isSet bool -} - -func (v NullableInt) Get() *int { - return v.value -} - -func (v *NullableInt) Set(val *int) { - v.value = val - v.isSet = true -} - -func (v NullableInt) IsSet() bool { - return v.isSet -} - -func (v *NullableInt) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt(val *int) *NullableInt { - return &NullableInt{value: val, isSet: true} -} - -func (v NullableInt) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt32 struct { - value *int32 - isSet bool -} - -func (v NullableInt32) Get() *int32 { - return v.value -} - -func (v *NullableInt32) Set(val *int32) { - v.value = val - v.isSet = true -} - -func (v NullableInt32) IsSet() bool { - return v.isSet -} - -func (v *NullableInt32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt32(val *int32) *NullableInt32 { - return &NullableInt32{value: val, isSet: true} -} - -func (v NullableInt32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt64 struct { - value *int64 - isSet bool -} - -func (v NullableInt64) Get() *int64 { - return v.value -} - -func (v *NullableInt64) Set(val *int64) { - v.value = val - v.isSet = true -} - -func (v NullableInt64) IsSet() bool { - return v.isSet -} - -func (v *NullableInt64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt64(val *int64) *NullableInt64 { - return &NullableInt64{value: val, isSet: true} -} - -func (v NullableInt64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat32 struct { - value *float32 - isSet bool -} - -func (v NullableFloat32) Get() *float32 { - return v.value -} - -func (v *NullableFloat32) Set(val *float32) { - v.value = val - v.isSet = true -} - -func (v NullableFloat32) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat32(val *float32) *NullableFloat32 { - return &NullableFloat32{value: val, isSet: true} -} - -func (v NullableFloat32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat64 struct { - value *float64 - isSet bool -} - -func (v NullableFloat64) Get() *float64 { - return v.value -} - -func (v *NullableFloat64) Set(val *float64) { - v.value = val - v.isSet = true -} - -func (v NullableFloat64) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat64(val *float64) *NullableFloat64 { - return &NullableFloat64{value: val, isSet: true} -} - -func (v NullableFloat64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableString struct { - value *string - isSet bool -} - -func (v NullableString) Get() *string { - return v.value -} - -func (v *NullableString) Set(val *string) { - v.value = val - v.isSet = true -} - -func (v NullableString) IsSet() bool { - return v.isSet -} - -func (v *NullableString) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableString(val *string) *NullableString { - return &NullableString{value: val, isSet: true} -} - -func (v NullableString) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableString) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableTime struct { - value *time.Time - isSet bool -} - -func (v NullableTime) Get() *time.Time { - return v.value -} - -func (v *NullableTime) Set(val *time.Time) { - v.value = val - v.isSet = true -} - -func (v NullableTime) IsSet() bool { - return v.isSet -} - -func (v *NullableTime) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableTime(val *time.Time) *NullableTime { - return &NullableTime{value: val, isSet: true} -} - -func (v NullableTime) MarshalJSON() ([]byte, error) { - return v.value.MarshalJSON() -} - -func (v *NullableTime) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// isNilorEmpty checks if an input is nil or empty -func isNilorEmpty(i any) bool { - if i == nil { - return true - } - switch reflect.TypeOf(i).Kind() { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: - return reflect.ValueOf(i).IsNil() - case reflect.Bool: - return false - default: - return reflect.ValueOf(i).IsZero() - } -} - -func RetryUntil[T any]( - retry func() (*T, error), - until func(*T, error) bool, - maxRetries *int, - initialDelay *time.Duration, - maxDelay *time.Duration, -) (*T, error) { - if maxRetries == nil { - maxRetries = new(int) - *maxRetries = 50 - } - - if initialDelay == nil { - initialDelay = new(time.Duration) - *initialDelay = 200 * time.Millisecond - } - - if maxDelay == nil { - maxDelay = new(time.Duration) - *maxDelay = 5 * time.Second - } - - for i := 0; i < *maxRetries; i++ { - res, err := retry() - - if ok := until(res, err); ok { - return res, nil - } - - time.Sleep(*initialDelay) - *initialDelay *= 2 - if *initialDelay > *maxDelay { - *initialDelay = *maxDelay - } - } - - return nil, &errs.WaitError{} -} diff --git a/clients/algoliasearch-client-go/algolia/monitoring/api_monitoring.go b/clients/algoliasearch-client-go/algolia/monitoring/api_monitoring.go index 57889d189a..6e45c18b43 100644 --- a/clients/algoliasearch-client-go/algolia/monitoring/api_monitoring.go +++ b/clients/algoliasearch-client-go/algolia/monitoring/api_monitoring.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "github.com/algolia/algoliasearch-client-go/v4/algolia/call" + "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" ) type Option struct { @@ -115,12 +115,15 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomDelete`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -141,7 +144,7 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -260,12 +263,15 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomGet`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -286,7 +292,7 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -423,12 +429,15 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPost`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -445,7 +454,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -455,7 +464,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -592,12 +601,15 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPut`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -614,7 +626,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -624,7 +636,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -725,10 +737,13 @@ func (c *APIClient) GetClusterIncidentsWithContext(ctx context.Context, r ApiGet ) requestPath := "/1/incidents/{clusters}" - requestPath = strings.ReplaceAll(requestPath, "{"+"clusters"+"}", url.PathEscape(parameterToString(r.clusters))) + requestPath = strings.ReplaceAll(requestPath, "{clusters}", url.PathEscape(parameterToString(r.clusters))) headers := make(map[string]string) queryParams := url.Values{} + if r.clusters == "" { + return returnValue, reportError("Parameter `clusters` is required when calling `GetClusterIncidents`.") + } // optional params if any for _, opt := range opts { @@ -745,7 +760,7 @@ func (c *APIClient) GetClusterIncidentsWithContext(ctx context.Context, r ApiGet return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -846,10 +861,13 @@ func (c *APIClient) GetClusterStatusWithContext(ctx context.Context, r ApiGetClu ) requestPath := "/1/status/{clusters}" - requestPath = strings.ReplaceAll(requestPath, "{"+"clusters"+"}", url.PathEscape(parameterToString(r.clusters))) + requestPath = strings.ReplaceAll(requestPath, "{clusters}", url.PathEscape(parameterToString(r.clusters))) headers := make(map[string]string) queryParams := url.Values{} + if r.clusters == "" { + return returnValue, reportError("Parameter `clusters` is required when calling `GetClusterStatus`.") + } // optional params if any for _, opt := range opts { @@ -866,7 +884,7 @@ func (c *APIClient) GetClusterStatusWithContext(ctx context.Context, r ApiGetClu return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -953,7 +971,7 @@ func (c *APIClient) GetIncidentsWithContext(ctx context.Context, opts ...Option) return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1054,10 +1072,13 @@ func (c *APIClient) GetIndexingTimeWithContext(ctx context.Context, r ApiGetInde ) requestPath := "/1/indexing/{clusters}" - requestPath = strings.ReplaceAll(requestPath, "{"+"clusters"+"}", url.PathEscape(parameterToString(r.clusters))) + requestPath = strings.ReplaceAll(requestPath, "{clusters}", url.PathEscape(parameterToString(r.clusters))) headers := make(map[string]string) queryParams := url.Values{} + if r.clusters == "" { + return returnValue, reportError("Parameter `clusters` is required when calling `GetIndexingTime`.") + } // optional params if any for _, opt := range opts { @@ -1074,7 +1095,7 @@ func (c *APIClient) GetIndexingTimeWithContext(ctx context.Context, r ApiGetInde return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1177,7 +1198,7 @@ func (c *APIClient) GetInventoryWithContext(ctx context.Context, opts ...Option) return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1278,10 +1299,13 @@ func (c *APIClient) GetLatencyWithContext(ctx context.Context, r ApiGetLatencyRe ) requestPath := "/1/latency/{clusters}" - requestPath = strings.ReplaceAll(requestPath, "{"+"clusters"+"}", url.PathEscape(parameterToString(r.clusters))) + requestPath = strings.ReplaceAll(requestPath, "{clusters}", url.PathEscape(parameterToString(r.clusters))) headers := make(map[string]string) queryParams := url.Values{} + if r.clusters == "" { + return returnValue, reportError("Parameter `clusters` is required when calling `GetLatency`.") + } // optional params if any for _, opt := range opts { @@ -1298,7 +1322,7 @@ func (c *APIClient) GetLatencyWithContext(ctx context.Context, r ApiGetLatencyRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1412,8 +1436,8 @@ func (c *APIClient) GetMetricsWithContext(ctx context.Context, r ApiGetMetricsRe ) requestPath := "/1/infrastructure/{metric}/period/{period}" - requestPath = strings.ReplaceAll(requestPath, "{"+"metric"+"}", url.PathEscape(parameterToString(r.metric))) - requestPath = strings.ReplaceAll(requestPath, "{"+"period"+"}", url.PathEscape(parameterToString(r.period))) + requestPath = strings.ReplaceAll(requestPath, "{metric}", url.PathEscape(parameterToString(r.metric))) + requestPath = strings.ReplaceAll(requestPath, "{period}", url.PathEscape(parameterToString(r.period))) headers := make(map[string]string) queryParams := url.Values{} @@ -1433,7 +1457,7 @@ func (c *APIClient) GetMetricsWithContext(ctx context.Context, r ApiGetMetricsRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1534,10 +1558,13 @@ func (c *APIClient) GetReachabilityWithContext(ctx context.Context, r ApiGetReac ) requestPath := "/1/reachability/{clusters}/probes" - requestPath = strings.ReplaceAll(requestPath, "{"+"clusters"+"}", url.PathEscape(parameterToString(r.clusters))) + requestPath = strings.ReplaceAll(requestPath, "{clusters}", url.PathEscape(parameterToString(r.clusters))) headers := make(map[string]string) queryParams := url.Values{} + if r.clusters == "" { + return returnValue, reportError("Parameter `clusters` is required when calling `GetReachability`.") + } // optional params if any for _, opt := range opts { @@ -1554,7 +1581,7 @@ func (c *APIClient) GetReachabilityWithContext(ctx context.Context, r ApiGetReac return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1657,7 +1684,7 @@ func (c *APIClient) GetStatusWithContext(ctx context.Context, opts ...Option) (* return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } diff --git a/clients/algoliasearch-client-go/algolia/monitoring/client.go b/clients/algoliasearch-client-go/algolia/monitoring/client.go index 82e97691cb..955fd594c9 100644 --- a/clients/algoliasearch-client-go/algolia/monitoring/client.go +++ b/clients/algoliasearch-client-go/algolia/monitoring/client.go @@ -23,7 +23,7 @@ import ( "github.com/algolia/algoliasearch-client-go/v4/algolia/call" "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/transport" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) var jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) @@ -37,26 +37,28 @@ type APIClient struct { } // NewClient creates a new API client with appID and apiKey. -func NewClient(appID, apiKey string) *APIClient { +func NewClient(appID, apiKey string) (*APIClient, error) { return NewClientWithConfig(Configuration{ - AppID: appID, - ApiKey: apiKey, - DefaultHeader: make(map[string]string), - UserAgent: getUserAgent(), - Debug: false, - Requester: newDefaultRequester(), + Configuration: transport.Configuration{ + AppID: appID, + ApiKey: apiKey, + DefaultHeader: make(map[string]string), + UserAgent: getUserAgent(), + Debug: false, + Requester: transport.NewDefaultRequester(nil), + }, }) } // NewClientWithConfig creates a new API client with the given configuration to fully customize the client behaviour. -func NewClientWithConfig(cfg Configuration) *APIClient { +func NewClientWithConfig(cfg Configuration) (*APIClient, error) { var hosts []*transport.StatefulHost if cfg.AppID == "" { - panic("appID is required") + return nil, errors.New("`appId` is missing.") } if cfg.ApiKey == "" { - panic("apiKey is required") + return nil, errors.New("`apiKey` is missing.") } if len(cfg.Hosts) == 0 { hosts = getDefaultHosts(cfg.AppID) @@ -66,7 +68,7 @@ func NewClientWithConfig(cfg Configuration) *APIClient { } } if cfg.Requester == nil { - cfg.Requester = newDefaultRequester() + cfg.Requester = transport.NewDefaultRequester(&cfg.ConnectTimeout) } if cfg.UserAgent == "" { cfg.UserAgent = getUserAgent() @@ -80,9 +82,10 @@ func NewClientWithConfig(cfg Configuration) *APIClient { cfg.Requester, cfg.ReadTimeout, cfg.WriteTimeout, + cfg.ConnectTimeout, cfg.Compression, ), - } + }, nil } func getDefaultHosts(appID string) []*transport.StatefulHost { @@ -121,7 +124,7 @@ func (c *APIClient) AddDefaultHeader(key string, value string) { } // callAPI do the request. -func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Response, error) { +func (c *APIClient) callAPI(request *http.Request, useReadTransporter bool) (*http.Response, error) { if c.cfg.Debug { dump, err := httputil.DumpRequestOut(request, true) if err != nil { @@ -130,7 +133,12 @@ func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Respon log.Printf("\n%s\n", string(dump)) } - resp, err := c.transport.Request(request.Context(), request, kind) + callKind := call.Write + if useReadTransporter || request.Method == http.MethodGet { + callKind = call.Read + } + + resp, err := c.transport.Request(request.Context(), request, callKind) if err != nil { return nil, err } diff --git a/clients/algoliasearch-client-go/algolia/monitoring/configuration.go b/clients/algoliasearch-client-go/algolia/monitoring/configuration.go index 3364098841..9365d8cb99 100644 --- a/clients/algoliasearch-client-go/algolia/monitoring/configuration.go +++ b/clients/algoliasearch-client-go/algolia/monitoring/configuration.go @@ -2,41 +2,10 @@ package monitoring import ( - "net/http" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -type Requester interface { - Request(*http.Request) (*http.Response, error) -} - -type defaultRequester struct { - client *http.Client -} - -func newDefaultRequester() *defaultRequester { - return &defaultRequester{ - client: http.DefaultClient, - } -} - -func (r *defaultRequester) Request(req *http.Request) (*http.Response, error) { - return r.client.Do(req) -} - // Configuration stores the configuration of the API client. type Configuration struct { - AppID string - ApiKey string - - Hosts []string `json:"host,omitempty"` - DefaultHeader map[string]string `json:"defaultHeader,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Debug bool `json:"debug,omitempty"` - Requester Requester - ReadTimeout time.Duration - WriteTimeout time.Duration - Compression compression.Compression + transport.Configuration } diff --git a/clients/algoliasearch-client-go/algolia/monitoring/response.go b/clients/algoliasearch-client-go/algolia/monitoring/response.go deleted file mode 100644 index d24d60dc30..0000000000 --- a/clients/algoliasearch-client-go/algolia/monitoring/response.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Algolia Monitoring API - -The Monitoring API lets you check the status and performance of your Algolia infrastructure. > **Note**: The Monitoring API is available on [Premium plans](https://www.algolia.com/pricing/) and plans including the Enterprise add-on. - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package monitoring - -import ( - "net/http" -) - -// APIResponse stores the API response returned by the server. -type APIResponse struct { - *http.Response `json:"-"` - Message string `json:"message,omitempty"` - // Operation is the name of the OpenAPI operation. - Operation string `json:"operation,omitempty"` - // RequestURL is the request URL. This value is always available, even if the - // embedded *http.Response is nil. - RequestURL string `json:"url,omitempty"` - // Method is the HTTP method used for the request. This value is always - // available, even if the embedded *http.Response is nil. - Method string `json:"method,omitempty"` - // Payload holds the contents of the response body (which may be nil or empty). - // This is provided here as the raw response.Body() reader will have already - // been drained. - Payload []byte `json:"-"` -} - -// NewAPIResponse returns a new APIResponse object. -func NewAPIResponse(r *http.Response) *APIResponse { - - response := &APIResponse{Response: r} - return response -} - -// NewAPIResponseWithError returns a new APIResponse object with the provided error message. -func NewAPIResponseWithError(errorMessage string) *APIResponse { - - response := &APIResponse{Message: errorMessage} - return response -} diff --git a/clients/algoliasearch-client-go/algolia/monitoring/utils.go b/clients/algoliasearch-client-go/algolia/monitoring/utils.go deleted file mode 100644 index 1e624314fd..0000000000 --- a/clients/algoliasearch-client-go/algolia/monitoring/utils.go +++ /dev/null @@ -1,385 +0,0 @@ -/* -Algolia Monitoring API - -The Monitoring API lets you check the status and performance of your Algolia infrastructure. > **Note**: The Monitoring API is available on [Premium plans](https://www.algolia.com/pricing/) and plans including the Enterprise add-on. - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package monitoring - -import ( - "encoding/json" - "reflect" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/errs" -) - -// PtrBool is a helper routine that returns a pointer to given boolean value. -func PtrBool(v bool) *bool { return &v } - -// PtrInt is a helper routine that returns a pointer to given integer value. -func PtrInt(v int) *int { return &v } - -// PtrInt32 is a helper routine that returns a pointer to given integer value. -func PtrInt32(v int32) *int32 { return &v } - -// PtrInt64 is a helper routine that returns a pointer to given integer value. -func PtrInt64(v int64) *int64 { return &v } - -// PtrFloat32 is a helper routine that returns a pointer to given float value. -func PtrFloat32(v float32) *float32 { return &v } - -// PtrFloat64 is a helper routine that returns a pointer to given float value. -func PtrFloat64(v float64) *float64 { return &v } - -// PtrString is a helper routine that returns a pointer to given string value. -func PtrString(v string) *string { return &v } - -// PtrTime is helper routine that returns a pointer to given Time value. -func PtrTime(v time.Time) *time.Time { return &v } - -type NullableBool struct { - value *bool - isSet bool -} - -func (v NullableBool) Get() *bool { - return v.value -} - -func (v *NullableBool) Set(val *bool) { - v.value = val - v.isSet = true -} - -func (v NullableBool) IsSet() bool { - return v.isSet -} - -func (v *NullableBool) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableBool(val *bool) *NullableBool { - return &NullableBool{value: val, isSet: true} -} - -func (v NullableBool) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableBool) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt struct { - value *int - isSet bool -} - -func (v NullableInt) Get() *int { - return v.value -} - -func (v *NullableInt) Set(val *int) { - v.value = val - v.isSet = true -} - -func (v NullableInt) IsSet() bool { - return v.isSet -} - -func (v *NullableInt) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt(val *int) *NullableInt { - return &NullableInt{value: val, isSet: true} -} - -func (v NullableInt) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt32 struct { - value *int32 - isSet bool -} - -func (v NullableInt32) Get() *int32 { - return v.value -} - -func (v *NullableInt32) Set(val *int32) { - v.value = val - v.isSet = true -} - -func (v NullableInt32) IsSet() bool { - return v.isSet -} - -func (v *NullableInt32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt32(val *int32) *NullableInt32 { - return &NullableInt32{value: val, isSet: true} -} - -func (v NullableInt32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt64 struct { - value *int64 - isSet bool -} - -func (v NullableInt64) Get() *int64 { - return v.value -} - -func (v *NullableInt64) Set(val *int64) { - v.value = val - v.isSet = true -} - -func (v NullableInt64) IsSet() bool { - return v.isSet -} - -func (v *NullableInt64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt64(val *int64) *NullableInt64 { - return &NullableInt64{value: val, isSet: true} -} - -func (v NullableInt64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat32 struct { - value *float32 - isSet bool -} - -func (v NullableFloat32) Get() *float32 { - return v.value -} - -func (v *NullableFloat32) Set(val *float32) { - v.value = val - v.isSet = true -} - -func (v NullableFloat32) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat32(val *float32) *NullableFloat32 { - return &NullableFloat32{value: val, isSet: true} -} - -func (v NullableFloat32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat64 struct { - value *float64 - isSet bool -} - -func (v NullableFloat64) Get() *float64 { - return v.value -} - -func (v *NullableFloat64) Set(val *float64) { - v.value = val - v.isSet = true -} - -func (v NullableFloat64) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat64(val *float64) *NullableFloat64 { - return &NullableFloat64{value: val, isSet: true} -} - -func (v NullableFloat64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableString struct { - value *string - isSet bool -} - -func (v NullableString) Get() *string { - return v.value -} - -func (v *NullableString) Set(val *string) { - v.value = val - v.isSet = true -} - -func (v NullableString) IsSet() bool { - return v.isSet -} - -func (v *NullableString) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableString(val *string) *NullableString { - return &NullableString{value: val, isSet: true} -} - -func (v NullableString) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableString) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableTime struct { - value *time.Time - isSet bool -} - -func (v NullableTime) Get() *time.Time { - return v.value -} - -func (v *NullableTime) Set(val *time.Time) { - v.value = val - v.isSet = true -} - -func (v NullableTime) IsSet() bool { - return v.isSet -} - -func (v *NullableTime) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableTime(val *time.Time) *NullableTime { - return &NullableTime{value: val, isSet: true} -} - -func (v NullableTime) MarshalJSON() ([]byte, error) { - return v.value.MarshalJSON() -} - -func (v *NullableTime) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// isNilorEmpty checks if an input is nil or empty -func isNilorEmpty(i any) bool { - if i == nil { - return true - } - switch reflect.TypeOf(i).Kind() { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: - return reflect.ValueOf(i).IsNil() - case reflect.Bool: - return false - default: - return reflect.ValueOf(i).IsZero() - } -} - -func RetryUntil[T any]( - retry func() (*T, error), - until func(*T, error) bool, - maxRetries *int, - initialDelay *time.Duration, - maxDelay *time.Duration, -) (*T, error) { - if maxRetries == nil { - maxRetries = new(int) - *maxRetries = 50 - } - - if initialDelay == nil { - initialDelay = new(time.Duration) - *initialDelay = 200 * time.Millisecond - } - - if maxDelay == nil { - maxDelay = new(time.Duration) - *maxDelay = 5 * time.Second - } - - for i := 0; i < *maxRetries; i++ { - res, err := retry() - - if ok := until(res, err); ok { - return res, nil - } - - time.Sleep(*initialDelay) - *initialDelay *= 2 - if *initialDelay > *maxDelay { - *initialDelay = *maxDelay - } - } - - return nil, &errs.WaitError{} -} diff --git a/clients/algoliasearch-client-go/algolia/personalization/api_personalization.go b/clients/algoliasearch-client-go/algolia/personalization/api_personalization.go index 67ca2c2439..d15ddf3da3 100644 --- a/clients/algoliasearch-client-go/algolia/personalization/api_personalization.go +++ b/clients/algoliasearch-client-go/algolia/personalization/api_personalization.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "github.com/algolia/algoliasearch-client-go/v4/algolia/call" + "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" ) type Option struct { @@ -115,12 +115,15 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomDelete`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -141,7 +144,7 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -260,12 +263,15 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomGet`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -286,7 +292,7 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -423,12 +429,15 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPost`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -445,7 +454,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -455,7 +464,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -592,12 +601,15 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPut`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -614,7 +626,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -624,7 +636,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -733,10 +745,13 @@ func (c *APIClient) DeleteUserProfileWithContext(ctx context.Context, r ApiDelet ) requestPath := "/1/profiles/{userToken}" - requestPath = strings.ReplaceAll(requestPath, "{"+"userToken"+"}", url.PathEscape(parameterToString(r.userToken))) + requestPath = strings.ReplaceAll(requestPath, "{userToken}", url.PathEscape(parameterToString(r.userToken))) headers := make(map[string]string) queryParams := url.Values{} + if r.userToken == "" { + return returnValue, reportError("Parameter `userToken` is required when calling `DeleteUserProfile`.") + } // optional params if any for _, opt := range opts { @@ -753,7 +768,7 @@ func (c *APIClient) DeleteUserProfileWithContext(ctx context.Context, r ApiDelet return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -840,7 +855,7 @@ func (c *APIClient) GetPersonalizationStrategyWithContext(ctx context.Context, o return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -945,10 +960,13 @@ func (c *APIClient) GetUserTokenProfileWithContext(ctx context.Context, r ApiGet ) requestPath := "/1/profiles/personalization/{userToken}" - requestPath = strings.ReplaceAll(requestPath, "{"+"userToken"+"}", url.PathEscape(parameterToString(r.userToken))) + requestPath = strings.ReplaceAll(requestPath, "{userToken}", url.PathEscape(parameterToString(r.userToken))) headers := make(map[string]string) queryParams := url.Values{} + if r.userToken == "" { + return returnValue, reportError("Parameter `userToken` is required when calling `GetUserTokenProfile`.") + } // optional params if any for _, opt := range opts { @@ -965,7 +983,7 @@ func (c *APIClient) GetUserTokenProfileWithContext(ctx context.Context, r ApiGet return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1074,8 +1092,9 @@ func (c *APIClient) SetPersonalizationStrategyWithContext(ctx context.Context, r headers := make(map[string]string) queryParams := url.Values{} + if r.personalizationStrategyParams == nil { - return returnValue, reportError("personalizationStrategyParams is required and must be specified") + return returnValue, reportError("Parameter `personalizationStrategyParams` is required when calling `SetPersonalizationStrategy`.") } // optional params if any @@ -1095,7 +1114,7 @@ func (c *APIClient) SetPersonalizationStrategyWithContext(ctx context.Context, r return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } diff --git a/clients/algoliasearch-client-go/algolia/personalization/client.go b/clients/algoliasearch-client-go/algolia/personalization/client.go index a6db544d0e..b6dabbbfa6 100644 --- a/clients/algoliasearch-client-go/algolia/personalization/client.go +++ b/clients/algoliasearch-client-go/algolia/personalization/client.go @@ -16,6 +16,7 @@ import ( "reflect" "regexp" "runtime" + "slices" "strings" "time" @@ -23,7 +24,7 @@ import ( "github.com/algolia/algoliasearch-client-go/v4/algolia/call" "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/transport" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) var jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) @@ -37,31 +38,33 @@ type APIClient struct { } // NewClient creates a new API client with appID, apiKey and region. -func NewClient(appID, apiKey string, region Region) *APIClient { +func NewClient(appID, apiKey string, region Region) (*APIClient, error) { return NewClientWithConfig(Configuration{ - AppID: appID, - ApiKey: apiKey, - Region: region, - DefaultHeader: make(map[string]string), - UserAgent: getUserAgent(), - Debug: false, - Requester: newDefaultRequester(), + Configuration: transport.Configuration{ + AppID: appID, + ApiKey: apiKey, + DefaultHeader: make(map[string]string), + UserAgent: getUserAgent(), + Debug: false, + Requester: transport.NewDefaultRequester(nil), + }, + Region: region, }) } // NewClientWithConfig creates a new API client with the given configuration to fully customize the client behaviour. -func NewClientWithConfig(cfg Configuration) *APIClient { +func NewClientWithConfig(cfg Configuration) (*APIClient, error) { var hosts []*transport.StatefulHost if cfg.AppID == "" { - panic("appID is required") + return nil, errors.New("`appId` is missing.") } if cfg.ApiKey == "" { - panic("apiKey is required") + return nil, errors.New("`apiKey` is missing.") } if len(cfg.Hosts) == 0 { - if cfg.Region == "" { - panic("region is required") + if cfg.Region == "" || (cfg.Region != "" && !slices.Contains(allowedRegions[:], string(cfg.Region))) { + return nil, fmt.Errorf("`region` is required and must be one of the following: %s", strings.Join(allowedRegions[:], ", ")) } hosts = getDefaultHosts(cfg.Region) } else { @@ -70,7 +73,7 @@ func NewClientWithConfig(cfg Configuration) *APIClient { } } if cfg.Requester == nil { - cfg.Requester = newDefaultRequester() + cfg.Requester = transport.NewDefaultRequester(&cfg.ConnectTimeout) } if cfg.UserAgent == "" { cfg.UserAgent = getUserAgent() @@ -84,18 +87,14 @@ func NewClientWithConfig(cfg Configuration) *APIClient { cfg.Requester, cfg.ReadTimeout, cfg.WriteTimeout, + cfg.ConnectTimeout, cfg.Compression, ), - } + }, nil } func getDefaultHosts(r Region) []*transport.StatefulHost { - hosts := []*transport.StatefulHost{} - switch r { - case EU, US: - hosts = append(hosts, transport.NewStatefulHost(strings.ReplaceAll("personalization.{region}.algolia.com", "{region}", string(r)), call.IsReadWrite)) - } - return hosts + return []*transport.StatefulHost{transport.NewStatefulHost(strings.ReplaceAll("personalization.{region}.algolia.com", "{region}", string(r)), call.IsReadWrite)} } func getUserAgent() string { @@ -119,7 +118,7 @@ func (c *APIClient) AddDefaultHeader(key string, value string) { } // callAPI do the request. -func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Response, error) { +func (c *APIClient) callAPI(request *http.Request, useReadTransporter bool) (*http.Response, error) { if c.cfg.Debug { dump, err := httputil.DumpRequestOut(request, true) if err != nil { @@ -128,7 +127,12 @@ func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Respon log.Printf("\n%s\n", string(dump)) } - resp, err := c.transport.Request(request.Context(), request, kind) + callKind := call.Write + if useReadTransporter || request.Method == http.MethodGet { + callKind = call.Read + } + + resp, err := c.transport.Request(request.Context(), request, callKind) if err != nil { return nil, err } diff --git a/clients/algoliasearch-client-go/algolia/personalization/configuration.go b/clients/algoliasearch-client-go/algolia/personalization/configuration.go index 505bcb2b9c..08cfd42c61 100644 --- a/clients/algoliasearch-client-go/algolia/personalization/configuration.go +++ b/clients/algoliasearch-client-go/algolia/personalization/configuration.go @@ -2,29 +2,10 @@ package personalization import ( - "net/http" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -type Requester interface { - Request(*http.Request) (*http.Response, error) -} - -type defaultRequester struct { - client *http.Client -} - -func newDefaultRequester() *defaultRequester { - return &defaultRequester{ - client: http.DefaultClient, - } -} - -func (r *defaultRequester) Request(req *http.Request) (*http.Response, error) { - return r.client.Do(req) -} +var allowedRegions = [...]string{"eu", "us"} type Region string @@ -35,16 +16,7 @@ const ( // Configuration stores the configuration of the API client. type Configuration struct { - AppID string - ApiKey string - Region Region + transport.Configuration - Hosts []string `json:"host,omitempty"` - DefaultHeader map[string]string `json:"defaultHeader,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Debug bool `json:"debug,omitempty"` - Requester Requester - ReadTimeout time.Duration - WriteTimeout time.Duration - Compression compression.Compression + Region Region } diff --git a/clients/algoliasearch-client-go/algolia/personalization/response.go b/clients/algoliasearch-client-go/algolia/personalization/response.go deleted file mode 100644 index 5ea0566ed1..0000000000 --- a/clients/algoliasearch-client-go/algolia/personalization/response.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Personalization API - -API powering the Personalization feature of Algolia. - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package personalization - -import ( - "net/http" -) - -// APIResponse stores the API response returned by the server. -type APIResponse struct { - *http.Response `json:"-"` - Message string `json:"message,omitempty"` - // Operation is the name of the OpenAPI operation. - Operation string `json:"operation,omitempty"` - // RequestURL is the request URL. This value is always available, even if the - // embedded *http.Response is nil. - RequestURL string `json:"url,omitempty"` - // Method is the HTTP method used for the request. This value is always - // available, even if the embedded *http.Response is nil. - Method string `json:"method,omitempty"` - // Payload holds the contents of the response body (which may be nil or empty). - // This is provided here as the raw response.Body() reader will have already - // been drained. - Payload []byte `json:"-"` -} - -// NewAPIResponse returns a new APIResponse object. -func NewAPIResponse(r *http.Response) *APIResponse { - - response := &APIResponse{Response: r} - return response -} - -// NewAPIResponseWithError returns a new APIResponse object with the provided error message. -func NewAPIResponseWithError(errorMessage string) *APIResponse { - - response := &APIResponse{Message: errorMessage} - return response -} diff --git a/clients/algoliasearch-client-go/algolia/personalization/utils.go b/clients/algoliasearch-client-go/algolia/personalization/utils.go deleted file mode 100644 index 731cdec090..0000000000 --- a/clients/algoliasearch-client-go/algolia/personalization/utils.go +++ /dev/null @@ -1,385 +0,0 @@ -/* -Personalization API - -API powering the Personalization feature of Algolia. - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package personalization - -import ( - "encoding/json" - "reflect" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/errs" -) - -// PtrBool is a helper routine that returns a pointer to given boolean value. -func PtrBool(v bool) *bool { return &v } - -// PtrInt is a helper routine that returns a pointer to given integer value. -func PtrInt(v int) *int { return &v } - -// PtrInt32 is a helper routine that returns a pointer to given integer value. -func PtrInt32(v int32) *int32 { return &v } - -// PtrInt64 is a helper routine that returns a pointer to given integer value. -func PtrInt64(v int64) *int64 { return &v } - -// PtrFloat32 is a helper routine that returns a pointer to given float value. -func PtrFloat32(v float32) *float32 { return &v } - -// PtrFloat64 is a helper routine that returns a pointer to given float value. -func PtrFloat64(v float64) *float64 { return &v } - -// PtrString is a helper routine that returns a pointer to given string value. -func PtrString(v string) *string { return &v } - -// PtrTime is helper routine that returns a pointer to given Time value. -func PtrTime(v time.Time) *time.Time { return &v } - -type NullableBool struct { - value *bool - isSet bool -} - -func (v NullableBool) Get() *bool { - return v.value -} - -func (v *NullableBool) Set(val *bool) { - v.value = val - v.isSet = true -} - -func (v NullableBool) IsSet() bool { - return v.isSet -} - -func (v *NullableBool) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableBool(val *bool) *NullableBool { - return &NullableBool{value: val, isSet: true} -} - -func (v NullableBool) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableBool) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt struct { - value *int - isSet bool -} - -func (v NullableInt) Get() *int { - return v.value -} - -func (v *NullableInt) Set(val *int) { - v.value = val - v.isSet = true -} - -func (v NullableInt) IsSet() bool { - return v.isSet -} - -func (v *NullableInt) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt(val *int) *NullableInt { - return &NullableInt{value: val, isSet: true} -} - -func (v NullableInt) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt32 struct { - value *int32 - isSet bool -} - -func (v NullableInt32) Get() *int32 { - return v.value -} - -func (v *NullableInt32) Set(val *int32) { - v.value = val - v.isSet = true -} - -func (v NullableInt32) IsSet() bool { - return v.isSet -} - -func (v *NullableInt32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt32(val *int32) *NullableInt32 { - return &NullableInt32{value: val, isSet: true} -} - -func (v NullableInt32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt64 struct { - value *int64 - isSet bool -} - -func (v NullableInt64) Get() *int64 { - return v.value -} - -func (v *NullableInt64) Set(val *int64) { - v.value = val - v.isSet = true -} - -func (v NullableInt64) IsSet() bool { - return v.isSet -} - -func (v *NullableInt64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt64(val *int64) *NullableInt64 { - return &NullableInt64{value: val, isSet: true} -} - -func (v NullableInt64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat32 struct { - value *float32 - isSet bool -} - -func (v NullableFloat32) Get() *float32 { - return v.value -} - -func (v *NullableFloat32) Set(val *float32) { - v.value = val - v.isSet = true -} - -func (v NullableFloat32) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat32(val *float32) *NullableFloat32 { - return &NullableFloat32{value: val, isSet: true} -} - -func (v NullableFloat32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat64 struct { - value *float64 - isSet bool -} - -func (v NullableFloat64) Get() *float64 { - return v.value -} - -func (v *NullableFloat64) Set(val *float64) { - v.value = val - v.isSet = true -} - -func (v NullableFloat64) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat64(val *float64) *NullableFloat64 { - return &NullableFloat64{value: val, isSet: true} -} - -func (v NullableFloat64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableString struct { - value *string - isSet bool -} - -func (v NullableString) Get() *string { - return v.value -} - -func (v *NullableString) Set(val *string) { - v.value = val - v.isSet = true -} - -func (v NullableString) IsSet() bool { - return v.isSet -} - -func (v *NullableString) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableString(val *string) *NullableString { - return &NullableString{value: val, isSet: true} -} - -func (v NullableString) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableString) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableTime struct { - value *time.Time - isSet bool -} - -func (v NullableTime) Get() *time.Time { - return v.value -} - -func (v *NullableTime) Set(val *time.Time) { - v.value = val - v.isSet = true -} - -func (v NullableTime) IsSet() bool { - return v.isSet -} - -func (v *NullableTime) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableTime(val *time.Time) *NullableTime { - return &NullableTime{value: val, isSet: true} -} - -func (v NullableTime) MarshalJSON() ([]byte, error) { - return v.value.MarshalJSON() -} - -func (v *NullableTime) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// isNilorEmpty checks if an input is nil or empty -func isNilorEmpty(i any) bool { - if i == nil { - return true - } - switch reflect.TypeOf(i).Kind() { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: - return reflect.ValueOf(i).IsNil() - case reflect.Bool: - return false - default: - return reflect.ValueOf(i).IsZero() - } -} - -func RetryUntil[T any]( - retry func() (*T, error), - until func(*T, error) bool, - maxRetries *int, - initialDelay *time.Duration, - maxDelay *time.Duration, -) (*T, error) { - if maxRetries == nil { - maxRetries = new(int) - *maxRetries = 50 - } - - if initialDelay == nil { - initialDelay = new(time.Duration) - *initialDelay = 200 * time.Millisecond - } - - if maxDelay == nil { - maxDelay = new(time.Duration) - *maxDelay = 5 * time.Second - } - - for i := 0; i < *maxRetries; i++ { - res, err := retry() - - if ok := until(res, err); ok { - return res, nil - } - - time.Sleep(*initialDelay) - *initialDelay *= 2 - if *initialDelay > *maxDelay { - *initialDelay = *maxDelay - } - } - - return nil, &errs.WaitError{} -} diff --git a/clients/algoliasearch-client-go/algolia/query-suggestions/api_query_suggestions.go b/clients/algoliasearch-client-go/algolia/query-suggestions/api_query_suggestions.go index 1d8a906c98..b0e6176534 100644 --- a/clients/algoliasearch-client-go/algolia/query-suggestions/api_query_suggestions.go +++ b/clients/algoliasearch-client-go/algolia/query-suggestions/api_query_suggestions.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "github.com/algolia/algoliasearch-client-go/v4/algolia/call" + "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" ) type Option struct { @@ -109,8 +109,9 @@ func (c *APIClient) CreateConfigWithContext(ctx context.Context, r ApiCreateConf headers := make(map[string]string) queryParams := url.Values{} + if r.querySuggestionsConfigurationWithIndex == nil { - return returnValue, reportError("querySuggestionsConfigurationWithIndex is required and must be specified") + return returnValue, reportError("Parameter `querySuggestionsConfigurationWithIndex` is required when calling `CreateConfig`.") } // optional params if any @@ -130,7 +131,7 @@ func (c *APIClient) CreateConfigWithContext(ctx context.Context, r ApiCreateConf return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -249,12 +250,15 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomDelete`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -275,7 +279,7 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -394,12 +398,15 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomGet`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -420,7 +427,7 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -557,12 +564,15 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPost`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -579,7 +589,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -589,7 +599,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -726,12 +736,15 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPut`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -748,7 +761,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -758,7 +771,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -865,10 +878,13 @@ func (c *APIClient) DeleteConfigWithContext(ctx context.Context, r ApiDeleteConf ) requestPath := "/1/configs/{indexName}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `DeleteConfig`.") + } // optional params if any for _, opt := range opts { @@ -885,7 +901,7 @@ func (c *APIClient) DeleteConfigWithContext(ctx context.Context, r ApiDeleteConf return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -972,7 +988,7 @@ func (c *APIClient) GetAllConfigsWithContext(ctx context.Context, opts ...Option return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1073,10 +1089,13 @@ func (c *APIClient) GetConfigWithContext(ctx context.Context, r ApiGetConfigRequ ) requestPath := "/1/configs/{indexName}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `GetConfig`.") + } // optional params if any for _, opt := range opts { @@ -1093,7 +1112,7 @@ func (c *APIClient) GetConfigWithContext(ctx context.Context, r ApiGetConfigRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1194,10 +1213,13 @@ func (c *APIClient) GetConfigStatusWithContext(ctx context.Context, r ApiGetConf ) requestPath := "/1/configs/{indexName}/status" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `GetConfigStatus`.") + } // optional params if any for _, opt := range opts { @@ -1214,7 +1236,7 @@ func (c *APIClient) GetConfigStatusWithContext(ctx context.Context, r ApiGetConf return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1315,10 +1337,13 @@ func (c *APIClient) GetLogFileWithContext(ctx context.Context, r ApiGetLogFileRe ) requestPath := "/1/logs/{indexName}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `GetLogFile`.") + } // optional params if any for _, opt := range opts { @@ -1335,7 +1360,7 @@ func (c *APIClient) GetLogFileWithContext(ctx context.Context, r ApiGetLogFileRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1454,12 +1479,16 @@ func (c *APIClient) UpdateConfigWithContext(ctx context.Context, r ApiUpdateConf ) requestPath := "/1/configs/{indexName}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `UpdateConfig`.") + } + if r.querySuggestionsConfiguration == nil { - return returnValue, reportError("querySuggestionsConfiguration is required and must be specified") + return returnValue, reportError("Parameter `querySuggestionsConfiguration` is required when calling `UpdateConfig`.") } // optional params if any @@ -1479,7 +1508,7 @@ func (c *APIClient) UpdateConfigWithContext(ctx context.Context, r ApiUpdateConf return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } diff --git a/clients/algoliasearch-client-go/algolia/query-suggestions/client.go b/clients/algoliasearch-client-go/algolia/query-suggestions/client.go index b52d53e3ac..4ce12d663b 100644 --- a/clients/algoliasearch-client-go/algolia/query-suggestions/client.go +++ b/clients/algoliasearch-client-go/algolia/query-suggestions/client.go @@ -16,6 +16,7 @@ import ( "reflect" "regexp" "runtime" + "slices" "strings" "time" @@ -23,7 +24,7 @@ import ( "github.com/algolia/algoliasearch-client-go/v4/algolia/call" "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/transport" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) var jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) @@ -37,31 +38,33 @@ type APIClient struct { } // NewClient creates a new API client with appID, apiKey and region. -func NewClient(appID, apiKey string, region Region) *APIClient { +func NewClient(appID, apiKey string, region Region) (*APIClient, error) { return NewClientWithConfig(Configuration{ - AppID: appID, - ApiKey: apiKey, - Region: region, - DefaultHeader: make(map[string]string), - UserAgent: getUserAgent(), - Debug: false, - Requester: newDefaultRequester(), + Configuration: transport.Configuration{ + AppID: appID, + ApiKey: apiKey, + DefaultHeader: make(map[string]string), + UserAgent: getUserAgent(), + Debug: false, + Requester: transport.NewDefaultRequester(nil), + }, + Region: region, }) } // NewClientWithConfig creates a new API client with the given configuration to fully customize the client behaviour. -func NewClientWithConfig(cfg Configuration) *APIClient { +func NewClientWithConfig(cfg Configuration) (*APIClient, error) { var hosts []*transport.StatefulHost if cfg.AppID == "" { - panic("appID is required") + return nil, errors.New("`appId` is missing.") } if cfg.ApiKey == "" { - panic("apiKey is required") + return nil, errors.New("`apiKey` is missing.") } if len(cfg.Hosts) == 0 { - if cfg.Region == "" { - panic("region is required") + if cfg.Region == "" || (cfg.Region != "" && !slices.Contains(allowedRegions[:], string(cfg.Region))) { + return nil, fmt.Errorf("`region` is required and must be one of the following: %s", strings.Join(allowedRegions[:], ", ")) } hosts = getDefaultHosts(cfg.Region) } else { @@ -70,7 +73,7 @@ func NewClientWithConfig(cfg Configuration) *APIClient { } } if cfg.Requester == nil { - cfg.Requester = newDefaultRequester() + cfg.Requester = transport.NewDefaultRequester(&cfg.ConnectTimeout) } if cfg.UserAgent == "" { cfg.UserAgent = getUserAgent() @@ -84,22 +87,18 @@ func NewClientWithConfig(cfg Configuration) *APIClient { cfg.Requester, cfg.ReadTimeout, cfg.WriteTimeout, + cfg.ConnectTimeout, cfg.Compression, ), - } + }, nil } func getDefaultHosts(r Region) []*transport.StatefulHost { - hosts := []*transport.StatefulHost{} - switch r { - case EU, US: - hosts = append(hosts, transport.NewStatefulHost(strings.ReplaceAll("query-suggestions.{region}.algolia.com", "{region}", string(r)), call.IsReadWrite)) - } - return hosts + return []*transport.StatefulHost{transport.NewStatefulHost(strings.ReplaceAll("query-suggestions.{region}.algolia.com", "{region}", string(r)), call.IsReadWrite)} } func getUserAgent() string { - return fmt.Sprintf("Algolia for Go (4.0.0-alpha.42); Go (%s); Query-suggestions (4.0.0-alpha.42)", runtime.Version()) + return fmt.Sprintf("Algolia for Go (4.0.0-alpha.42); Go (%s); QuerySuggestions (4.0.0-alpha.42)", runtime.Version()) } // parameterToString convert any parameters to string. @@ -119,7 +118,7 @@ func (c *APIClient) AddDefaultHeader(key string, value string) { } // callAPI do the request. -func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Response, error) { +func (c *APIClient) callAPI(request *http.Request, useReadTransporter bool) (*http.Response, error) { if c.cfg.Debug { dump, err := httputil.DumpRequestOut(request, true) if err != nil { @@ -128,7 +127,12 @@ func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Respon log.Printf("\n%s\n", string(dump)) } - resp, err := c.transport.Request(request.Context(), request, kind) + callKind := call.Write + if useReadTransporter || request.Method == http.MethodGet { + callKind = call.Read + } + + resp, err := c.transport.Request(request.Context(), request, callKind) if err != nil { return nil, err } diff --git a/clients/algoliasearch-client-go/algolia/query-suggestions/configuration.go b/clients/algoliasearch-client-go/algolia/query-suggestions/configuration.go index ef3bc8b5ff..b8e10ef6d9 100644 --- a/clients/algoliasearch-client-go/algolia/query-suggestions/configuration.go +++ b/clients/algoliasearch-client-go/algolia/query-suggestions/configuration.go @@ -2,29 +2,10 @@ package suggestions import ( - "net/http" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -type Requester interface { - Request(*http.Request) (*http.Response, error) -} - -type defaultRequester struct { - client *http.Client -} - -func newDefaultRequester() *defaultRequester { - return &defaultRequester{ - client: http.DefaultClient, - } -} - -func (r *defaultRequester) Request(req *http.Request) (*http.Response, error) { - return r.client.Do(req) -} +var allowedRegions = [...]string{"eu", "us"} type Region string @@ -35,16 +16,7 @@ const ( // Configuration stores the configuration of the API client. type Configuration struct { - AppID string - ApiKey string - Region Region + transport.Configuration - Hosts []string `json:"host,omitempty"` - DefaultHeader map[string]string `json:"defaultHeader,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Debug bool `json:"debug,omitempty"` - Requester Requester - ReadTimeout time.Duration - WriteTimeout time.Duration - Compression compression.Compression + Region Region } diff --git a/clients/algoliasearch-client-go/algolia/query-suggestions/response.go b/clients/algoliasearch-client-go/algolia/query-suggestions/response.go deleted file mode 100644 index 405c3aa647..0000000000 --- a/clients/algoliasearch-client-go/algolia/query-suggestions/response.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Query Suggestions API - -The Query Suggestions API lets you manage Algolia's Query Suggestions configurations. Query Suggestions add new indices with popular search queries, external suggestions, or facet values to your Algolia application. In your user interface, you can query the Query Suggestions indices like regular indices and add [suggested searches](https://www.algolia.com/doc/guides/building-search-ui/ui-and-ux-patterns/query-suggestions/js/) to guide users and speed up their search. - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package suggestions - -import ( - "net/http" -) - -// APIResponse stores the API response returned by the server. -type APIResponse struct { - *http.Response `json:"-"` - Message string `json:"message,omitempty"` - // Operation is the name of the OpenAPI operation. - Operation string `json:"operation,omitempty"` - // RequestURL is the request URL. This value is always available, even if the - // embedded *http.Response is nil. - RequestURL string `json:"url,omitempty"` - // Method is the HTTP method used for the request. This value is always - // available, even if the embedded *http.Response is nil. - Method string `json:"method,omitempty"` - // Payload holds the contents of the response body (which may be nil or empty). - // This is provided here as the raw response.Body() reader will have already - // been drained. - Payload []byte `json:"-"` -} - -// NewAPIResponse returns a new APIResponse object. -func NewAPIResponse(r *http.Response) *APIResponse { - - response := &APIResponse{Response: r} - return response -} - -// NewAPIResponseWithError returns a new APIResponse object with the provided error message. -func NewAPIResponseWithError(errorMessage string) *APIResponse { - - response := &APIResponse{Message: errorMessage} - return response -} diff --git a/clients/algoliasearch-client-go/algolia/query-suggestions/utils.go b/clients/algoliasearch-client-go/algolia/query-suggestions/utils.go deleted file mode 100644 index 97a5b47f3c..0000000000 --- a/clients/algoliasearch-client-go/algolia/query-suggestions/utils.go +++ /dev/null @@ -1,385 +0,0 @@ -/* -Query Suggestions API - -The Query Suggestions API lets you manage Algolia's Query Suggestions configurations. Query Suggestions add new indices with popular search queries, external suggestions, or facet values to your Algolia application. In your user interface, you can query the Query Suggestions indices like regular indices and add [suggested searches](https://www.algolia.com/doc/guides/building-search-ui/ui-and-ux-patterns/query-suggestions/js/) to guide users and speed up their search. - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package suggestions - -import ( - "encoding/json" - "reflect" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/errs" -) - -// PtrBool is a helper routine that returns a pointer to given boolean value. -func PtrBool(v bool) *bool { return &v } - -// PtrInt is a helper routine that returns a pointer to given integer value. -func PtrInt(v int) *int { return &v } - -// PtrInt32 is a helper routine that returns a pointer to given integer value. -func PtrInt32(v int32) *int32 { return &v } - -// PtrInt64 is a helper routine that returns a pointer to given integer value. -func PtrInt64(v int64) *int64 { return &v } - -// PtrFloat32 is a helper routine that returns a pointer to given float value. -func PtrFloat32(v float32) *float32 { return &v } - -// PtrFloat64 is a helper routine that returns a pointer to given float value. -func PtrFloat64(v float64) *float64 { return &v } - -// PtrString is a helper routine that returns a pointer to given string value. -func PtrString(v string) *string { return &v } - -// PtrTime is helper routine that returns a pointer to given Time value. -func PtrTime(v time.Time) *time.Time { return &v } - -type NullableBool struct { - value *bool - isSet bool -} - -func (v NullableBool) Get() *bool { - return v.value -} - -func (v *NullableBool) Set(val *bool) { - v.value = val - v.isSet = true -} - -func (v NullableBool) IsSet() bool { - return v.isSet -} - -func (v *NullableBool) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableBool(val *bool) *NullableBool { - return &NullableBool{value: val, isSet: true} -} - -func (v NullableBool) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableBool) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt struct { - value *int - isSet bool -} - -func (v NullableInt) Get() *int { - return v.value -} - -func (v *NullableInt) Set(val *int) { - v.value = val - v.isSet = true -} - -func (v NullableInt) IsSet() bool { - return v.isSet -} - -func (v *NullableInt) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt(val *int) *NullableInt { - return &NullableInt{value: val, isSet: true} -} - -func (v NullableInt) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt32 struct { - value *int32 - isSet bool -} - -func (v NullableInt32) Get() *int32 { - return v.value -} - -func (v *NullableInt32) Set(val *int32) { - v.value = val - v.isSet = true -} - -func (v NullableInt32) IsSet() bool { - return v.isSet -} - -func (v *NullableInt32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt32(val *int32) *NullableInt32 { - return &NullableInt32{value: val, isSet: true} -} - -func (v NullableInt32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt64 struct { - value *int64 - isSet bool -} - -func (v NullableInt64) Get() *int64 { - return v.value -} - -func (v *NullableInt64) Set(val *int64) { - v.value = val - v.isSet = true -} - -func (v NullableInt64) IsSet() bool { - return v.isSet -} - -func (v *NullableInt64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt64(val *int64) *NullableInt64 { - return &NullableInt64{value: val, isSet: true} -} - -func (v NullableInt64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat32 struct { - value *float32 - isSet bool -} - -func (v NullableFloat32) Get() *float32 { - return v.value -} - -func (v *NullableFloat32) Set(val *float32) { - v.value = val - v.isSet = true -} - -func (v NullableFloat32) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat32(val *float32) *NullableFloat32 { - return &NullableFloat32{value: val, isSet: true} -} - -func (v NullableFloat32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat64 struct { - value *float64 - isSet bool -} - -func (v NullableFloat64) Get() *float64 { - return v.value -} - -func (v *NullableFloat64) Set(val *float64) { - v.value = val - v.isSet = true -} - -func (v NullableFloat64) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat64(val *float64) *NullableFloat64 { - return &NullableFloat64{value: val, isSet: true} -} - -func (v NullableFloat64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableString struct { - value *string - isSet bool -} - -func (v NullableString) Get() *string { - return v.value -} - -func (v *NullableString) Set(val *string) { - v.value = val - v.isSet = true -} - -func (v NullableString) IsSet() bool { - return v.isSet -} - -func (v *NullableString) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableString(val *string) *NullableString { - return &NullableString{value: val, isSet: true} -} - -func (v NullableString) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableString) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableTime struct { - value *time.Time - isSet bool -} - -func (v NullableTime) Get() *time.Time { - return v.value -} - -func (v *NullableTime) Set(val *time.Time) { - v.value = val - v.isSet = true -} - -func (v NullableTime) IsSet() bool { - return v.isSet -} - -func (v *NullableTime) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableTime(val *time.Time) *NullableTime { - return &NullableTime{value: val, isSet: true} -} - -func (v NullableTime) MarshalJSON() ([]byte, error) { - return v.value.MarshalJSON() -} - -func (v *NullableTime) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// isNilorEmpty checks if an input is nil or empty -func isNilorEmpty(i any) bool { - if i == nil { - return true - } - switch reflect.TypeOf(i).Kind() { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: - return reflect.ValueOf(i).IsNil() - case reflect.Bool: - return false - default: - return reflect.ValueOf(i).IsZero() - } -} - -func RetryUntil[T any]( - retry func() (*T, error), - until func(*T, error) bool, - maxRetries *int, - initialDelay *time.Duration, - maxDelay *time.Duration, -) (*T, error) { - if maxRetries == nil { - maxRetries = new(int) - *maxRetries = 50 - } - - if initialDelay == nil { - initialDelay = new(time.Duration) - *initialDelay = 200 * time.Millisecond - } - - if maxDelay == nil { - maxDelay = new(time.Duration) - *maxDelay = 5 * time.Second - } - - for i := 0; i < *maxRetries; i++ { - res, err := retry() - - if ok := until(res, err); ok { - return res, nil - } - - time.Sleep(*initialDelay) - *initialDelay *= 2 - if *initialDelay > *maxDelay { - *initialDelay = *maxDelay - } - } - - return nil, &errs.WaitError{} -} diff --git a/clients/algoliasearch-client-go/algolia/recommend/api_recommend.go b/clients/algoliasearch-client-go/algolia/recommend/api_recommend.go index 1e48acac21..1c2ea2cffb 100644 --- a/clients/algoliasearch-client-go/algolia/recommend/api_recommend.go +++ b/clients/algoliasearch-client-go/algolia/recommend/api_recommend.go @@ -10,7 +10,7 @@ import ( "net/url" "strings" - "github.com/algolia/algoliasearch-client-go/v4/algolia/call" + "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" ) type Option struct { @@ -115,12 +115,15 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomDelete`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -141,7 +144,7 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -260,12 +263,15 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomGet`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -286,7 +292,7 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -423,12 +429,15 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPost`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -445,7 +454,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -455,7 +464,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -592,12 +601,15 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPut`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -614,7 +626,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -624,7 +636,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -751,12 +763,19 @@ func (c *APIClient) DeleteRecommendRuleWithContext(ctx context.Context, r ApiDel ) requestPath := "/1/indexes/{indexName}/{model}/recommend/rules/{objectID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"model"+"}", url.PathEscape(parameterToString(r.model))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{model}", url.PathEscape(parameterToString(r.model))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `DeleteRecommendRule`.") + } + + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `DeleteRecommendRule`.") + } // optional params if any for _, opt := range opts { @@ -773,7 +792,7 @@ func (c *APIClient) DeleteRecommendRuleWithContext(ctx context.Context, r ApiDel return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -900,12 +919,19 @@ func (c *APIClient) GetRecommendRuleWithContext(ctx context.Context, r ApiGetRec ) requestPath := "/1/indexes/{indexName}/{model}/recommend/rules/{objectID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"model"+"}", url.PathEscape(parameterToString(r.model))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{model}", url.PathEscape(parameterToString(r.model))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `GetRecommendRule`.") + } + + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `GetRecommendRule`.") + } // optional params if any for _, opt := range opts { @@ -922,7 +948,7 @@ func (c *APIClient) GetRecommendRuleWithContext(ctx context.Context, r ApiGetRec return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1049,12 +1075,15 @@ func (c *APIClient) GetRecommendStatusWithContext(ctx context.Context, r ApiGetR ) requestPath := "/1/indexes/{indexName}/{model}/task/{taskID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"model"+"}", url.PathEscape(parameterToString(r.model))) - requestPath = strings.ReplaceAll(requestPath, "{"+"taskID"+"}", url.PathEscape(parameterToString(r.taskID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{model}", url.PathEscape(parameterToString(r.model))) + requestPath = strings.ReplaceAll(requestPath, "{taskID}", url.PathEscape(parameterToString(r.taskID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `GetRecommendStatus`.") + } // optional params if any for _, opt := range opts { @@ -1071,7 +1100,7 @@ func (c *APIClient) GetRecommendStatusWithContext(ctx context.Context, r ApiGetR return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1186,8 +1215,9 @@ func (c *APIClient) GetRecommendationsWithContext(ctx context.Context, r ApiGetR headers := make(map[string]string) queryParams := url.Values{} + if r.getRecommendationsParams == nil { - return returnValue, reportError("getRecommendationsParams is required and must be specified") + return returnValue, reportError("Parameter `getRecommendationsParams` is required when calling `GetRecommendations`.") } // optional params if any @@ -1207,7 +1237,7 @@ func (c *APIClient) GetRecommendationsWithContext(ctx context.Context, r ApiGetR return returnValue, err } - res, err := c.callAPI(req, call.Read) + res, err := c.callAPI(req, true) if err != nil { return returnValue, err } @@ -1339,11 +1369,14 @@ func (c *APIClient) SearchRecommendRulesWithContext(ctx context.Context, r ApiSe ) requestPath := "/1/indexes/{indexName}/{model}/recommend/rules/search" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"model"+"}", url.PathEscape(parameterToString(r.model))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{model}", url.PathEscape(parameterToString(r.model))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `SearchRecommendRules`.") + } // optional params if any for _, opt := range opts { @@ -1356,7 +1389,7 @@ func (c *APIClient) SearchRecommendRulesWithContext(ctx context.Context, r ApiSe } // body params - if isNilorEmpty(r.searchRecommendRulesParams) { + if utils.IsNilOrEmpty(r.searchRecommendRulesParams) { postBody = "{}" } else { postBody = r.searchRecommendRulesParams @@ -1366,7 +1399,7 @@ func (c *APIClient) SearchRecommendRulesWithContext(ctx context.Context, r ApiSe return returnValue, err } - res, err := c.callAPI(req, call.Read) + res, err := c.callAPI(req, true) if err != nil { return returnValue, err } diff --git a/clients/algoliasearch-client-go/algolia/recommend/client.go b/clients/algoliasearch-client-go/algolia/recommend/client.go index 4f012db505..9a45df4603 100644 --- a/clients/algoliasearch-client-go/algolia/recommend/client.go +++ b/clients/algoliasearch-client-go/algolia/recommend/client.go @@ -23,7 +23,7 @@ import ( "github.com/algolia/algoliasearch-client-go/v4/algolia/call" "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/transport" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) var jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) @@ -37,26 +37,28 @@ type APIClient struct { } // NewClient creates a new API client with appID and apiKey. -func NewClient(appID, apiKey string) *APIClient { +func NewClient(appID, apiKey string) (*APIClient, error) { return NewClientWithConfig(Configuration{ - AppID: appID, - ApiKey: apiKey, - DefaultHeader: make(map[string]string), - UserAgent: getUserAgent(), - Debug: false, - Requester: newDefaultRequester(), + Configuration: transport.Configuration{ + AppID: appID, + ApiKey: apiKey, + DefaultHeader: make(map[string]string), + UserAgent: getUserAgent(), + Debug: false, + Requester: transport.NewDefaultRequester(nil), + }, }) } // NewClientWithConfig creates a new API client with the given configuration to fully customize the client behaviour. -func NewClientWithConfig(cfg Configuration) *APIClient { +func NewClientWithConfig(cfg Configuration) (*APIClient, error) { var hosts []*transport.StatefulHost if cfg.AppID == "" { - panic("appID is required") + return nil, errors.New("`appId` is missing.") } if cfg.ApiKey == "" { - panic("apiKey is required") + return nil, errors.New("`apiKey` is missing.") } if len(cfg.Hosts) == 0 { hosts = getDefaultHosts(cfg.AppID) @@ -66,7 +68,7 @@ func NewClientWithConfig(cfg Configuration) *APIClient { } } if cfg.Requester == nil { - cfg.Requester = newDefaultRequester() + cfg.Requester = transport.NewDefaultRequester(&cfg.ConnectTimeout) } if cfg.UserAgent == "" { cfg.UserAgent = getUserAgent() @@ -80,9 +82,10 @@ func NewClientWithConfig(cfg Configuration) *APIClient { cfg.Requester, cfg.ReadTimeout, cfg.WriteTimeout, + cfg.ConnectTimeout, cfg.Compression, ), - } + }, nil } func getDefaultHosts(appID string) []*transport.StatefulHost { @@ -121,7 +124,7 @@ func (c *APIClient) AddDefaultHeader(key string, value string) { } // callAPI do the request. -func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Response, error) { +func (c *APIClient) callAPI(request *http.Request, useReadTransporter bool) (*http.Response, error) { if c.cfg.Debug { dump, err := httputil.DumpRequestOut(request, true) if err != nil { @@ -130,7 +133,12 @@ func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Respon log.Printf("\n%s\n", string(dump)) } - resp, err := c.transport.Request(request.Context(), request, kind) + callKind := call.Write + if useReadTransporter || request.Method == http.MethodGet { + callKind = call.Read + } + + resp, err := c.transport.Request(request.Context(), request, callKind) if err != nil { return nil, err } diff --git a/clients/algoliasearch-client-go/algolia/recommend/configuration.go b/clients/algoliasearch-client-go/algolia/recommend/configuration.go index af040379ea..f20ab2a738 100644 --- a/clients/algoliasearch-client-go/algolia/recommend/configuration.go +++ b/clients/algoliasearch-client-go/algolia/recommend/configuration.go @@ -2,41 +2,10 @@ package recommend import ( - "net/http" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -type Requester interface { - Request(*http.Request) (*http.Response, error) -} - -type defaultRequester struct { - client *http.Client -} - -func newDefaultRequester() *defaultRequester { - return &defaultRequester{ - client: http.DefaultClient, - } -} - -func (r *defaultRequester) Request(req *http.Request) (*http.Response, error) { - return r.client.Do(req) -} - // Configuration stores the configuration of the API client. type Configuration struct { - AppID string - ApiKey string - - Hosts []string `json:"host,omitempty"` - DefaultHeader map[string]string `json:"defaultHeader,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Debug bool `json:"debug,omitempty"` - Requester Requester - ReadTimeout time.Duration - WriteTimeout time.Duration - Compression compression.Compression + transport.Configuration } diff --git a/clients/algoliasearch-client-go/algolia/recommend/model_search_recommend_rules_params.go b/clients/algoliasearch-client-go/algolia/recommend/model_search_recommend_rules_params.go index 961a76732c..6e9f6a49be 100644 --- a/clients/algoliasearch-client-go/algolia/recommend/model_search_recommend_rules_params.go +++ b/clients/algoliasearch-client-go/algolia/recommend/model_search_recommend_rules_params.go @@ -4,6 +4,8 @@ package recommend import ( "encoding/json" "fmt" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" ) // SearchRecommendRulesParams Recommend rules search parameters. @@ -17,7 +19,7 @@ type SearchRecommendRulesParams struct { // Maximum number of hits per page. HitsPerPage *int32 `json:"hitsPerPage,omitempty"` // Restricts responses to enabled rules. When absent (default), _all_ rules are retrieved. - Enabled NullableBool `json:"enabled,omitempty"` + Enabled utils.NullableBool `json:"enabled,omitempty"` } type SearchRecommendRulesParamsOption func(f *SearchRecommendRulesParams) @@ -46,7 +48,7 @@ func WithSearchRecommendRulesParamsHitsPerPage(val int32) SearchRecommendRulesPa } } -func WithSearchRecommendRulesParamsEnabled(val NullableBool) SearchRecommendRulesParamsOption { +func WithSearchRecommendRulesParamsEnabled(val utils.NullableBool) SearchRecommendRulesParamsOption { return func(f *SearchRecommendRulesParams) { f.Enabled = val } @@ -229,7 +231,7 @@ func (o *SearchRecommendRulesParams) HasEnabled() bool { return false } -// SetEnabled gets a reference to the given NullableBool and assigns it to the Enabled field. +// SetEnabled gets a reference to the given utils.NullableBool and assigns it to the Enabled field. func (o *SearchRecommendRulesParams) SetEnabled(v bool) *SearchRecommendRulesParams { o.Enabled.Set(&v) return o diff --git a/clients/algoliasearch-client-go/algolia/recommend/response.go b/clients/algoliasearch-client-go/algolia/recommend/response.go deleted file mode 100644 index db1ec93a75..0000000000 --- a/clients/algoliasearch-client-go/algolia/recommend/response.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Recommend API - -The Recommend API lets you generate recommendations with several AI models. > **Note**: You should use Algolia's [libraries and tools](https://www.algolia.com/doc/guides/getting-started/how-algolia-works/in-depth/ecosystem/) to interact with the Recommend API. Using the HTTP endpoints directly is not covered by the [SLA](https://www.algolia.com/policies/sla/). - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package recommend - -import ( - "net/http" -) - -// APIResponse stores the API response returned by the server. -type APIResponse struct { - *http.Response `json:"-"` - Message string `json:"message,omitempty"` - // Operation is the name of the OpenAPI operation. - Operation string `json:"operation,omitempty"` - // RequestURL is the request URL. This value is always available, even if the - // embedded *http.Response is nil. - RequestURL string `json:"url,omitempty"` - // Method is the HTTP method used for the request. This value is always - // available, even if the embedded *http.Response is nil. - Method string `json:"method,omitempty"` - // Payload holds the contents of the response body (which may be nil or empty). - // This is provided here as the raw response.Body() reader will have already - // been drained. - Payload []byte `json:"-"` -} - -// NewAPIResponse returns a new APIResponse object. -func NewAPIResponse(r *http.Response) *APIResponse { - - response := &APIResponse{Response: r} - return response -} - -// NewAPIResponseWithError returns a new APIResponse object with the provided error message. -func NewAPIResponseWithError(errorMessage string) *APIResponse { - - response := &APIResponse{Message: errorMessage} - return response -} diff --git a/clients/algoliasearch-client-go/algolia/recommend/utils.go b/clients/algoliasearch-client-go/algolia/recommend/utils.go deleted file mode 100644 index e0e48c8f10..0000000000 --- a/clients/algoliasearch-client-go/algolia/recommend/utils.go +++ /dev/null @@ -1,385 +0,0 @@ -/* -Recommend API - -The Recommend API lets you generate recommendations with several AI models. > **Note**: You should use Algolia's [libraries and tools](https://www.algolia.com/doc/guides/getting-started/how-algolia-works/in-depth/ecosystem/) to interact with the Recommend API. Using the HTTP endpoints directly is not covered by the [SLA](https://www.algolia.com/policies/sla/). - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package recommend - -import ( - "encoding/json" - "reflect" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/errs" -) - -// PtrBool is a helper routine that returns a pointer to given boolean value. -func PtrBool(v bool) *bool { return &v } - -// PtrInt is a helper routine that returns a pointer to given integer value. -func PtrInt(v int) *int { return &v } - -// PtrInt32 is a helper routine that returns a pointer to given integer value. -func PtrInt32(v int32) *int32 { return &v } - -// PtrInt64 is a helper routine that returns a pointer to given integer value. -func PtrInt64(v int64) *int64 { return &v } - -// PtrFloat32 is a helper routine that returns a pointer to given float value. -func PtrFloat32(v float32) *float32 { return &v } - -// PtrFloat64 is a helper routine that returns a pointer to given float value. -func PtrFloat64(v float64) *float64 { return &v } - -// PtrString is a helper routine that returns a pointer to given string value. -func PtrString(v string) *string { return &v } - -// PtrTime is helper routine that returns a pointer to given Time value. -func PtrTime(v time.Time) *time.Time { return &v } - -type NullableBool struct { - value *bool - isSet bool -} - -func (v NullableBool) Get() *bool { - return v.value -} - -func (v *NullableBool) Set(val *bool) { - v.value = val - v.isSet = true -} - -func (v NullableBool) IsSet() bool { - return v.isSet -} - -func (v *NullableBool) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableBool(val *bool) *NullableBool { - return &NullableBool{value: val, isSet: true} -} - -func (v NullableBool) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableBool) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt struct { - value *int - isSet bool -} - -func (v NullableInt) Get() *int { - return v.value -} - -func (v *NullableInt) Set(val *int) { - v.value = val - v.isSet = true -} - -func (v NullableInt) IsSet() bool { - return v.isSet -} - -func (v *NullableInt) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt(val *int) *NullableInt { - return &NullableInt{value: val, isSet: true} -} - -func (v NullableInt) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt32 struct { - value *int32 - isSet bool -} - -func (v NullableInt32) Get() *int32 { - return v.value -} - -func (v *NullableInt32) Set(val *int32) { - v.value = val - v.isSet = true -} - -func (v NullableInt32) IsSet() bool { - return v.isSet -} - -func (v *NullableInt32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt32(val *int32) *NullableInt32 { - return &NullableInt32{value: val, isSet: true} -} - -func (v NullableInt32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt64 struct { - value *int64 - isSet bool -} - -func (v NullableInt64) Get() *int64 { - return v.value -} - -func (v *NullableInt64) Set(val *int64) { - v.value = val - v.isSet = true -} - -func (v NullableInt64) IsSet() bool { - return v.isSet -} - -func (v *NullableInt64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt64(val *int64) *NullableInt64 { - return &NullableInt64{value: val, isSet: true} -} - -func (v NullableInt64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat32 struct { - value *float32 - isSet bool -} - -func (v NullableFloat32) Get() *float32 { - return v.value -} - -func (v *NullableFloat32) Set(val *float32) { - v.value = val - v.isSet = true -} - -func (v NullableFloat32) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat32(val *float32) *NullableFloat32 { - return &NullableFloat32{value: val, isSet: true} -} - -func (v NullableFloat32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat64 struct { - value *float64 - isSet bool -} - -func (v NullableFloat64) Get() *float64 { - return v.value -} - -func (v *NullableFloat64) Set(val *float64) { - v.value = val - v.isSet = true -} - -func (v NullableFloat64) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat64(val *float64) *NullableFloat64 { - return &NullableFloat64{value: val, isSet: true} -} - -func (v NullableFloat64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableString struct { - value *string - isSet bool -} - -func (v NullableString) Get() *string { - return v.value -} - -func (v *NullableString) Set(val *string) { - v.value = val - v.isSet = true -} - -func (v NullableString) IsSet() bool { - return v.isSet -} - -func (v *NullableString) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableString(val *string) *NullableString { - return &NullableString{value: val, isSet: true} -} - -func (v NullableString) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableString) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableTime struct { - value *time.Time - isSet bool -} - -func (v NullableTime) Get() *time.Time { - return v.value -} - -func (v *NullableTime) Set(val *time.Time) { - v.value = val - v.isSet = true -} - -func (v NullableTime) IsSet() bool { - return v.isSet -} - -func (v *NullableTime) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableTime(val *time.Time) *NullableTime { - return &NullableTime{value: val, isSet: true} -} - -func (v NullableTime) MarshalJSON() ([]byte, error) { - return v.value.MarshalJSON() -} - -func (v *NullableTime) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// isNilorEmpty checks if an input is nil or empty -func isNilorEmpty(i any) bool { - if i == nil { - return true - } - switch reflect.TypeOf(i).Kind() { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: - return reflect.ValueOf(i).IsNil() - case reflect.Bool: - return false - default: - return reflect.ValueOf(i).IsZero() - } -} - -func RetryUntil[T any]( - retry func() (*T, error), - until func(*T, error) bool, - maxRetries *int, - initialDelay *time.Duration, - maxDelay *time.Duration, -) (*T, error) { - if maxRetries == nil { - maxRetries = new(int) - *maxRetries = 50 - } - - if initialDelay == nil { - initialDelay = new(time.Duration) - *initialDelay = 200 * time.Millisecond - } - - if maxDelay == nil { - maxDelay = new(time.Duration) - *maxDelay = 5 * time.Second - } - - for i := 0; i < *maxRetries; i++ { - res, err := retry() - - if ok := until(res, err); ok { - return res, nil - } - - time.Sleep(*initialDelay) - *initialDelay *= 2 - if *initialDelay > *maxDelay { - *initialDelay = *maxDelay - } - } - - return nil, &errs.WaitError{} -} diff --git a/clients/algoliasearch-client-go/algolia/search/api_search.go b/clients/algoliasearch-client-go/algolia/search/api_search.go index d40e2ca18a..905ed61c2f 100644 --- a/clients/algoliasearch-client-go/algolia/search/api_search.go +++ b/clients/algoliasearch-client-go/algolia/search/api_search.go @@ -12,8 +12,9 @@ import ( "strings" "time" - "github.com/algolia/algoliasearch-client-go/v4/algolia/call" - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/errs" + "github.com/algolia/algoliasearch-client-go/v4/algolia/errs" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" ) type Option struct { @@ -112,8 +113,9 @@ func (c *APIClient) AddApiKeyWithContext(ctx context.Context, r ApiAddApiKeyRequ headers := make(map[string]string) queryParams := url.Values{} + if r.apiKey == nil { - return returnValue, reportError("apiKey is required and must be specified") + return returnValue, reportError("Parameter `apiKey` is required when calling `AddApiKey`.") } // optional params if any @@ -133,7 +135,7 @@ func (c *APIClient) AddApiKeyWithContext(ctx context.Context, r ApiAddApiKeyRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -273,11 +275,21 @@ func (c *APIClient) AddOrUpdateObjectWithContext(ctx context.Context, r ApiAddOr ) requestPath := "/1/indexes/{indexName}/{objectID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `AddOrUpdateObject`.") + } + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `AddOrUpdateObject`.") + } + + if len(r.body) == 0 { + return returnValue, reportError("Parameter `body` is required when calling `AddOrUpdateObject`.") + } // optional params if any for _, opt := range opts { @@ -296,7 +308,7 @@ func (c *APIClient) AddOrUpdateObjectWithContext(ctx context.Context, r ApiAddOr return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -405,8 +417,9 @@ func (c *APIClient) AppendSourceWithContext(ctx context.Context, r ApiAppendSour headers := make(map[string]string) queryParams := url.Values{} + if r.source == nil { - return returnValue, reportError("source is required and must be specified") + return returnValue, reportError("Parameter `source` is required when calling `AppendSource`.") } // optional params if any @@ -426,7 +439,7 @@ func (c *APIClient) AppendSourceWithContext(ctx context.Context, r ApiAppendSour return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -551,10 +564,11 @@ func (c *APIClient) AssignUserIdWithContext(ctx context.Context, r ApiAssignUser headers := make(map[string]string) queryParams := url.Values{} if r.xAlgoliaUserID == "" { - return returnValue, reportError("xAlgoliaUserID is required and must be specified") + return returnValue, reportError("Parameter `xAlgoliaUserID` is required when calling `AssignUserId`.") } + if r.assignUserIdParams == nil { - return returnValue, reportError("assignUserIdParams is required and must be specified") + return returnValue, reportError("Parameter `assignUserIdParams` is required when calling `AssignUserId`.") } headers["X-Algolia-User-ID"] = parameterToString(r.xAlgoliaUserID) @@ -576,7 +590,7 @@ func (c *APIClient) AssignUserIdWithContext(ctx context.Context, r ApiAssignUser return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -697,12 +711,16 @@ func (c *APIClient) BatchWithContext(ctx context.Context, r ApiBatchRequest, opt ) requestPath := "/1/indexes/{indexName}/batch" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `Batch`.") + } + if r.batchWriteParams == nil { - return returnValue, reportError("batchWriteParams is required and must be specified") + return returnValue, reportError("Parameter `batchWriteParams` is required when calling `Batch`.") } // optional params if any @@ -722,7 +740,7 @@ func (c *APIClient) BatchWithContext(ctx context.Context, r ApiBatchRequest, opt return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -847,10 +865,11 @@ func (c *APIClient) BatchAssignUserIdsWithContext(ctx context.Context, r ApiBatc headers := make(map[string]string) queryParams := url.Values{} if r.xAlgoliaUserID == "" { - return returnValue, reportError("xAlgoliaUserID is required and must be specified") + return returnValue, reportError("Parameter `xAlgoliaUserID` is required when calling `BatchAssignUserIds`.") } + if r.batchAssignUserIdsParams == nil { - return returnValue, reportError("batchAssignUserIdsParams is required and must be specified") + return returnValue, reportError("Parameter `batchAssignUserIdsParams` is required when calling `BatchAssignUserIds`.") } headers["X-Algolia-User-ID"] = parameterToString(r.xAlgoliaUserID) @@ -872,7 +891,7 @@ func (c *APIClient) BatchAssignUserIdsWithContext(ctx context.Context, r ApiBatc return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -991,12 +1010,13 @@ func (c *APIClient) BatchDictionaryEntriesWithContext(ctx context.Context, r Api ) requestPath := "/1/dictionaries/{dictionaryName}/batch" - requestPath = strings.ReplaceAll(requestPath, "{"+"dictionaryName"+"}", url.PathEscape(parameterToString(r.dictionaryName))) + requestPath = strings.ReplaceAll(requestPath, "{dictionaryName}", url.PathEscape(parameterToString(r.dictionaryName))) headers := make(map[string]string) queryParams := url.Values{} + if r.batchDictionaryEntriesParams == nil { - return returnValue, reportError("batchDictionaryEntriesParams is required and must be specified") + return returnValue, reportError("Parameter `batchDictionaryEntriesParams` is required when calling `BatchDictionaryEntries`.") } // optional params if any @@ -1016,7 +1036,7 @@ func (c *APIClient) BatchDictionaryEntriesWithContext(ctx context.Context, r Api return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1139,10 +1159,13 @@ func (c *APIClient) BrowseWithContext(ctx context.Context, r ApiBrowseRequest, o ) requestPath := "/1/indexes/{indexName}/browse" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `Browse`.") + } // optional params if any for _, opt := range opts { @@ -1155,7 +1178,7 @@ func (c *APIClient) BrowseWithContext(ctx context.Context, r ApiBrowseRequest, o } // body params - if isNilorEmpty(r.browseParams) { + if utils.IsNilOrEmpty(r.browseParams) { postBody = "{}" } else { postBody = r.browseParams @@ -1165,7 +1188,7 @@ func (c *APIClient) BrowseWithContext(ctx context.Context, r ApiBrowseRequest, o return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1266,10 +1289,13 @@ func (c *APIClient) ClearObjectsWithContext(ctx context.Context, r ApiClearObjec ) requestPath := "/1/indexes/{indexName}/clear" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `ClearObjects`.") + } // optional params if any for _, opt := range opts { @@ -1286,7 +1312,7 @@ func (c *APIClient) ClearObjectsWithContext(ctx context.Context, r ApiClearObjec return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1405,12 +1431,15 @@ func (c *APIClient) ClearRulesWithContext(ctx context.Context, r ApiClearRulesRe ) requestPath := "/1/indexes/{indexName}/rules/clear" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `ClearRules`.") + } - if !isNilorEmpty(r.forwardToReplicas) { + if !utils.IsNilOrEmpty(r.forwardToReplicas) { queryParams.Set("forwardToReplicas", parameterToString(r.forwardToReplicas)) } @@ -1429,7 +1458,7 @@ func (c *APIClient) ClearRulesWithContext(ctx context.Context, r ApiClearRulesRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1548,12 +1577,15 @@ func (c *APIClient) ClearSynonymsWithContext(ctx context.Context, r ApiClearSyno ) requestPath := "/1/indexes/{indexName}/synonyms/clear" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `ClearSynonyms`.") + } - if !isNilorEmpty(r.forwardToReplicas) { + if !utils.IsNilOrEmpty(r.forwardToReplicas) { queryParams.Set("forwardToReplicas", parameterToString(r.forwardToReplicas)) } @@ -1572,7 +1604,7 @@ func (c *APIClient) ClearSynonymsWithContext(ctx context.Context, r ApiClearSyno return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1691,12 +1723,15 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomDelete`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -1717,7 +1752,7 @@ func (c *APIClient) CustomDeleteWithContext(ctx context.Context, r ApiCustomDele return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1836,12 +1871,15 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomGet`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -1862,7 +1900,7 @@ func (c *APIClient) CustomGetWithContext(ctx context.Context, r ApiCustomGetRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -1999,12 +2037,15 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPost`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -2021,7 +2062,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -2031,7 +2072,7 @@ func (c *APIClient) CustomPostWithContext(ctx context.Context, r ApiCustomPostRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2168,12 +2209,15 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ ) requestPath := "/1{path}" - requestPath = strings.ReplaceAll(requestPath, "{"+"path"+"}", url.PathEscape(parameterToString(r.path))) + requestPath = strings.ReplaceAll(requestPath, "{path}", url.PathEscape(parameterToString(r.path))) headers := make(map[string]string) queryParams := url.Values{} + if r.path == "" { + return returnValue, reportError("Parameter `path` is required when calling `CustomPut`.") + } - if !isNilorEmpty(r.parameters) { + if !utils.IsNilOrEmpty(r.parameters) { for k, v := range r.parameters { queryParams.Set(k, parameterToString(v)) } @@ -2190,7 +2234,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ } // body params - if isNilorEmpty(r.body) { + if utils.IsNilOrEmpty(r.body) { postBody = "{}" } else { postBody = r.body @@ -2200,7 +2244,7 @@ func (c *APIClient) CustomPutWithContext(ctx context.Context, r ApiCustomPutRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2303,10 +2347,13 @@ func (c *APIClient) DeleteApiKeyWithContext(ctx context.Context, r ApiDeleteApiK ) requestPath := "/1/keys/{key}" - requestPath = strings.ReplaceAll(requestPath, "{"+"key"+"}", url.PathEscape(parameterToString(r.key))) + requestPath = strings.ReplaceAll(requestPath, "{key}", url.PathEscape(parameterToString(r.key))) headers := make(map[string]string) queryParams := url.Values{} + if r.key == "" { + return returnValue, reportError("Parameter `key` is required when calling `DeleteApiKey`.") + } // optional params if any for _, opt := range opts { @@ -2323,7 +2370,7 @@ func (c *APIClient) DeleteApiKeyWithContext(ctx context.Context, r ApiDeleteApiK return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2444,12 +2491,16 @@ func (c *APIClient) DeleteByWithContext(ctx context.Context, r ApiDeleteByReques ) requestPath := "/1/indexes/{indexName}/deleteByQuery" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `DeleteBy`.") + } + if r.deleteByParams == nil { - return returnValue, reportError("deleteByParams is required and must be specified") + return returnValue, reportError("Parameter `deleteByParams` is required when calling `DeleteBy`.") } // optional params if any @@ -2469,7 +2520,7 @@ func (c *APIClient) DeleteByWithContext(ctx context.Context, r ApiDeleteByReques return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2570,10 +2621,13 @@ func (c *APIClient) DeleteIndexWithContext(ctx context.Context, r ApiDeleteIndex ) requestPath := "/1/indexes/{indexName}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `DeleteIndex`.") + } // optional params if any for _, opt := range opts { @@ -2590,7 +2644,7 @@ func (c *APIClient) DeleteIndexWithContext(ctx context.Context, r ApiDeleteIndex return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2704,11 +2758,17 @@ func (c *APIClient) DeleteObjectWithContext(ctx context.Context, r ApiDeleteObje ) requestPath := "/1/indexes/{indexName}/{objectID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `DeleteObject`.") + } + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `DeleteObject`.") + } // optional params if any for _, opt := range opts { @@ -2725,7 +2785,7 @@ func (c *APIClient) DeleteObjectWithContext(ctx context.Context, r ApiDeleteObje return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2857,13 +2917,19 @@ func (c *APIClient) DeleteRuleWithContext(ctx context.Context, r ApiDeleteRuleRe ) requestPath := "/1/indexes/{indexName}/rules/{objectID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `DeleteRule`.") + } + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `DeleteRule`.") + } - if !isNilorEmpty(r.forwardToReplicas) { + if !utils.IsNilOrEmpty(r.forwardToReplicas) { queryParams.Set("forwardToReplicas", parameterToString(r.forwardToReplicas)) } @@ -2882,7 +2948,7 @@ func (c *APIClient) DeleteRuleWithContext(ctx context.Context, r ApiDeleteRuleRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -2983,10 +3049,13 @@ func (c *APIClient) DeleteSourceWithContext(ctx context.Context, r ApiDeleteSour ) requestPath := "/1/security/sources/{source}" - requestPath = strings.ReplaceAll(requestPath, "{"+"source"+"}", url.PathEscape(parameterToString(r.source))) + requestPath = strings.ReplaceAll(requestPath, "{source}", url.PathEscape(parameterToString(r.source))) headers := make(map[string]string) queryParams := url.Values{} + if r.source == "" { + return returnValue, reportError("Parameter `source` is required when calling `DeleteSource`.") + } // optional params if any for _, opt := range opts { @@ -3003,7 +3072,7 @@ func (c *APIClient) DeleteSourceWithContext(ctx context.Context, r ApiDeleteSour return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3135,13 +3204,19 @@ func (c *APIClient) DeleteSynonymWithContext(ctx context.Context, r ApiDeleteSyn ) requestPath := "/1/indexes/{indexName}/synonyms/{objectID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `DeleteSynonym`.") + } + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `DeleteSynonym`.") + } - if !isNilorEmpty(r.forwardToReplicas) { + if !utils.IsNilOrEmpty(r.forwardToReplicas) { queryParams.Set("forwardToReplicas", parameterToString(r.forwardToReplicas)) } @@ -3160,7 +3235,7 @@ func (c *APIClient) DeleteSynonymWithContext(ctx context.Context, r ApiDeleteSyn return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3263,10 +3338,13 @@ func (c *APIClient) GetApiKeyWithContext(ctx context.Context, r ApiGetApiKeyRequ ) requestPath := "/1/keys/{key}" - requestPath = strings.ReplaceAll(requestPath, "{"+"key"+"}", url.PathEscape(parameterToString(r.key))) + requestPath = strings.ReplaceAll(requestPath, "{key}", url.PathEscape(parameterToString(r.key))) headers := make(map[string]string) queryParams := url.Values{} + if r.key == "" { + return returnValue, reportError("Parameter `key` is required when calling `GetApiKey`.") + } // optional params if any for _, opt := range opts { @@ -3283,7 +3361,7 @@ func (c *APIClient) GetApiKeyWithContext(ctx context.Context, r ApiGetApiKeyRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3370,7 +3448,7 @@ func (c *APIClient) GetDictionaryLanguagesWithContext(ctx context.Context, opts return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3457,7 +3535,7 @@ func (c *APIClient) GetDictionarySettingsWithContext(ctx context.Context, opts . return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3626,16 +3704,16 @@ func (c *APIClient) GetLogsWithContext(ctx context.Context, r ApiGetLogsRequest, headers := make(map[string]string) queryParams := url.Values{} - if !isNilorEmpty(r.offset) { + if !utils.IsNilOrEmpty(r.offset) { queryParams.Set("offset", parameterToString(r.offset)) } - if !isNilorEmpty(r.length) { + if !utils.IsNilOrEmpty(r.length) { queryParams.Set("length", parameterToString(r.length)) } - if !isNilorEmpty(r.indexName) { + if !utils.IsNilOrEmpty(r.indexName) { queryParams.Set("indexName", parameterToString(r.indexName)) } - if !isNilorEmpty(r.type_) { + if !utils.IsNilOrEmpty(r.type_) { queryParams.Set("type", parameterToString(r.type_)) } @@ -3654,7 +3732,7 @@ func (c *APIClient) GetLogsWithContext(ctx context.Context, r ApiGetLogsRequest, return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3786,13 +3864,19 @@ func (c *APIClient) GetObjectWithContext(ctx context.Context, r ApiGetObjectRequ ) requestPath := "/1/indexes/{indexName}/{objectID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `GetObject`.") + } + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `GetObject`.") + } - if !isNilorEmpty(r.attributesToRetrieve) { + if !utils.IsNilOrEmpty(r.attributesToRetrieve) { queryParams.Set("attributesToRetrieve", parameterToString(r.attributesToRetrieve)) } @@ -3811,7 +3895,7 @@ func (c *APIClient) GetObjectWithContext(ctx context.Context, r ApiGetObjectRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -3920,8 +4004,9 @@ func (c *APIClient) GetObjectsWithContext(ctx context.Context, r ApiGetObjectsRe headers := make(map[string]string) queryParams := url.Values{} + if r.getObjectsParams == nil { - return returnValue, reportError("getObjectsParams is required and must be specified") + return returnValue, reportError("Parameter `getObjectsParams` is required when calling `GetObjects`.") } // optional params if any @@ -3941,7 +4026,7 @@ func (c *APIClient) GetObjectsWithContext(ctx context.Context, r ApiGetObjectsRe return returnValue, err } - res, err := c.callAPI(req, call.Read) + res, err := c.callAPI(req, true) if err != nil { return returnValue, err } @@ -4055,11 +4140,17 @@ func (c *APIClient) GetRuleWithContext(ctx context.Context, r ApiGetRuleRequest, ) requestPath := "/1/indexes/{indexName}/rules/{objectID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `GetRule`.") + } + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `GetRule`.") + } // optional params if any for _, opt := range opts { @@ -4076,7 +4167,7 @@ func (c *APIClient) GetRuleWithContext(ctx context.Context, r ApiGetRuleRequest, return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4177,10 +4268,13 @@ func (c *APIClient) GetSettingsWithContext(ctx context.Context, r ApiGetSettings ) requestPath := "/1/indexes/{indexName}/settings" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `GetSettings`.") + } // optional params if any for _, opt := range opts { @@ -4197,7 +4291,7 @@ func (c *APIClient) GetSettingsWithContext(ctx context.Context, r ApiGetSettings return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4284,7 +4378,7 @@ func (c *APIClient) GetSourcesWithContext(ctx context.Context, opts ...Option) ( return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4398,11 +4492,17 @@ func (c *APIClient) GetSynonymWithContext(ctx context.Context, r ApiGetSynonymRe ) requestPath := "/1/indexes/{indexName}/synonyms/{objectID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `GetSynonym`.") + } + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `GetSynonym`.") + } // optional params if any for _, opt := range opts { @@ -4419,7 +4519,7 @@ func (c *APIClient) GetSynonymWithContext(ctx context.Context, r ApiGetSynonymRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4533,11 +4633,14 @@ func (c *APIClient) GetTaskWithContext(ctx context.Context, r ApiGetTaskRequest, ) requestPath := "/1/indexes/{indexName}/task/{taskID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"taskID"+"}", url.PathEscape(parameterToString(r.taskID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{taskID}", url.PathEscape(parameterToString(r.taskID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `GetTask`.") + } // optional params if any for _, opt := range opts { @@ -4554,7 +4657,7 @@ func (c *APIClient) GetTaskWithContext(ctx context.Context, r ApiGetTaskRequest, return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4643,7 +4746,7 @@ func (c *APIClient) GetTopUserIdsWithContext(ctx context.Context, opts ...Option return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4746,10 +4849,13 @@ func (c *APIClient) GetUserIdWithContext(ctx context.Context, r ApiGetUserIdRequ ) requestPath := "/1/clusters/mapping/{userID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"userID"+"}", url.PathEscape(parameterToString(r.userID))) + requestPath = strings.ReplaceAll(requestPath, "{userID}", url.PathEscape(parameterToString(r.userID))) headers := make(map[string]string) queryParams := url.Values{} + if r.userID == "" { + return returnValue, reportError("Parameter `userID` is required when calling `GetUserId`.") + } // optional params if any for _, opt := range opts { @@ -4766,7 +4872,7 @@ func (c *APIClient) GetUserIdWithContext(ctx context.Context, r ApiGetUserIdRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4875,7 +4981,7 @@ func (c *APIClient) HasPendingMappingsWithContext(ctx context.Context, r ApiHasP headers := make(map[string]string) queryParams := url.Values{} - if !isNilorEmpty(r.getClusters) { + if !utils.IsNilOrEmpty(r.getClusters) { queryParams.Set("getClusters", parameterToString(r.getClusters)) } @@ -4894,7 +5000,7 @@ func (c *APIClient) HasPendingMappingsWithContext(ctx context.Context, r ApiHasP return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -4981,7 +5087,7 @@ func (c *APIClient) ListApiKeysWithContext(ctx context.Context, opts ...Option) return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5068,7 +5174,7 @@ func (c *APIClient) ListClustersWithContext(ctx context.Context, opts ...Option) return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5195,10 +5301,10 @@ func (c *APIClient) ListIndicesWithContext(ctx context.Context, r ApiListIndices headers := make(map[string]string) queryParams := url.Values{} - if !isNilorEmpty(r.page) { + if !utils.IsNilOrEmpty(r.page) { queryParams.Set("page", parameterToString(r.page)) } - if !isNilorEmpty(r.hitsPerPage) { + if !utils.IsNilOrEmpty(r.hitsPerPage) { queryParams.Set("hitsPerPage", parameterToString(r.hitsPerPage)) } @@ -5217,7 +5323,7 @@ func (c *APIClient) ListIndicesWithContext(ctx context.Context, r ApiListIndices return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5346,10 +5452,10 @@ func (c *APIClient) ListUserIdsWithContext(ctx context.Context, r ApiListUserIds headers := make(map[string]string) queryParams := url.Values{} - if !isNilorEmpty(r.page) { + if !utils.IsNilOrEmpty(r.page) { queryParams.Set("page", parameterToString(r.page)) } - if !isNilorEmpty(r.hitsPerPage) { + if !utils.IsNilOrEmpty(r.hitsPerPage) { queryParams.Set("hitsPerPage", parameterToString(r.hitsPerPage)) } @@ -5368,7 +5474,7 @@ func (c *APIClient) ListUserIdsWithContext(ctx context.Context, r ApiListUserIds return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5479,8 +5585,9 @@ func (c *APIClient) MultipleBatchWithContext(ctx context.Context, r ApiMultipleB headers := make(map[string]string) queryParams := url.Values{} + if r.batchParams == nil { - return returnValue, reportError("batchParams is required and must be specified") + return returnValue, reportError("Parameter `batchParams` is required when calling `MultipleBatch`.") } // optional params if any @@ -5500,7 +5607,7 @@ func (c *APIClient) MultipleBatchWithContext(ctx context.Context, r ApiMultipleB return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5637,12 +5744,16 @@ func (c *APIClient) OperationIndexWithContext(ctx context.Context, r ApiOperatio ) requestPath := "/1/indexes/{indexName}/operation" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `OperationIndex`.") + } + if r.operationIndexParams == nil { - return returnValue, reportError("operationIndexParams is required and must be specified") + return returnValue, reportError("Parameter `operationIndexParams` is required when calling `OperationIndex`.") } // optional params if any @@ -5662,7 +5773,7 @@ func (c *APIClient) OperationIndexWithContext(ctx context.Context, r ApiOperatio return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5814,16 +5925,26 @@ func (c *APIClient) PartialUpdateObjectWithContext(ctx context.Context, r ApiPar ) requestPath := "/1/indexes/{indexName}/{objectID}/partial" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} - if r.attributesToUpdate == nil { - return returnValue, reportError("attributesToUpdate is required and must be specified") + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `PartialUpdateObject`.") + } + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `PartialUpdateObject`.") } - if !isNilorEmpty(r.createIfNotExists) { + if len(r.attributesToUpdate) == 0 { + return returnValue, reportError("Parameter `attributesToUpdate` is required when calling `PartialUpdateObject`.") + } + if len(r.attributesToUpdate) == 0 { + return returnValue, reportError("Parameter `attributesToUpdate` is required when calling `PartialUpdateObject`.") + } + + if !utils.IsNilOrEmpty(r.createIfNotExists) { queryParams.Set("createIfNotExists", parameterToString(r.createIfNotExists)) } @@ -5844,7 +5965,7 @@ func (c *APIClient) PartialUpdateObjectWithContext(ctx context.Context, r ApiPar return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -5945,10 +6066,13 @@ func (c *APIClient) RemoveUserIdWithContext(ctx context.Context, r ApiRemoveUser ) requestPath := "/1/clusters/mapping/{userID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"userID"+"}", url.PathEscape(parameterToString(r.userID))) + requestPath = strings.ReplaceAll(requestPath, "{userID}", url.PathEscape(parameterToString(r.userID))) headers := make(map[string]string) queryParams := url.Values{} + if r.userID == "" { + return returnValue, reportError("Parameter `userID` is required when calling `RemoveUserId`.") + } // optional params if any for _, opt := range opts { @@ -5965,7 +6089,7 @@ func (c *APIClient) RemoveUserIdWithContext(ctx context.Context, r ApiRemoveUser return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -6074,8 +6198,9 @@ func (c *APIClient) ReplaceSourcesWithContext(ctx context.Context, r ApiReplaceS headers := make(map[string]string) queryParams := url.Values{} - if r.source == nil { - return returnValue, reportError("source is required and must be specified") + + if len(r.source) == 0 { + return returnValue, reportError("Parameter `source` is required when calling `ReplaceSources`.") } // optional params if any @@ -6095,7 +6220,7 @@ func (c *APIClient) ReplaceSourcesWithContext(ctx context.Context, r ApiReplaceS return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -6198,10 +6323,13 @@ func (c *APIClient) RestoreApiKeyWithContext(ctx context.Context, r ApiRestoreAp ) requestPath := "/1/keys/{key}/restore" - requestPath = strings.ReplaceAll(requestPath, "{"+"key"+"}", url.PathEscape(parameterToString(r.key))) + requestPath = strings.ReplaceAll(requestPath, "{key}", url.PathEscape(parameterToString(r.key))) headers := make(map[string]string) queryParams := url.Values{} + if r.key == "" { + return returnValue, reportError("Parameter `key` is required when calling `RestoreApiKey`.") + } // optional params if any for _, opt := range opts { @@ -6218,7 +6346,7 @@ func (c *APIClient) RestoreApiKeyWithContext(ctx context.Context, r ApiRestoreAp return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -6343,10 +6471,17 @@ func (c *APIClient) SaveObjectWithContext(ctx context.Context, r ApiSaveObjectRe ) requestPath := "/1/indexes/{indexName}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `SaveObject`.") + } + + if len(r.body) == 0 { + return returnValue, reportError("Parameter `body` is required when calling `SaveObject`.") + } // optional params if any for _, opt := range opts { @@ -6365,7 +6500,7 @@ func (c *APIClient) SaveObjectWithContext(ctx context.Context, r ApiSaveObjectRe return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -6515,16 +6650,23 @@ func (c *APIClient) SaveRuleWithContext(ctx context.Context, r ApiSaveRuleReques ) requestPath := "/1/indexes/{indexName}/rules/{objectID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `SaveRule`.") + } + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `SaveRule`.") + } + if r.rule == nil { - return returnValue, reportError("rule is required and must be specified") + return returnValue, reportError("Parameter `rule` is required when calling `SaveRule`.") } - if !isNilorEmpty(r.forwardToReplicas) { + if !utils.IsNilOrEmpty(r.forwardToReplicas) { queryParams.Set("forwardToReplicas", parameterToString(r.forwardToReplicas)) } @@ -6545,7 +6687,7 @@ func (c *APIClient) SaveRuleWithContext(ctx context.Context, r ApiSaveRuleReques return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -6700,18 +6842,22 @@ func (c *APIClient) SaveRulesWithContext(ctx context.Context, r ApiSaveRulesRequ ) requestPath := "/1/indexes/{indexName}/rules/batch" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} - if r.rules == nil { - return returnValue, reportError("rules is required and must be specified") + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `SaveRules`.") + } + + if len(r.rules) == 0 { + return returnValue, reportError("Parameter `rules` is required when calling `SaveRules`.") } - if !isNilorEmpty(r.forwardToReplicas) { + if !utils.IsNilOrEmpty(r.forwardToReplicas) { queryParams.Set("forwardToReplicas", parameterToString(r.forwardToReplicas)) } - if !isNilorEmpty(r.clearExistingRules) { + if !utils.IsNilOrEmpty(r.clearExistingRules) { queryParams.Set("clearExistingRules", parameterToString(r.clearExistingRules)) } @@ -6732,7 +6878,7 @@ func (c *APIClient) SaveRulesWithContext(ctx context.Context, r ApiSaveRulesRequ return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -6888,16 +7034,23 @@ func (c *APIClient) SaveSynonymWithContext(ctx context.Context, r ApiSaveSynonym ) requestPath := "/1/indexes/{indexName}/synonyms/{objectID}" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"objectID"+"}", url.PathEscape(parameterToString(r.objectID))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{objectID}", url.PathEscape(parameterToString(r.objectID))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `SaveSynonym`.") + } + if r.objectID == "" { + return returnValue, reportError("Parameter `objectID` is required when calling `SaveSynonym`.") + } + if r.synonymHit == nil { - return returnValue, reportError("synonymHit is required and must be specified") + return returnValue, reportError("Parameter `synonymHit` is required when calling `SaveSynonym`.") } - if !isNilorEmpty(r.forwardToReplicas) { + if !utils.IsNilOrEmpty(r.forwardToReplicas) { queryParams.Set("forwardToReplicas", parameterToString(r.forwardToReplicas)) } @@ -6918,7 +7071,7 @@ func (c *APIClient) SaveSynonymWithContext(ctx context.Context, r ApiSaveSynonym return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -7073,18 +7226,22 @@ func (c *APIClient) SaveSynonymsWithContext(ctx context.Context, r ApiSaveSynony ) requestPath := "/1/indexes/{indexName}/synonyms/batch" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} - if r.synonymHit == nil { - return returnValue, reportError("synonymHit is required and must be specified") + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `SaveSynonyms`.") } - if !isNilorEmpty(r.forwardToReplicas) { + if len(r.synonymHit) == 0 { + return returnValue, reportError("Parameter `synonymHit` is required when calling `SaveSynonyms`.") + } + + if !utils.IsNilOrEmpty(r.forwardToReplicas) { queryParams.Set("forwardToReplicas", parameterToString(r.forwardToReplicas)) } - if !isNilorEmpty(r.replaceExistingSynonyms) { + if !utils.IsNilOrEmpty(r.replaceExistingSynonyms) { queryParams.Set("replaceExistingSynonyms", parameterToString(r.replaceExistingSynonyms)) } @@ -7105,7 +7262,7 @@ func (c *APIClient) SaveSynonymsWithContext(ctx context.Context, r ApiSaveSynony return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -7214,8 +7371,9 @@ func (c *APIClient) SearchWithContext(ctx context.Context, r ApiSearchRequest, o headers := make(map[string]string) queryParams := url.Values{} + if r.searchMethodParams == nil { - return returnValue, reportError("searchMethodParams is required and must be specified") + return returnValue, reportError("Parameter `searchMethodParams` is required when calling `Search`.") } // optional params if any @@ -7235,7 +7393,7 @@ func (c *APIClient) SearchWithContext(ctx context.Context, r ApiSearchRequest, o return returnValue, err } - res, err := c.callAPI(req, call.Read) + res, err := c.callAPI(req, true) if err != nil { return returnValue, err } @@ -7354,12 +7512,13 @@ func (c *APIClient) SearchDictionaryEntriesWithContext(ctx context.Context, r Ap ) requestPath := "/1/dictionaries/{dictionaryName}/search" - requestPath = strings.ReplaceAll(requestPath, "{"+"dictionaryName"+"}", url.PathEscape(parameterToString(r.dictionaryName))) + requestPath = strings.ReplaceAll(requestPath, "{dictionaryName}", url.PathEscape(parameterToString(r.dictionaryName))) headers := make(map[string]string) queryParams := url.Values{} + if r.searchDictionaryEntriesParams == nil { - return returnValue, reportError("searchDictionaryEntriesParams is required and must be specified") + return returnValue, reportError("Parameter `searchDictionaryEntriesParams` is required when calling `SearchDictionaryEntries`.") } // optional params if any @@ -7379,7 +7538,7 @@ func (c *APIClient) SearchDictionaryEntriesWithContext(ctx context.Context, r Ap return returnValue, err } - res, err := c.callAPI(req, call.Read) + res, err := c.callAPI(req, true) if err != nil { return returnValue, err } @@ -7513,11 +7672,17 @@ func (c *APIClient) SearchForFacetValuesWithContext(ctx context.Context, r ApiSe ) requestPath := "/1/indexes/{indexName}/facets/{facetName}/query" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) - requestPath = strings.ReplaceAll(requestPath, "{"+"facetName"+"}", url.PathEscape(parameterToString(r.facetName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{facetName}", url.PathEscape(parameterToString(r.facetName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `SearchForFacetValues`.") + } + if r.facetName == "" { + return returnValue, reportError("Parameter `facetName` is required when calling `SearchForFacetValues`.") + } // optional params if any for _, opt := range opts { @@ -7530,7 +7695,7 @@ func (c *APIClient) SearchForFacetValuesWithContext(ctx context.Context, r ApiSe } // body params - if isNilorEmpty(r.searchForFacetValuesRequest) { + if utils.IsNilOrEmpty(r.searchForFacetValuesRequest) { postBody = "{}" } else { postBody = r.searchForFacetValuesRequest @@ -7540,7 +7705,7 @@ func (c *APIClient) SearchForFacetValuesWithContext(ctx context.Context, r ApiSe return returnValue, err } - res, err := c.callAPI(req, call.Read) + res, err := c.callAPI(req, true) if err != nil { return returnValue, err } @@ -7659,10 +7824,13 @@ func (c *APIClient) SearchRulesWithContext(ctx context.Context, r ApiSearchRules ) requestPath := "/1/indexes/{indexName}/rules/search" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `SearchRules`.") + } // optional params if any for _, opt := range opts { @@ -7675,7 +7843,7 @@ func (c *APIClient) SearchRulesWithContext(ctx context.Context, r ApiSearchRules } // body params - if isNilorEmpty(r.searchRulesParams) { + if utils.IsNilOrEmpty(r.searchRulesParams) { postBody = "{}" } else { postBody = r.searchRulesParams @@ -7685,7 +7853,7 @@ func (c *APIClient) SearchRulesWithContext(ctx context.Context, r ApiSearchRules return returnValue, err } - res, err := c.callAPI(req, call.Read) + res, err := c.callAPI(req, true) if err != nil { return returnValue, err } @@ -7804,10 +7972,13 @@ func (c *APIClient) SearchSingleIndexWithContext(ctx context.Context, r ApiSearc ) requestPath := "/1/indexes/{indexName}/query" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `SearchSingleIndex`.") + } // optional params if any for _, opt := range opts { @@ -7820,7 +7991,7 @@ func (c *APIClient) SearchSingleIndexWithContext(ctx context.Context, r ApiSearc } // body params - if isNilorEmpty(r.searchParams) { + if utils.IsNilOrEmpty(r.searchParams) { postBody = "{}" } else { postBody = r.searchParams @@ -7830,7 +8001,7 @@ func (c *APIClient) SearchSingleIndexWithContext(ctx context.Context, r ApiSearc return returnValue, err } - res, err := c.callAPI(req, call.Read) + res, err := c.callAPI(req, true) if err != nil { return returnValue, err } @@ -8003,18 +8174,21 @@ func (c *APIClient) SearchSynonymsWithContext(ctx context.Context, r ApiSearchSy ) requestPath := "/1/indexes/{indexName}/synonyms/search" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `SearchSynonyms`.") + } - if !isNilorEmpty(r.type_) { + if !utils.IsNilOrEmpty(r.type_) { queryParams.Set("type", parameterToString(r.type_)) } - if !isNilorEmpty(r.page) { + if !utils.IsNilOrEmpty(r.page) { queryParams.Set("page", parameterToString(r.page)) } - if !isNilorEmpty(r.hitsPerPage) { + if !utils.IsNilOrEmpty(r.hitsPerPage) { queryParams.Set("hitsPerPage", parameterToString(r.hitsPerPage)) } @@ -8029,7 +8203,7 @@ func (c *APIClient) SearchSynonymsWithContext(ctx context.Context, r ApiSearchSy } // body params - if isNilorEmpty(r.searchSynonymsParams) { + if utils.IsNilOrEmpty(r.searchSynonymsParams) { postBody = "{}" } else { postBody = r.searchSynonymsParams @@ -8039,7 +8213,7 @@ func (c *APIClient) SearchSynonymsWithContext(ctx context.Context, r ApiSearchSy return returnValue, err } - res, err := c.callAPI(req, call.Read) + res, err := c.callAPI(req, true) if err != nil { return returnValue, err } @@ -8150,8 +8324,9 @@ func (c *APIClient) SearchUserIdsWithContext(ctx context.Context, r ApiSearchUse headers := make(map[string]string) queryParams := url.Values{} + if r.searchUserIdsParams == nil { - return returnValue, reportError("searchUserIdsParams is required and must be specified") + return returnValue, reportError("Parameter `searchUserIdsParams` is required when calling `SearchUserIds`.") } // optional params if any @@ -8171,7 +8346,7 @@ func (c *APIClient) SearchUserIdsWithContext(ctx context.Context, r ApiSearchUse return returnValue, err } - res, err := c.callAPI(req, call.Read) + res, err := c.callAPI(req, true) if err != nil { return returnValue, err } @@ -8280,8 +8455,9 @@ func (c *APIClient) SetDictionarySettingsWithContext(ctx context.Context, r ApiS headers := make(map[string]string) queryParams := url.Values{} + if r.dictionarySettingsParams == nil { - return returnValue, reportError("dictionarySettingsParams is required and must be specified") + return returnValue, reportError("Parameter `dictionarySettingsParams` is required when calling `SetDictionarySettings`.") } // optional params if any @@ -8301,7 +8477,7 @@ func (c *APIClient) SetDictionarySettingsWithContext(ctx context.Context, r ApiS return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -8438,15 +8614,19 @@ func (c *APIClient) SetSettingsWithContext(ctx context.Context, r ApiSetSettings ) requestPath := "/1/indexes/{indexName}/settings" - requestPath = strings.ReplaceAll(requestPath, "{"+"indexName"+"}", url.PathEscape(parameterToString(r.indexName))) + requestPath = strings.ReplaceAll(requestPath, "{indexName}", url.PathEscape(parameterToString(r.indexName))) headers := make(map[string]string) queryParams := url.Values{} + if r.indexName == "" { + return returnValue, reportError("Parameter `indexName` is required when calling `SetSettings`.") + } + if r.indexSettings == nil { - return returnValue, reportError("indexSettings is required and must be specified") + return returnValue, reportError("Parameter `indexSettings` is required when calling `SetSettings`.") } - if !isNilorEmpty(r.forwardToReplicas) { + if !utils.IsNilOrEmpty(r.forwardToReplicas) { queryParams.Set("forwardToReplicas", parameterToString(r.forwardToReplicas)) } @@ -8467,7 +8647,7 @@ func (c *APIClient) SetSettingsWithContext(ctx context.Context, r ApiSetSettings return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -8590,12 +8770,16 @@ func (c *APIClient) UpdateApiKeyWithContext(ctx context.Context, r ApiUpdateApiK ) requestPath := "/1/keys/{key}" - requestPath = strings.ReplaceAll(requestPath, "{"+"key"+"}", url.PathEscape(parameterToString(r.key))) + requestPath = strings.ReplaceAll(requestPath, "{key}", url.PathEscape(parameterToString(r.key))) headers := make(map[string]string) queryParams := url.Values{} + if r.key == "" { + return returnValue, reportError("Parameter `key` is required when calling `UpdateApiKey`.") + } + if r.apiKey == nil { - return returnValue, reportError("apiKey is required and must be specified") + return returnValue, reportError("Parameter `apiKey` is required when calling `UpdateApiKey`.") } // optional params if any @@ -8615,7 +8799,7 @@ func (c *APIClient) UpdateApiKeyWithContext(ctx context.Context, r ApiUpdateApiK return returnValue, err } - res, err := c.callAPI(req, call.Write) + res, err := c.callAPI(req, false) if err != nil { return returnValue, err } @@ -8720,7 +8904,7 @@ func (c *APIClient) WaitForTaskWithContext( maxDelay *time.Duration, opts ...Option, ) (*GetTaskResponse, error) { - return RetryUntil( + return utils.RetryUntil( func() (*GetTaskResponse, error) { return c.GetTaskWithContext(ctx, c.NewApiGetTaskRequest(indexName, taskID), opts...) }, @@ -8833,7 +9017,7 @@ func (c *APIClient) WaitForApiKeyWithContext( return nil, &errs.WaitKeyUpdateError{} } - return RetryUntil( + return utils.RetryUntil( func() (*GetApiKeyResponse, error) { return c.GetApiKeyWithContext(ctx, c.NewApiGetApiKeyRequest(key), opts...) }, @@ -8891,7 +9075,7 @@ func (c *APIClient) WaitForApiKeyWithContext( ) } - return RetryUntil( + return utils.RetryUntil( func() (*GetApiKeyResponse, error) { return c.GetApiKeyWithContext(ctx, c.NewApiGetApiKeyRequest(key), opts...) }, diff --git a/clients/algoliasearch-client-go/algolia/search/client.go b/clients/algoliasearch-client-go/algolia/search/client.go index d90011ed2d..75bc7f6a2a 100644 --- a/clients/algoliasearch-client-go/algolia/search/client.go +++ b/clients/algoliasearch-client-go/algolia/search/client.go @@ -23,7 +23,7 @@ import ( "github.com/algolia/algoliasearch-client-go/v4/algolia/call" "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/transport" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) var jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) @@ -37,26 +37,28 @@ type APIClient struct { } // NewClient creates a new API client with appID and apiKey. -func NewClient(appID, apiKey string) *APIClient { +func NewClient(appID, apiKey string) (*APIClient, error) { return NewClientWithConfig(Configuration{ - AppID: appID, - ApiKey: apiKey, - DefaultHeader: make(map[string]string), - UserAgent: getUserAgent(), - Debug: false, - Requester: newDefaultRequester(), + Configuration: transport.Configuration{ + AppID: appID, + ApiKey: apiKey, + DefaultHeader: make(map[string]string), + UserAgent: getUserAgent(), + Debug: false, + Requester: transport.NewDefaultRequester(nil), + }, }) } // NewClientWithConfig creates a new API client with the given configuration to fully customize the client behaviour. -func NewClientWithConfig(cfg Configuration) *APIClient { +func NewClientWithConfig(cfg Configuration) (*APIClient, error) { var hosts []*transport.StatefulHost if cfg.AppID == "" { - panic("appID is required") + return nil, errors.New("`appId` is missing.") } if cfg.ApiKey == "" { - panic("apiKey is required") + return nil, errors.New("`apiKey` is missing.") } if len(cfg.Hosts) == 0 { hosts = getDefaultHosts(cfg.AppID) @@ -66,7 +68,7 @@ func NewClientWithConfig(cfg Configuration) *APIClient { } } if cfg.Requester == nil { - cfg.Requester = newDefaultRequester() + cfg.Requester = transport.NewDefaultRequester(&cfg.ConnectTimeout) } if cfg.UserAgent == "" { cfg.UserAgent = getUserAgent() @@ -80,9 +82,10 @@ func NewClientWithConfig(cfg Configuration) *APIClient { cfg.Requester, cfg.ReadTimeout, cfg.WriteTimeout, + cfg.ConnectTimeout, cfg.Compression, ), - } + }, nil } func getDefaultHosts(appID string) []*transport.StatefulHost { @@ -121,7 +124,7 @@ func (c *APIClient) AddDefaultHeader(key string, value string) { } // callAPI do the request. -func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Response, error) { +func (c *APIClient) callAPI(request *http.Request, useReadTransporter bool) (*http.Response, error) { if c.cfg.Debug { dump, err := httputil.DumpRequestOut(request, true) if err != nil { @@ -130,7 +133,12 @@ func (c *APIClient) callAPI(request *http.Request, kind call.Kind) (*http.Respon log.Printf("\n%s\n", string(dump)) } - resp, err := c.transport.Request(request.Context(), request, kind) + callKind := call.Write + if useReadTransporter || request.Method == http.MethodGet { + callKind = call.Read + } + + resp, err := c.transport.Request(request.Context(), request, callKind) if err != nil { return nil, err } diff --git a/clients/algoliasearch-client-go/algolia/search/configuration.go b/clients/algoliasearch-client-go/algolia/search/configuration.go index 60acfc3938..9cf984dab0 100644 --- a/clients/algoliasearch-client-go/algolia/search/configuration.go +++ b/clients/algoliasearch-client-go/algolia/search/configuration.go @@ -2,41 +2,10 @@ package search import ( - "net/http" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/compression" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -type Requester interface { - Request(*http.Request) (*http.Response, error) -} - -type defaultRequester struct { - client *http.Client -} - -func newDefaultRequester() *defaultRequester { - return &defaultRequester{ - client: http.DefaultClient, - } -} - -func (r *defaultRequester) Request(req *http.Request) (*http.Response, error) { - return r.client.Do(req) -} - // Configuration stores the configuration of the API client. type Configuration struct { - AppID string - ApiKey string - - Hosts []string `json:"host,omitempty"` - DefaultHeader map[string]string `json:"defaultHeader,omitempty"` - UserAgent string `json:"userAgent,omitempty"` - Debug bool `json:"debug,omitempty"` - Requester Requester - ReadTimeout time.Duration - WriteTimeout time.Duration - Compression compression.Compression + transport.Configuration } diff --git a/clients/algoliasearch-client-go/algolia/search/model_search_rules_params.go b/clients/algoliasearch-client-go/algolia/search/model_search_rules_params.go index 2d7b296cc7..54d7bbe93d 100644 --- a/clients/algoliasearch-client-go/algolia/search/model_search_rules_params.go +++ b/clients/algoliasearch-client-go/algolia/search/model_search_rules_params.go @@ -4,6 +4,8 @@ package search import ( "encoding/json" "fmt" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/utils" ) // SearchRulesParams Rules search parameters. @@ -18,7 +20,7 @@ type SearchRulesParams struct { // Maximum number of hits per page. HitsPerPage *int32 `json:"hitsPerPage,omitempty"` // Restricts responses to enabled rules. When not specified (default), _all_ rules are retrieved. - Enabled NullableBool `json:"enabled,omitempty"` + Enabled utils.NullableBool `json:"enabled,omitempty"` // Request options to send with the API call. RequestOptions []map[string]interface{} `json:"requestOptions,omitempty"` } @@ -55,7 +57,7 @@ func WithSearchRulesParamsHitsPerPage(val int32) SearchRulesParamsOption { } } -func WithSearchRulesParamsEnabled(val NullableBool) SearchRulesParamsOption { +func WithSearchRulesParamsEnabled(val utils.NullableBool) SearchRulesParamsOption { return func(f *SearchRulesParams) { f.Enabled = val } @@ -277,7 +279,7 @@ func (o *SearchRulesParams) HasEnabled() bool { return false } -// SetEnabled gets a reference to the given NullableBool and assigns it to the Enabled field. +// SetEnabled gets a reference to the given utils.NullableBool and assigns it to the Enabled field. func (o *SearchRulesParams) SetEnabled(v bool) *SearchRulesParams { o.Enabled.Set(&v) return o diff --git a/clients/algoliasearch-client-go/algolia/search/response.go b/clients/algoliasearch-client-go/algolia/search/response.go deleted file mode 100644 index 73f2ad56ff..0000000000 --- a/clients/algoliasearch-client-go/algolia/search/response.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Search API - -Use the Search REST API to manage your data (indices and records), implement search, and improve relevance (with Rules, synonyms, and language dictionaries). Although Algolia provides a REST API, you should use the official open source API [clients, libraries, and tools](https://www.algolia.com/doc/guides/getting-started/how-algolia-works/in-depth/ecosystem/) instead. There's no [SLA](https://www.algolia.com/policies/sla/) if you use the REST API directly. - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package search - -import ( - "net/http" -) - -// APIResponse stores the API response returned by the server. -type APIResponse struct { - *http.Response `json:"-"` - Message string `json:"message,omitempty"` - // Operation is the name of the OpenAPI operation. - Operation string `json:"operation,omitempty"` - // RequestURL is the request URL. This value is always available, even if the - // embedded *http.Response is nil. - RequestURL string `json:"url,omitempty"` - // Method is the HTTP method used for the request. This value is always - // available, even if the embedded *http.Response is nil. - Method string `json:"method,omitempty"` - // Payload holds the contents of the response body (which may be nil or empty). - // This is provided here as the raw response.Body() reader will have already - // been drained. - Payload []byte `json:"-"` -} - -// NewAPIResponse returns a new APIResponse object. -func NewAPIResponse(r *http.Response) *APIResponse { - - response := &APIResponse{Response: r} - return response -} - -// NewAPIResponseWithError returns a new APIResponse object with the provided error message. -func NewAPIResponseWithError(errorMessage string) *APIResponse { - - response := &APIResponse{Message: errorMessage} - return response -} diff --git a/clients/algoliasearch-client-go/algolia/search/utils.go b/clients/algoliasearch-client-go/algolia/search/utils.go deleted file mode 100644 index d72428383f..0000000000 --- a/clients/algoliasearch-client-go/algolia/search/utils.go +++ /dev/null @@ -1,385 +0,0 @@ -/* -Search API - -Use the Search REST API to manage your data (indices and records), implement search, and improve relevance (with Rules, synonyms, and language dictionaries). Although Algolia provides a REST API, you should use the official open source API [clients, libraries, and tools](https://www.algolia.com/doc/guides/getting-started/how-algolia-works/in-depth/ecosystem/) instead. There's no [SLA](https://www.algolia.com/policies/sla/) if you use the REST API directly. - -API version: 1.0.0 -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package search - -import ( - "encoding/json" - "reflect" - "time" - - "github.com/algolia/algoliasearch-client-go/v4/algolia/internal/errs" -) - -// PtrBool is a helper routine that returns a pointer to given boolean value. -func PtrBool(v bool) *bool { return &v } - -// PtrInt is a helper routine that returns a pointer to given integer value. -func PtrInt(v int) *int { return &v } - -// PtrInt32 is a helper routine that returns a pointer to given integer value. -func PtrInt32(v int32) *int32 { return &v } - -// PtrInt64 is a helper routine that returns a pointer to given integer value. -func PtrInt64(v int64) *int64 { return &v } - -// PtrFloat32 is a helper routine that returns a pointer to given float value. -func PtrFloat32(v float32) *float32 { return &v } - -// PtrFloat64 is a helper routine that returns a pointer to given float value. -func PtrFloat64(v float64) *float64 { return &v } - -// PtrString is a helper routine that returns a pointer to given string value. -func PtrString(v string) *string { return &v } - -// PtrTime is helper routine that returns a pointer to given Time value. -func PtrTime(v time.Time) *time.Time { return &v } - -type NullableBool struct { - value *bool - isSet bool -} - -func (v NullableBool) Get() *bool { - return v.value -} - -func (v *NullableBool) Set(val *bool) { - v.value = val - v.isSet = true -} - -func (v NullableBool) IsSet() bool { - return v.isSet -} - -func (v *NullableBool) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableBool(val *bool) *NullableBool { - return &NullableBool{value: val, isSet: true} -} - -func (v NullableBool) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableBool) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt struct { - value *int - isSet bool -} - -func (v NullableInt) Get() *int { - return v.value -} - -func (v *NullableInt) Set(val *int) { - v.value = val - v.isSet = true -} - -func (v NullableInt) IsSet() bool { - return v.isSet -} - -func (v *NullableInt) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt(val *int) *NullableInt { - return &NullableInt{value: val, isSet: true} -} - -func (v NullableInt) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt32 struct { - value *int32 - isSet bool -} - -func (v NullableInt32) Get() *int32 { - return v.value -} - -func (v *NullableInt32) Set(val *int32) { - v.value = val - v.isSet = true -} - -func (v NullableInt32) IsSet() bool { - return v.isSet -} - -func (v *NullableInt32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt32(val *int32) *NullableInt32 { - return &NullableInt32{value: val, isSet: true} -} - -func (v NullableInt32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableInt64 struct { - value *int64 - isSet bool -} - -func (v NullableInt64) Get() *int64 { - return v.value -} - -func (v *NullableInt64) Set(val *int64) { - v.value = val - v.isSet = true -} - -func (v NullableInt64) IsSet() bool { - return v.isSet -} - -func (v *NullableInt64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableInt64(val *int64) *NullableInt64 { - return &NullableInt64{value: val, isSet: true} -} - -func (v NullableInt64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableInt64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat32 struct { - value *float32 - isSet bool -} - -func (v NullableFloat32) Get() *float32 { - return v.value -} - -func (v *NullableFloat32) Set(val *float32) { - v.value = val - v.isSet = true -} - -func (v NullableFloat32) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat32) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat32(val *float32) *NullableFloat32 { - return &NullableFloat32{value: val, isSet: true} -} - -func (v NullableFloat32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableFloat64 struct { - value *float64 - isSet bool -} - -func (v NullableFloat64) Get() *float64 { - return v.value -} - -func (v *NullableFloat64) Set(val *float64) { - v.value = val - v.isSet = true -} - -func (v NullableFloat64) IsSet() bool { - return v.isSet -} - -func (v *NullableFloat64) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableFloat64(val *float64) *NullableFloat64 { - return &NullableFloat64{value: val, isSet: true} -} - -func (v NullableFloat64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableFloat64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableString struct { - value *string - isSet bool -} - -func (v NullableString) Get() *string { - return v.value -} - -func (v *NullableString) Set(val *string) { - v.value = val - v.isSet = true -} - -func (v NullableString) IsSet() bool { - return v.isSet -} - -func (v *NullableString) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableString(val *string) *NullableString { - return &NullableString{value: val, isSet: true} -} - -func (v NullableString) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableString) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -type NullableTime struct { - value *time.Time - isSet bool -} - -func (v NullableTime) Get() *time.Time { - return v.value -} - -func (v *NullableTime) Set(val *time.Time) { - v.value = val - v.isSet = true -} - -func (v NullableTime) IsSet() bool { - return v.isSet -} - -func (v *NullableTime) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableTime(val *time.Time) *NullableTime { - return &NullableTime{value: val, isSet: true} -} - -func (v NullableTime) MarshalJSON() ([]byte, error) { - return v.value.MarshalJSON() -} - -func (v *NullableTime) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// isNilorEmpty checks if an input is nil or empty -func isNilorEmpty(i any) bool { - if i == nil { - return true - } - switch reflect.TypeOf(i).Kind() { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: - return reflect.ValueOf(i).IsNil() - case reflect.Bool: - return false - default: - return reflect.ValueOf(i).IsZero() - } -} - -func RetryUntil[T any]( - retry func() (*T, error), - until func(*T, error) bool, - maxRetries *int, - initialDelay *time.Duration, - maxDelay *time.Duration, -) (*T, error) { - if maxRetries == nil { - maxRetries = new(int) - *maxRetries = 50 - } - - if initialDelay == nil { - initialDelay = new(time.Duration) - *initialDelay = 200 * time.Millisecond - } - - if maxDelay == nil { - maxDelay = new(time.Duration) - *maxDelay = 5 * time.Second - } - - for i := 0; i < *maxRetries; i++ { - res, err := retry() - - if ok := until(res, err); ok { - return res, nil - } - - time.Sleep(*initialDelay) - *initialDelay *= 2 - if *initialDelay > *maxDelay { - *initialDelay = *maxDelay - } - } - - return nil, &errs.WaitError{} -} diff --git a/tests/output/go/go.sum b/tests/output/go/go.sum index 51d4c9244b..7e95708b3e 100644 --- a/tests/output/go/go.sum +++ b/tests/output/go/go.sum @@ -4,6 +4,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= diff --git a/tests/output/go/tests/client/abtesting_test.go b/tests/output/go/tests/client/abtesting_test.go new file mode 100644 index 0000000000..4fef180af0 --- /dev/null +++ b/tests/output/go/tests/client/abtesting_test.go @@ -0,0 +1,135 @@ +package client + +import ( + "regexp" + "testing" + + "github.com/stretchr/testify/require" + + "gotests/tests" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/abtesting" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" +) + +func createAbtestingClient(t *testing.T) (*abtesting.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} + cfg := abtesting.Configuration{ + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: abtesting.US, + } + client, err := abtesting.NewClientWithConfig(cfg) + require.NoError(t, err) + + return client, echo +} + +func TestAbtestingcommonApi0(t *testing.T) { + var err error + client, echo := createAbtestingClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Regexp(t, regexp.MustCompile(`^Algolia for Go \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Abtesting (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$`), echo.Header.Get("User-Agent")) +} + +func TestAbtestingcommonApi1(t *testing.T) { + var err error + client, echo := createAbtestingClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(5000), echo.Timeout.Milliseconds()) +} + +func TestAbtestingcommonApi2(t *testing.T) { + var err error + client, echo := createAbtestingClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(30000), echo.Timeout.Milliseconds()) +} + +func TestAbtestingparameters0(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *abtesting.APIClient + var cfg abtesting.Configuration + _ = client + require.NoError(t, err) + cfg = abtesting.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + } + client, err = abtesting.NewClientWithConfig(cfg) + + require.NoError(t, err) + _, err = client.GetABTest(client.NewApiGetABTestRequest( + 123, + )) + + require.Equal(t, "analytics.algolia.com", echo.Host) +} + +func TestAbtestingparameters1(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *abtesting.APIClient + var cfg abtesting.Configuration + _ = client + require.NoError(t, err) + cfg = abtesting.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: abtesting.Region("us"), + } + client, err = abtesting.NewClientWithConfig(cfg) + + require.NoError(t, err) + _, err = client.GetABTest(client.NewApiGetABTestRequest( + 123, + )) + + require.Equal(t, "analytics.us.algolia.com", echo.Host) +} + +func TestAbtestingparameters2(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *abtesting.APIClient + var cfg abtesting.Configuration + _ = client + cfg = abtesting.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: abtesting.Region("not_a_region"), + } + client, err = abtesting.NewClientWithConfig(cfg) + + require.EqualError(t, err, "`region` must be one of the following: de, us") +} diff --git a/tests/output/go/tests/client/analytics_test.go b/tests/output/go/tests/client/analytics_test.go new file mode 100644 index 0000000000..51bdebbb65 --- /dev/null +++ b/tests/output/go/tests/client/analytics_test.go @@ -0,0 +1,146 @@ +package client + +import ( + "regexp" + "testing" + + "github.com/stretchr/testify/require" + + "gotests/tests" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/analytics" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" +) + +func createAnalyticsClient(t *testing.T) (*analytics.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} + cfg := analytics.Configuration{ + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: analytics.US, + } + client, err := analytics.NewClientWithConfig(cfg) + require.NoError(t, err) + + return client, echo +} + +func TestAnalyticscommonApi0(t *testing.T) { + var err error + client, echo := createAnalyticsClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Regexp(t, regexp.MustCompile(`^Algolia for Go \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Analytics (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$`), echo.Header.Get("User-Agent")) +} + +func TestAnalyticscommonApi1(t *testing.T) { + var err error + client, echo := createAnalyticsClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(5000), echo.Timeout.Milliseconds()) +} + +func TestAnalyticscommonApi2(t *testing.T) { + var err error + client, echo := createAnalyticsClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(30000), echo.Timeout.Milliseconds()) +} + +func TestAnalyticsparameters0(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *analytics.APIClient + var cfg analytics.Configuration + _ = client + require.NoError(t, err) + cfg = analytics.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + } + client, err = analytics.NewClientWithConfig(cfg) + + require.NoError(t, err) + _, err = client.GetAverageClickPosition(client.NewApiGetAverageClickPositionRequest( + "my-index", + )) + + require.Equal(t, "analytics.algolia.com", echo.Host) +} + +func TestAnalyticsparameters1(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *analytics.APIClient + var cfg analytics.Configuration + _ = client + require.NoError(t, err) + cfg = analytics.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: analytics.Region("de"), + } + client, err = analytics.NewClientWithConfig(cfg) + + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, "analytics.de.algolia.com", echo.Host) +} + +func TestAnalyticsparameters2(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *analytics.APIClient + var cfg analytics.Configuration + _ = client + cfg = analytics.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: analytics.Region("not_a_region"), + } + client, err = analytics.NewClientWithConfig(cfg) + + require.EqualError(t, err, "`region` must be one of the following: de, us") +} + +func TestAnalyticsparameters3(t *testing.T) { + var err error + client, echo := createAnalyticsClient(t) + _ = echo + _, err = client.GetClickPositions(client.NewApiGetClickPositionsRequest( + tests.ZeroValue[string](), + )) + + require.EqualError(t, err, "Parameter `index` is required when calling `GetClickPositions`.") +} diff --git a/tests/output/go/tests/client/ingestion_test.go b/tests/output/go/tests/client/ingestion_test.go new file mode 100644 index 0000000000..bc7db8d28b --- /dev/null +++ b/tests/output/go/tests/client/ingestion_test.go @@ -0,0 +1,111 @@ +package client + +import ( + "regexp" + "testing" + + "github.com/stretchr/testify/require" + + "gotests/tests" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/ingestion" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" +) + +func createIngestionClient(t *testing.T) (*ingestion.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} + cfg := ingestion.Configuration{ + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: ingestion.US, + } + client, err := ingestion.NewClientWithConfig(cfg) + require.NoError(t, err) + + return client, echo +} + +func TestIngestioncommonApi0(t *testing.T) { + var err error + client, echo := createIngestionClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Regexp(t, regexp.MustCompile(`^Algolia for Go \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Ingestion (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$`), echo.Header.Get("User-Agent")) +} + +func TestIngestioncommonApi1(t *testing.T) { + var err error + client, echo := createIngestionClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(5000), echo.Timeout.Milliseconds()) +} + +func TestIngestioncommonApi2(t *testing.T) { + var err error + client, echo := createIngestionClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(30000), echo.Timeout.Milliseconds()) +} + +func TestIngestionparameters0(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *ingestion.APIClient + var cfg ingestion.Configuration + _ = client + require.NoError(t, err) + cfg = ingestion.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: ingestion.Region("us"), + } + client, err = ingestion.NewClientWithConfig(cfg) + + require.NoError(t, err) + _, err = client.GetSource(client.NewApiGetSourceRequest( + "6c02aeb1-775e-418e-870b-1faccd4b2c0f", + )) + + require.Equal(t, "data.us.algolia.com", echo.Host) +} + +func TestIngestionparameters1(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *ingestion.APIClient + var cfg ingestion.Configuration + _ = client + cfg = ingestion.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: ingestion.Region("not_a_region"), + } + client, err = ingestion.NewClientWithConfig(cfg) + + require.EqualError(t, err, "`region` is required and must be one of the following: eu, us") +} diff --git a/tests/output/go/tests/client/insights_test.go b/tests/output/go/tests/client/insights_test.go new file mode 100644 index 0000000000..7cd134d199 --- /dev/null +++ b/tests/output/go/tests/client/insights_test.go @@ -0,0 +1,140 @@ +package client + +import ( + "regexp" + "testing" + + "github.com/stretchr/testify/require" + + "gotests/tests" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/insights" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" +) + +func createInsightsClient(t *testing.T) (*insights.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} + cfg := insights.Configuration{ + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: insights.US, + } + client, err := insights.NewClientWithConfig(cfg) + require.NoError(t, err) + + return client, echo +} + +func TestInsightscommonApi0(t *testing.T) { + var err error + client, echo := createInsightsClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Regexp(t, regexp.MustCompile(`^Algolia for Go \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Insights (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$`), echo.Header.Get("User-Agent")) +} + +func TestInsightscommonApi1(t *testing.T) { + var err error + client, echo := createInsightsClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(5000), echo.Timeout.Milliseconds()) +} + +func TestInsightscommonApi2(t *testing.T) { + var err error + client, echo := createInsightsClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(30000), echo.Timeout.Milliseconds()) +} + +func TestInsightsparameters0(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *insights.APIClient + var cfg insights.Configuration + _ = client + require.NoError(t, err) + cfg = insights.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + } + client, err = insights.NewClientWithConfig(cfg) + + require.NoError(t, err) + _, err = client.PushEvents(client.NewApiPushEventsRequest( + + insights.NewEmptyInsightsEvents().SetEvents( + []insights.EventsItems{*insights.ClickedObjectIDsAfterSearchAsEventsItems( + insights.NewEmptyClickedObjectIDsAfterSearch().SetEventType(insights.ClickEvent("click")).SetEventName("Product Clicked").SetIndex("products").SetUserToken("user-123456").SetAuthenticatedUserToken("user-123456").SetTimestamp(1641290601962).SetObjectIDs( + []string{"9780545139700", "9780439784542"}).SetQueryID("43b15df305339e827f0ac0bdc5ebcaa7").SetPositions( + []int32{7, 6}))}), + )) + + require.Equal(t, "insights.algolia.io", echo.Host) +} + +func TestInsightsparameters1(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *insights.APIClient + var cfg insights.Configuration + _ = client + require.NoError(t, err) + cfg = insights.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: insights.Region("us"), + } + client, err = insights.NewClientWithConfig(cfg) + + require.NoError(t, err) + _, err = client.CustomDelete(client.NewApiCustomDeleteRequest( + "/test", + )) + + require.Equal(t, "insights.us.algolia.io", echo.Host) +} + +func TestInsightsparameters2(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *insights.APIClient + var cfg insights.Configuration + _ = client + cfg = insights.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: insights.Region("not_a_region"), + } + client, err = insights.NewClientWithConfig(cfg) + + require.EqualError(t, err, "`region` must be one of the following: de, us") +} diff --git a/tests/output/go/tests/client/monitoring_test.go b/tests/output/go/tests/client/monitoring_test.go new file mode 100644 index 0000000000..6c5d567ab9 --- /dev/null +++ b/tests/output/go/tests/client/monitoring_test.go @@ -0,0 +1,84 @@ +package client + +import ( + "regexp" + "testing" + + "github.com/stretchr/testify/require" + + "gotests/tests" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/monitoring" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" +) + +func createMonitoringClient(t *testing.T) (*monitoring.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} + cfg := monitoring.Configuration{ + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + } + client, err := monitoring.NewClientWithConfig(cfg) + require.NoError(t, err) + + return client, echo +} + +func TestMonitoringcommonApi0(t *testing.T) { + var err error + client, echo := createMonitoringClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Regexp(t, regexp.MustCompile(`^Algolia for Go \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Monitoring (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$`), echo.Header.Get("User-Agent")) +} + +func TestMonitoringcommonApi1(t *testing.T) { + var err error + client, echo := createMonitoringClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(5000), echo.Timeout.Milliseconds()) +} + +func TestMonitoringcommonApi2(t *testing.T) { + var err error + client, echo := createMonitoringClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(30000), echo.Timeout.Milliseconds()) +} + +func TestMonitoringparameters0(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *monitoring.APIClient + var cfg monitoring.Configuration + _ = client + require.NoError(t, err) + cfg = monitoring.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + } + client, err = monitoring.NewClientWithConfig(cfg) + +} diff --git a/tests/output/go/tests/client/personalization_test.go b/tests/output/go/tests/client/personalization_test.go new file mode 100644 index 0000000000..20f2b1b9c7 --- /dev/null +++ b/tests/output/go/tests/client/personalization_test.go @@ -0,0 +1,124 @@ +package client + +import ( + "regexp" + "testing" + + "github.com/stretchr/testify/require" + + "gotests/tests" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/personalization" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" +) + +func createPersonalizationClient(t *testing.T) (*personalization.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} + cfg := personalization.Configuration{ + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: personalization.US, + } + client, err := personalization.NewClientWithConfig(cfg) + require.NoError(t, err) + + return client, echo +} + +func TestPersonalizationcommonApi0(t *testing.T) { + var err error + client, echo := createPersonalizationClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Regexp(t, regexp.MustCompile(`^Algolia for Go \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Personalization (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$`), echo.Header.Get("User-Agent")) +} + +func TestPersonalizationcommonApi1(t *testing.T) { + var err error + client, echo := createPersonalizationClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(5000), echo.Timeout.Milliseconds()) +} + +func TestPersonalizationcommonApi2(t *testing.T) { + var err error + client, echo := createPersonalizationClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(30000), echo.Timeout.Milliseconds()) +} + +func TestPersonalizationparameters0(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *personalization.APIClient + var cfg personalization.Configuration + _ = client + cfg = personalization.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: personalization.Region(""), + } + client, err = personalization.NewClientWithConfig(cfg) + + require.EqualError(t, err, "`region` is required and must be one of the following: eu, us") +} + +func TestPersonalizationparameters1(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *personalization.APIClient + var cfg personalization.Configuration + _ = client + cfg = personalization.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: personalization.Region("not_a_region"), + } + client, err = personalization.NewClientWithConfig(cfg) + + require.EqualError(t, err, "`region` is required and must be one of the following: eu, us") +} + +func TestPersonalizationparameters2(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *personalization.APIClient + var cfg personalization.Configuration + _ = client + require.NoError(t, err) + cfg = personalization.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: personalization.Region("us"), + } + client, err = personalization.NewClientWithConfig(cfg) + +} diff --git a/tests/output/go/tests/client/query-suggestions_test.go b/tests/output/go/tests/client/query-suggestions_test.go new file mode 100644 index 0000000000..a9bd269abb --- /dev/null +++ b/tests/output/go/tests/client/query-suggestions_test.go @@ -0,0 +1,124 @@ +package client + +import ( + "regexp" + "testing" + + "github.com/stretchr/testify/require" + + "gotests/tests" + + suggestions "github.com/algolia/algoliasearch-client-go/v4/algolia/query-suggestions" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" +) + +func createSuggestionsClient(t *testing.T) (*suggestions.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} + cfg := suggestions.Configuration{ + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: suggestions.US, + } + client, err := suggestions.NewClientWithConfig(cfg) + require.NoError(t, err) + + return client, echo +} + +func TestSuggestionscommonApi0(t *testing.T) { + var err error + client, echo := createSuggestionsClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Regexp(t, regexp.MustCompile(`^Algolia for Go \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; QuerySuggestions (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$`), echo.Header.Get("User-Agent")) +} + +func TestSuggestionscommonApi1(t *testing.T) { + var err error + client, echo := createSuggestionsClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(5000), echo.Timeout.Milliseconds()) +} + +func TestSuggestionscommonApi2(t *testing.T) { + var err error + client, echo := createSuggestionsClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(30000), echo.Timeout.Milliseconds()) +} + +func TestSuggestionsparameters0(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *suggestions.APIClient + var cfg suggestions.Configuration + _ = client + cfg = suggestions.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: suggestions.Region(""), + } + client, err = suggestions.NewClientWithConfig(cfg) + + require.EqualError(t, err, "`region` is required and must be one of the following: eu, us") +} + +func TestSuggestionsparameters1(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *suggestions.APIClient + var cfg suggestions.Configuration + _ = client + cfg = suggestions.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: suggestions.Region("not_a_region"), + } + client, err = suggestions.NewClientWithConfig(cfg) + + require.EqualError(t, err, "`region` is required and must be one of the following: eu, us") +} + +func TestSuggestionsparameters2(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *suggestions.APIClient + var cfg suggestions.Configuration + _ = client + require.NoError(t, err) + cfg = suggestions.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "my-api-key", + Requester: echo, + }, + Region: suggestions.Region("us"), + } + client, err = suggestions.NewClientWithConfig(cfg) + +} diff --git a/tests/output/go/tests/client/recommend_test.go b/tests/output/go/tests/client/recommend_test.go new file mode 100644 index 0000000000..36cc06129c --- /dev/null +++ b/tests/output/go/tests/client/recommend_test.go @@ -0,0 +1,114 @@ +package client + +import ( + "regexp" + "testing" + + "github.com/stretchr/testify/require" + + "gotests/tests" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/recommend" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" +) + +func createRecommendClient(t *testing.T) (*recommend.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} + cfg := recommend.Configuration{ + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + } + client, err := recommend.NewClientWithConfig(cfg) + require.NoError(t, err) + + return client, echo +} + +func TestRecommendapi0(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *recommend.APIClient + var cfg recommend.Configuration + _ = client + require.NoError(t, err) + cfg = recommend.Configuration{ + Configuration: transport.Configuration{ + AppID: "test-app-id", + ApiKey: "test-api-key", + Requester: echo, + }, + } + client, err = recommend.NewClientWithConfig(cfg) + + require.NoError(t, err) + _, err = client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + + require.Equal(t, "test-app-id-dsn.algolia.net", echo.Host) +} + +func TestRecommendapi1(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *recommend.APIClient + var cfg recommend.Configuration + _ = client + require.NoError(t, err) + cfg = recommend.Configuration{ + Configuration: transport.Configuration{ + AppID: "test-app-id", + ApiKey: "test-api-key", + Requester: echo, + }, + } + client, err = recommend.NewClientWithConfig(cfg) + + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, "test-app-id.algolia.net", echo.Host) +} + +func TestRecommendcommonApi0(t *testing.T) { + var err error + client, echo := createRecommendClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Regexp(t, regexp.MustCompile(`^Algolia for Go \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Recommend (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$`), echo.Header.Get("User-Agent")) +} + +func TestRecommendcommonApi1(t *testing.T) { + var err error + client, echo := createRecommendClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(5000), echo.Timeout.Milliseconds()) +} + +func TestRecommendcommonApi2(t *testing.T) { + var err error + client, echo := createRecommendClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(30000), echo.Timeout.Milliseconds()) +} diff --git a/tests/output/go/tests/client/search_test.go b/tests/output/go/tests/client/search_test.go new file mode 100644 index 0000000000..a35a87e0d2 --- /dev/null +++ b/tests/output/go/tests/client/search_test.go @@ -0,0 +1,184 @@ +package client + +import ( + "regexp" + "testing" + + "github.com/stretchr/testify/require" + + "gotests/tests" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" +) + +func createSearchClient(t *testing.T) (*search.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} + cfg := search.Configuration{ + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + } + client, err := search.NewClientWithConfig(cfg) + require.NoError(t, err) + + return client, echo +} + +func TestSearchapi0(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *search.APIClient + var cfg search.Configuration + _ = client + require.NoError(t, err) + cfg = search.Configuration{ + Configuration: transport.Configuration{ + AppID: "test-app-id", + ApiKey: "test-api-key", + Requester: echo, + }, + } + client, err = search.NewClientWithConfig(cfg) + + require.NoError(t, err) + _, err = client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + + require.Equal(t, "test-app-id-dsn.algolia.net", echo.Host) +} + +func TestSearchapi1(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *search.APIClient + var cfg search.Configuration + _ = client + require.NoError(t, err) + cfg = search.Configuration{ + Configuration: transport.Configuration{ + AppID: "test-app-id", + ApiKey: "test-api-key", + Requester: echo, + }, + } + client, err = search.NewClientWithConfig(cfg) + + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, "test-app-id.algolia.net", echo.Host) +} + +func TestSearchcommonApi0(t *testing.T) { + var err error + client, echo := createSearchClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Regexp(t, regexp.MustCompile(`^Algolia for Go \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Search (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$`), echo.Header.Get("User-Agent")) +} + +func TestSearchcommonApi1(t *testing.T) { + var err error + client, echo := createSearchClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(5000), echo.Timeout.Milliseconds()) +} + +func TestSearchcommonApi2(t *testing.T) { + var err error + client, echo := createSearchClient(t) + _ = echo + require.NoError(t, err) + _, err = client.CustomPost(client.NewApiCustomPostRequest( + "/test", + )) + + require.Equal(t, int64(2000), echo.ConnectTimeout.Milliseconds()) + require.Equal(t, int64(30000), echo.Timeout.Milliseconds()) +} + +func TestSearchparameters0(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *search.APIClient + var cfg search.Configuration + _ = client + cfg = search.Configuration{ + Configuration: transport.Configuration{ + AppID: "", + ApiKey: "", + Requester: echo, + }, + } + client, err = search.NewClientWithConfig(cfg) + + require.EqualError(t, err, "`appId` is missing.") + cfg = search.Configuration{ + Configuration: transport.Configuration{ + AppID: "", + ApiKey: "my-api-key", + Requester: echo, + }, + } + client, err = search.NewClientWithConfig(cfg) + + require.EqualError(t, err, "`appId` is missing.") + cfg = search.Configuration{ + Configuration: transport.Configuration{ + AppID: "my-app-id", + ApiKey: "", + Requester: echo, + }, + } + client, err = search.NewClientWithConfig(cfg) + + require.EqualError(t, err, "`apiKey` is missing.") +} + +func TestSearchparameters1(t *testing.T) { + var err error + client, echo := createSearchClient(t) + _ = echo + _, err = client.AddApiKey(client.NewApiAddApiKeyRequest( + tests.ZeroValue[*search.ApiKey](), + )) + + require.EqualError(t, err, "Parameter `apiKey` is required when calling `AddApiKey`.") +} + +func TestSearchparameters2(t *testing.T) { + var err error + client, echo := createSearchClient(t) + _ = echo + _, err = client.AddOrUpdateObject(client.NewApiAddOrUpdateObjectRequest( + tests.ZeroValue[string](), "my-object-id", map[string]any{}, + )) + + require.EqualError(t, err, "Parameter `indexName` is required when calling `AddOrUpdateObject`.") + _, err = client.AddOrUpdateObject(client.NewApiAddOrUpdateObjectRequest( + "my-index-name", tests.ZeroValue[string](), map[string]any{}, + )) + + require.EqualError(t, err, "Parameter `objectID` is required when calling `AddOrUpdateObject`.") + _, err = client.AddOrUpdateObject(client.NewApiAddOrUpdateObjectRequest( + "my-index-name", "my-object-id", tests.ZeroValue[map[string]any](), + )) + + require.EqualError(t, err, "Parameter `body` is required when calling `AddOrUpdateObject`.") +} diff --git a/tests/output/go/tests/requests/abtesting_test.go b/tests/output/go/tests/requests/abtesting_test.go index f202b891e5..e6ccceb479 100644 --- a/tests/output/go/tests/requests/abtesting_test.go +++ b/tests/output/go/tests/requests/abtesting_test.go @@ -1,4 +1,4 @@ -package tests +package requests import ( "encoding/json" @@ -8,21 +8,23 @@ import ( "github.com/kinbiko/jsonassert" "github.com/stretchr/testify/require" + "gotests/tests" + "github.com/algolia/algoliasearch-client-go/v4/algolia/abtesting" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -func createAbtestingClient() (*abtesting.APIClient, *echoRequester) { - echo := &echoRequester{} +func createAbtestingClient() (*abtesting.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} cfg := abtesting.Configuration{ - AppID: "appID", - ApiKey: "apiKey", - Region: abtesting.US, - Requester: echo, + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: abtesting.US, } - client := abtesting.NewClientWithConfig(cfg) - - // so that the linter doesn't complain - _ = jsonassert.New(nil) + client, _ := abtesting.NewClientWithConfig(cfg) return client, echo } @@ -42,11 +44,11 @@ func TestAbtesting_AddABTests(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/abtests") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"endAt":"2022-12-31T00:00:00.000Z","name":"myABTest","variants":[{"index":"AB_TEST_1","trafficPercentage":30},{"index":"AB_TEST_2","trafficPercentage":50}]}`) + ja.Assertf(*echo.Body, `{"endAt":"2022-12-31T00:00:00.000Z","name":"myABTest","variants":[{"index":"AB_TEST_1","trafficPercentage":30},{"index":"AB_TEST_2","trafficPercentage":50}]}`) }) } @@ -61,10 +63,10 @@ func TestAbtesting_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow del method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomDelete(client.NewApiCustomDeleteRequest( @@ -74,14 +76,14 @@ func TestAbtesting_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -97,10 +99,10 @@ func TestAbtesting_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow get method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomGet(client.NewApiCustomGetRequest( @@ -110,14 +112,14 @@ func TestAbtesting_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -133,11 +135,11 @@ func TestAbtesting_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow post method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPost(client.NewApiCustomPostRequest( @@ -147,15 +149,15 @@ func TestAbtesting_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default query parameters", func(t *testing.T) { @@ -168,15 +170,15 @@ func TestAbtesting_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges query parameters with default ones", func(t *testing.T) { @@ -189,15 +191,15 @@ func TestAbtesting_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","query2":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default headers", func(t *testing.T) { @@ -210,20 +212,20 @@ func TestAbtesting_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges headers with default ones", func(t *testing.T) { @@ -236,20 +238,20 @@ func TestAbtesting_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts booleans", func(t *testing.T) { @@ -262,15 +264,15 @@ func TestAbtesting_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","isItWorking":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts integers", func(t *testing.T) { @@ -283,15 +285,15 @@ func TestAbtesting_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of string", func(t *testing.T) { @@ -305,15 +307,15 @@ func TestAbtesting_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"c,d"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of booleans", func(t *testing.T) { @@ -327,15 +329,15 @@ func TestAbtesting_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"true,true,false"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of integers", func(t *testing.T) { @@ -349,15 +351,15 @@ func TestAbtesting_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"1,2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -373,11 +375,11 @@ func TestAbtesting_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow put method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPut(client.NewApiCustomPutRequest( @@ -387,15 +389,15 @@ func TestAbtesting_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -411,10 +413,10 @@ func TestAbtesting_DeleteABTest(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/abtests/42") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -429,10 +431,10 @@ func TestAbtesting_GetABTest(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/abtests/42") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -445,10 +447,10 @@ func TestAbtesting_ListABTests(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/abtests") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("listABTests with parameters", func(t *testing.T) { _, err := client.ListABTests(client.NewApiListABTestsRequest().WithOffset(42).WithLimit(21).WithIndexPrefix("foo").WithIndexSuffix("bar")) @@ -456,14 +458,14 @@ func TestAbtesting_ListABTests(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/abtests") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"offset":"42","limit":"21","indexPrefix":"foo","indexSuffix":"bar"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -479,9 +481,9 @@ func TestAbtesting_StopABTest(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/abtests/42/stop") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) - require.Empty(t, echo.body) + require.Empty(t, echo.Body) }) } diff --git a/tests/output/go/tests/requests/analytics_test.go b/tests/output/go/tests/requests/analytics_test.go index 5fea3e9460..c88394de0d 100644 --- a/tests/output/go/tests/requests/analytics_test.go +++ b/tests/output/go/tests/requests/analytics_test.go @@ -1,4 +1,4 @@ -package tests +package requests import ( "encoding/json" @@ -8,21 +8,23 @@ import ( "github.com/kinbiko/jsonassert" "github.com/stretchr/testify/require" + "gotests/tests" + "github.com/algolia/algoliasearch-client-go/v4/algolia/analytics" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -func createAnalyticsClient() (*analytics.APIClient, *echoRequester) { - echo := &echoRequester{} +func createAnalyticsClient() (*analytics.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} cfg := analytics.Configuration{ - AppID: "appID", - ApiKey: "apiKey", - Region: analytics.US, - Requester: echo, + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: analytics.US, } - client := analytics.NewClientWithConfig(cfg) - - // so that the linter doesn't complain - _ = jsonassert.New(nil) + client, _ := analytics.NewClientWithConfig(cfg) return client, echo } @@ -38,10 +40,10 @@ func TestAnalytics_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow del method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomDelete(client.NewApiCustomDeleteRequest( @@ -51,14 +53,14 @@ func TestAnalytics_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -74,10 +76,10 @@ func TestAnalytics_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow get method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomGet(client.NewApiCustomGetRequest( @@ -87,14 +89,14 @@ func TestAnalytics_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -110,11 +112,11 @@ func TestAnalytics_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow post method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPost(client.NewApiCustomPostRequest( @@ -124,15 +126,15 @@ func TestAnalytics_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default query parameters", func(t *testing.T) { @@ -145,15 +147,15 @@ func TestAnalytics_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges query parameters with default ones", func(t *testing.T) { @@ -166,15 +168,15 @@ func TestAnalytics_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","query2":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default headers", func(t *testing.T) { @@ -187,20 +189,20 @@ func TestAnalytics_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges headers with default ones", func(t *testing.T) { @@ -213,20 +215,20 @@ func TestAnalytics_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts booleans", func(t *testing.T) { @@ -239,15 +241,15 @@ func TestAnalytics_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","isItWorking":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts integers", func(t *testing.T) { @@ -260,15 +262,15 @@ func TestAnalytics_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of string", func(t *testing.T) { @@ -282,15 +284,15 @@ func TestAnalytics_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"c,d"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of booleans", func(t *testing.T) { @@ -304,15 +306,15 @@ func TestAnalytics_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"true,true,false"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of integers", func(t *testing.T) { @@ -326,15 +328,15 @@ func TestAnalytics_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"1,2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -350,11 +352,11 @@ func TestAnalytics_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow put method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPut(client.NewApiCustomPutRequest( @@ -364,15 +366,15 @@ func TestAnalytics_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -388,14 +390,14 @@ func TestAnalytics_GetAverageClickPosition(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/clicks/averageClickPosition") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getAverageClickPosition with all parameters", func(t *testing.T) { @@ -406,14 +408,14 @@ func TestAnalytics_GetAverageClickPosition(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/clicks/averageClickPosition") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","startDate":"1999-09-19","endDate":"2001-01-01","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -429,14 +431,14 @@ func TestAnalytics_GetClickPositions(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/clicks/positions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getClickPositions with all parameters", func(t *testing.T) { @@ -447,14 +449,14 @@ func TestAnalytics_GetClickPositions(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/clicks/positions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","startDate":"1999-09-19","endDate":"2001-01-01","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -470,14 +472,14 @@ func TestAnalytics_GetClickThroughRate(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/clicks/clickThroughRate") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getClickThroughRate with all parameters", func(t *testing.T) { @@ -488,14 +490,14 @@ func TestAnalytics_GetClickThroughRate(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/clicks/clickThroughRate") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","startDate":"1999-09-19","endDate":"2001-01-01","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -511,14 +513,14 @@ func TestAnalytics_GetConversationRate(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/conversions/conversionRate") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getConversationRate with all parameters", func(t *testing.T) { @@ -529,14 +531,14 @@ func TestAnalytics_GetConversationRate(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/conversions/conversionRate") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","startDate":"1999-09-19","endDate":"2001-01-01","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -552,14 +554,14 @@ func TestAnalytics_GetNoClickRate(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches/noClickRate") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getNoClickRate with all parameters", func(t *testing.T) { @@ -570,14 +572,14 @@ func TestAnalytics_GetNoClickRate(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches/noClickRate") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","startDate":"1999-09-19","endDate":"2001-01-01","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -593,14 +595,14 @@ func TestAnalytics_GetNoResultsRate(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches/noResultRate") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getNoResultsRate with all parameters", func(t *testing.T) { @@ -611,14 +613,14 @@ func TestAnalytics_GetNoResultsRate(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches/noResultRate") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","startDate":"1999-09-19","endDate":"2001-01-01","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -634,14 +636,14 @@ func TestAnalytics_GetSearchesCount(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches/count") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getSearchesCount with all parameters", func(t *testing.T) { @@ -652,14 +654,14 @@ func TestAnalytics_GetSearchesCount(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches/count") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","startDate":"1999-09-19","endDate":"2001-01-01","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -675,14 +677,14 @@ func TestAnalytics_GetSearchesNoClicks(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches/noClicks") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getSearchesNoClicks with all parameters", func(t *testing.T) { @@ -693,14 +695,14 @@ func TestAnalytics_GetSearchesNoClicks(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches/noClicks") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","startDate":"1999-09-19","endDate":"2001-01-01","limit":"21","offset":"42","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -716,14 +718,14 @@ func TestAnalytics_GetSearchesNoResults(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches/noResults") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getSearchesNoResults with all parameters", func(t *testing.T) { @@ -734,14 +736,14 @@ func TestAnalytics_GetSearchesNoResults(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches/noResults") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","startDate":"1999-09-19","endDate":"2001-01-01","limit":"21","offset":"42","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -757,14 +759,14 @@ func TestAnalytics_GetStatus(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/status") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -780,14 +782,14 @@ func TestAnalytics_GetTopCountries(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/countries") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getTopCountries with all parameters", func(t *testing.T) { @@ -798,14 +800,14 @@ func TestAnalytics_GetTopCountries(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/countries") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","startDate":"1999-09-19","endDate":"2001-01-01","limit":"21","offset":"42","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -821,14 +823,14 @@ func TestAnalytics_GetTopFilterAttributes(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/filters") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getTopFilterAttributes with all parameters", func(t *testing.T) { @@ -839,14 +841,14 @@ func TestAnalytics_GetTopFilterAttributes(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/filters") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","search":"mySearch","startDate":"1999-09-19","endDate":"2001-01-01","limit":"21","offset":"42","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -862,14 +864,14 @@ func TestAnalytics_GetTopFilterForAttribute(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/filters/myAttribute") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getTopFilterForAttribute with minimal parameters and multiple attributes", func(t *testing.T) { @@ -880,14 +882,14 @@ func TestAnalytics_GetTopFilterForAttribute(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/filters/myAttribute1%2CmyAttribute2") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getTopFilterForAttribute with all parameters", func(t *testing.T) { @@ -898,14 +900,14 @@ func TestAnalytics_GetTopFilterForAttribute(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/filters/myAttribute") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","search":"mySearch","startDate":"1999-09-19","endDate":"2001-01-01","limit":"21","offset":"42","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getTopFilterForAttribute with all parameters and multiple attributes", func(t *testing.T) { @@ -916,14 +918,14 @@ func TestAnalytics_GetTopFilterForAttribute(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/filters/myAttribute1%2CmyAttribute2") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","search":"mySearch","startDate":"1999-09-19","endDate":"2001-01-01","limit":"21","offset":"42","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -939,14 +941,14 @@ func TestAnalytics_GetTopFiltersNoResults(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/filters/noResults") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getTopFiltersNoResults with all parameters", func(t *testing.T) { @@ -957,14 +959,14 @@ func TestAnalytics_GetTopFiltersNoResults(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/filters/noResults") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","search":"mySearch","startDate":"1999-09-19","endDate":"2001-01-01","limit":"21","offset":"42","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -980,14 +982,14 @@ func TestAnalytics_GetTopHits(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/hits") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getTopHits with all parameters", func(t *testing.T) { @@ -998,14 +1000,14 @@ func TestAnalytics_GetTopHits(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/hits") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","search":"mySearch","clickAnalytics":"true","startDate":"1999-09-19","endDate":"2001-01-01","limit":"21","offset":"42","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1021,14 +1023,14 @@ func TestAnalytics_GetTopSearches(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getTopSearches with all parameters", func(t *testing.T) { @@ -1039,14 +1041,14 @@ func TestAnalytics_GetTopSearches(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/searches") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","clickAnalytics":"true","startDate":"1999-09-19","endDate":"2001-01-01","orderBy":"searchCount","direction":"asc","limit":"21","offset":"42","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1062,14 +1064,14 @@ func TestAnalytics_GetUsersCount(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/users/count") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("get getUsersCount with all parameters", func(t *testing.T) { @@ -1080,14 +1082,14 @@ func TestAnalytics_GetUsersCount(t *testing.T) { expectedPath, err := url.QueryUnescape("/2/users/count") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"index":"index","startDate":"1999-09-19","endDate":"2001-01-01","tags":"tag"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } diff --git a/tests/output/go/tests/requests/ingestion_test.go b/tests/output/go/tests/requests/ingestion_test.go index aa59c15d1c..01ba4ebb40 100644 --- a/tests/output/go/tests/requests/ingestion_test.go +++ b/tests/output/go/tests/requests/ingestion_test.go @@ -1,4 +1,4 @@ -package tests +package requests import ( "encoding/json" @@ -8,21 +8,23 @@ import ( "github.com/kinbiko/jsonassert" "github.com/stretchr/testify/require" + "gotests/tests" + "github.com/algolia/algoliasearch-client-go/v4/algolia/ingestion" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -func createIngestionClient() (*ingestion.APIClient, *echoRequester) { - echo := &echoRequester{} +func createIngestionClient() (*ingestion.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} cfg := ingestion.Configuration{ - AppID: "appID", - ApiKey: "apiKey", - Region: ingestion.US, - Requester: echo, + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: ingestion.US, } - client := ingestion.NewClientWithConfig(cfg) - - // so that the linter doesn't complain - _ = jsonassert.New(nil) + client, _ := ingestion.NewClientWithConfig(cfg) return client, echo } @@ -40,11 +42,11 @@ func TestIngestion_CreateAuthentication(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/authentications") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"type":"oauth","name":"authName","input":{"url":"http://test.oauth","client_id":"myID","client_secret":"mySecret"}}`) + ja.Assertf(*echo.Body, `{"type":"oauth","name":"authName","input":{"url":"http://test.oauth","client_id":"myID","client_secret":"mySecret"}}`) }) t.Run("createAuthenticationAlgolia", func(t *testing.T) { _, err := client.CreateAuthentication(client.NewApiCreateAuthenticationRequest( @@ -56,11 +58,11 @@ func TestIngestion_CreateAuthentication(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/authentications") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"type":"algolia","name":"authName","input":{"appID":"myappID","apiKey":"randomApiKey"}}`) + ja.Assertf(*echo.Body, `{"type":"algolia","name":"authName","input":{"appID":"myappID","apiKey":"randomApiKey"}}`) }) } @@ -77,11 +79,11 @@ func TestIngestion_CreateDestination(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/destinations") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"type":"search","name":"destinationName","input":{"indexPrefix":"prefix_"},"authenticationID":"6c02aeb1-775e-418e-870b-1faccd4b2c0f"}`) + ja.Assertf(*echo.Body, `{"type":"search","name":"destinationName","input":{"indexPrefix":"prefix_"},"authenticationID":"6c02aeb1-775e-418e-870b-1faccd4b2c0f"}`) }) } @@ -100,11 +102,11 @@ func TestIngestion_CreateSource(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/sources") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"type":"commercetools","name":"sourceName","input":{"storeKeys":["myStore"],"locales":["de"],"url":"http://commercetools.com","projectKey":"keyID"},"authenticationID":"6c02aeb1-775e-418e-870b-1faccd4b2c0f"}`) + ja.Assertf(*echo.Body, `{"type":"commercetools","name":"sourceName","input":{"storeKeys":["myStore"],"locales":["de"],"url":"http://commercetools.com","projectKey":"keyID"},"authenticationID":"6c02aeb1-775e-418e-870b-1faccd4b2c0f"}`) }) } @@ -121,11 +123,11 @@ func TestIngestion_CreateTask(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/tasks") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"sourceID":"search","destinationID":"destinationName","trigger":{"type":"onDemand"},"action":"replace"}`) + ja.Assertf(*echo.Body, `{"sourceID":"search","destinationID":"destinationName","trigger":{"type":"onDemand"},"action":"replace"}`) }) t.Run("createTaskSchedule", func(t *testing.T) { _, err := client.CreateTask(client.NewApiCreateTaskRequest( @@ -137,11 +139,11 @@ func TestIngestion_CreateTask(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/tasks") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"sourceID":"search","destinationID":"destinationName","trigger":{"type":"schedule","cron":"* * * * *"},"action":"replace"}`) + ja.Assertf(*echo.Body, `{"sourceID":"search","destinationID":"destinationName","trigger":{"type":"schedule","cron":"* * * * *"},"action":"replace"}`) }) t.Run("createTaskSubscription", func(t *testing.T) { _, err := client.CreateTask(client.NewApiCreateTaskRequest( @@ -153,11 +155,11 @@ func TestIngestion_CreateTask(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/tasks") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"sourceID":"search","destinationID":"destinationName","trigger":{"type":"onDemand"},"action":"replace"}`) + ja.Assertf(*echo.Body, `{"sourceID":"search","destinationID":"destinationName","trigger":{"type":"onDemand"},"action":"replace"}`) }) } @@ -172,10 +174,10 @@ func TestIngestion_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow del method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomDelete(client.NewApiCustomDeleteRequest( @@ -185,14 +187,14 @@ func TestIngestion_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -208,10 +210,10 @@ func TestIngestion_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow get method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomGet(client.NewApiCustomGetRequest( @@ -221,14 +223,14 @@ func TestIngestion_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -244,11 +246,11 @@ func TestIngestion_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow post method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPost(client.NewApiCustomPostRequest( @@ -258,15 +260,15 @@ func TestIngestion_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default query parameters", func(t *testing.T) { @@ -279,15 +281,15 @@ func TestIngestion_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges query parameters with default ones", func(t *testing.T) { @@ -300,15 +302,15 @@ func TestIngestion_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","query2":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default headers", func(t *testing.T) { @@ -321,20 +323,20 @@ func TestIngestion_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges headers with default ones", func(t *testing.T) { @@ -347,20 +349,20 @@ func TestIngestion_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts booleans", func(t *testing.T) { @@ -373,15 +375,15 @@ func TestIngestion_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","isItWorking":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts integers", func(t *testing.T) { @@ -394,15 +396,15 @@ func TestIngestion_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of string", func(t *testing.T) { @@ -416,15 +418,15 @@ func TestIngestion_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"c,d"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of booleans", func(t *testing.T) { @@ -438,15 +440,15 @@ func TestIngestion_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"true,true,false"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of integers", func(t *testing.T) { @@ -460,15 +462,15 @@ func TestIngestion_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"1,2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -484,11 +486,11 @@ func TestIngestion_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow put method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPut(client.NewApiCustomPutRequest( @@ -498,15 +500,15 @@ func TestIngestion_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -522,10 +524,10 @@ func TestIngestion_DeleteAuthentication(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/authentications/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -540,10 +542,10 @@ func TestIngestion_DeleteDestination(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/destinations/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -558,10 +560,10 @@ func TestIngestion_DeleteSource(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -576,10 +578,10 @@ func TestIngestion_DeleteTask(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -594,10 +596,10 @@ func TestIngestion_DisableTask(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f/disable") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) - require.Empty(t, echo.body) + require.Empty(t, echo.Body) }) } @@ -612,10 +614,10 @@ func TestIngestion_EnableTask(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f/enable") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) - require.Empty(t, echo.body) + require.Empty(t, echo.Body) }) } @@ -630,10 +632,10 @@ func TestIngestion_GetAuthentication(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/authentications/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -646,10 +648,10 @@ func TestIngestion_GetAuthentications(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/authentications") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -664,10 +666,10 @@ func TestIngestion_GetDestination(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/destinations/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -680,10 +682,10 @@ func TestIngestion_GetDestinations(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/destinations") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -698,10 +700,10 @@ func TestIngestion_GetDockerSourceStreams(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f/discover") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -716,10 +718,10 @@ func TestIngestion_GetEvent(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/runs/6c02aeb1-775e-418e-870b-1faccd4b2c0f/events/6c02aeb1-775e-418e-870b-1faccd4b2c0c") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -734,10 +736,10 @@ func TestIngestion_GetEvents(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/runs/6c02aeb1-775e-418e-870b-1faccd4b2c0f/events") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -752,10 +754,10 @@ func TestIngestion_GetRun(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/runs/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -768,10 +770,10 @@ func TestIngestion_GetRuns(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/runs") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -786,10 +788,10 @@ func TestIngestion_GetSource(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -802,10 +804,10 @@ func TestIngestion_GetSources(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/sources") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -820,10 +822,10 @@ func TestIngestion_GetTask(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -836,10 +838,10 @@ func TestIngestion_GetTasks(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/tasks") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -854,10 +856,10 @@ func TestIngestion_RunTask(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f/run") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) - require.Empty(t, echo.body) + require.Empty(t, echo.Body) }) } @@ -874,11 +876,11 @@ func TestIngestion_SearchAuthentications(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/authentications/search") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"authenticationIDs":["6c02aeb1-775e-418e-870b-1faccd4b2c0f","947ac9c4-7e58-4c87-b1e7-14a68e99699a"]}`) + ja.Assertf(*echo.Body, `{"authenticationIDs":["6c02aeb1-775e-418e-870b-1faccd4b2c0f","947ac9c4-7e58-4c87-b1e7-14a68e99699a"]}`) }) } @@ -895,11 +897,11 @@ func TestIngestion_SearchDestinations(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/destinations/search") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"destinationIDs":["6c02aeb1-775e-418e-870b-1faccd4b2c0f","947ac9c4-7e58-4c87-b1e7-14a68e99699a"]}`) + ja.Assertf(*echo.Body, `{"destinationIDs":["6c02aeb1-775e-418e-870b-1faccd4b2c0f","947ac9c4-7e58-4c87-b1e7-14a68e99699a"]}`) }) } @@ -916,11 +918,11 @@ func TestIngestion_SearchSources(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/sources/search") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"sourceIDs":["6c02aeb1-775e-418e-870b-1faccd4b2c0f","947ac9c4-7e58-4c87-b1e7-14a68e99699a"]}`) + ja.Assertf(*echo.Body, `{"sourceIDs":["6c02aeb1-775e-418e-870b-1faccd4b2c0f","947ac9c4-7e58-4c87-b1e7-14a68e99699a"]}`) }) } @@ -937,11 +939,11 @@ func TestIngestion_SearchTasks(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/tasks/search") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"taskIDs":["6c02aeb1-775e-418e-870b-1faccd4b2c0f","947ac9c4-7e58-4c87-b1e7-14a68e99699a"]}`) + ja.Assertf(*echo.Body, `{"taskIDs":["6c02aeb1-775e-418e-870b-1faccd4b2c0f","947ac9c4-7e58-4c87-b1e7-14a68e99699a"]}`) }) } @@ -956,10 +958,10 @@ func TestIngestion_TriggerDockerSourceDiscover(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f/discover") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) - require.Empty(t, echo.body) + require.Empty(t, echo.Body) }) } @@ -975,11 +977,11 @@ func TestIngestion_UpdateAuthentication(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/authentications/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PATCH", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PATCH", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"name":"newName"}`) + ja.Assertf(*echo.Body, `{"name":"newName"}`) }) } @@ -995,11 +997,11 @@ func TestIngestion_UpdateDestination(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/destinations/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PATCH", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PATCH", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"name":"newName"}`) + ja.Assertf(*echo.Body, `{"name":"newName"}`) }) } @@ -1015,11 +1017,11 @@ func TestIngestion_UpdateSource(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PATCH", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PATCH", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"name":"newName"}`) + ja.Assertf(*echo.Body, `{"name":"newName"}`) }) } @@ -1035,10 +1037,10 @@ func TestIngestion_UpdateTask(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PATCH", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PATCH", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"enabled":false}`) + ja.Assertf(*echo.Body, `{"enabled":false}`) }) } diff --git a/tests/output/go/tests/requests/insights_test.go b/tests/output/go/tests/requests/insights_test.go index 95cb6256b3..1c5b84c3f5 100644 --- a/tests/output/go/tests/requests/insights_test.go +++ b/tests/output/go/tests/requests/insights_test.go @@ -1,4 +1,4 @@ -package tests +package requests import ( "encoding/json" @@ -8,21 +8,23 @@ import ( "github.com/kinbiko/jsonassert" "github.com/stretchr/testify/require" + "gotests/tests" + "github.com/algolia/algoliasearch-client-go/v4/algolia/insights" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -func createInsightsClient() (*insights.APIClient, *echoRequester) { - echo := &echoRequester{} +func createInsightsClient() (*insights.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} cfg := insights.Configuration{ - AppID: "appID", - ApiKey: "apiKey", - Region: insights.US, - Requester: echo, + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: insights.US, } - client := insights.NewClientWithConfig(cfg) - - // so that the linter doesn't complain - _ = jsonassert.New(nil) + client, _ := insights.NewClientWithConfig(cfg) return client, echo } @@ -38,10 +40,10 @@ func TestInsights_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow del method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomDelete(client.NewApiCustomDeleteRequest( @@ -51,14 +53,14 @@ func TestInsights_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -74,10 +76,10 @@ func TestInsights_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow get method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomGet(client.NewApiCustomGetRequest( @@ -87,14 +89,14 @@ func TestInsights_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -110,11 +112,11 @@ func TestInsights_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow post method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPost(client.NewApiCustomPostRequest( @@ -124,15 +126,15 @@ func TestInsights_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default query parameters", func(t *testing.T) { @@ -145,15 +147,15 @@ func TestInsights_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges query parameters with default ones", func(t *testing.T) { @@ -166,15 +168,15 @@ func TestInsights_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","query2":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default headers", func(t *testing.T) { @@ -187,20 +189,20 @@ func TestInsights_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges headers with default ones", func(t *testing.T) { @@ -213,20 +215,20 @@ func TestInsights_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts booleans", func(t *testing.T) { @@ -239,15 +241,15 @@ func TestInsights_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","isItWorking":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts integers", func(t *testing.T) { @@ -260,15 +262,15 @@ func TestInsights_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of string", func(t *testing.T) { @@ -282,15 +284,15 @@ func TestInsights_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"c,d"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of booleans", func(t *testing.T) { @@ -304,15 +306,15 @@ func TestInsights_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"true,true,false"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of integers", func(t *testing.T) { @@ -326,15 +328,15 @@ func TestInsights_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"1,2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -350,11 +352,11 @@ func TestInsights_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow put method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPut(client.NewApiCustomPutRequest( @@ -364,15 +366,15 @@ func TestInsights_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -388,10 +390,10 @@ func TestInsights_DeleteUserToken(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/usertokens/test-user-1") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -411,11 +413,11 @@ func TestInsights_PushEvents(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/events") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"events":[{"eventType":"click","eventName":"Product Clicked","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7","positions":[7,6]}]}`) + ja.Assertf(*echo.Body, `{"events":[{"eventType":"click","eventName":"Product Clicked","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7","positions":[7,6]}]}`) }) t.Run("Many events type", func(t *testing.T) { _, err := client.PushEvents(client.NewApiPushEventsRequest( @@ -431,11 +433,11 @@ func TestInsights_PushEvents(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/events") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"]}]}`) + ja.Assertf(*echo.Body, `{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"},{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"]}]}`) }) t.Run("ConvertedObjectIDsAfterSearch", func(t *testing.T) { _, err := client.PushEvents(client.NewApiPushEventsRequest( @@ -449,11 +451,11 @@ func TestInsights_PushEvents(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/events") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"}]}`) + ja.Assertf(*echo.Body, `{"events":[{"eventType":"conversion","eventName":"Product Purchased","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"],"queryID":"43b15df305339e827f0ac0bdc5ebcaa7"}]}`) }) t.Run("ViewedObjectIDs", func(t *testing.T) { _, err := client.PushEvents(client.NewApiPushEventsRequest( @@ -467,11 +469,11 @@ func TestInsights_PushEvents(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/events") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"events":[{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"]}]}`) + ja.Assertf(*echo.Body, `{"events":[{"eventType":"view","eventName":"Product Detail Page Viewed","index":"products","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"]}]}`) }) t.Run("AddedToCartObjectIDs", func(t *testing.T) { _, err := client.PushEvents(client.NewApiPushEventsRequest( @@ -486,10 +488,10 @@ func TestInsights_PushEvents(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/events") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"events":[{"eventType":"conversion","eventSubtype":"addToCart","eventName":"Product Added To Cart","index":"products","queryID":"43b15df305339e827f0ac0bdc5ebcaa7","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"],"objectData":[{"price":19.99,"quantity":10,"discount":2.5},{"price":"8$","quantity":7,"discount":"30%%"}],"currency":"USD"}]}`) + ja.Assertf(*echo.Body, `{"events":[{"eventType":"conversion","eventSubtype":"addToCart","eventName":"Product Added To Cart","index":"products","queryID":"43b15df305339e827f0ac0bdc5ebcaa7","userToken":"user-123456","authenticatedUserToken":"user-123456","timestamp":1641290601962,"objectIDs":["9780545139700","9780439784542"],"objectData":[{"price":19.99,"quantity":10,"discount":2.5},{"price":"8$","quantity":7,"discount":"30%%"}],"currency":"USD"}]}`) }) } diff --git a/tests/output/go/tests/requests/monitoring_test.go b/tests/output/go/tests/requests/monitoring_test.go index 90ea369e16..004f998b08 100644 --- a/tests/output/go/tests/requests/monitoring_test.go +++ b/tests/output/go/tests/requests/monitoring_test.go @@ -1,4 +1,4 @@ -package tests +package requests import ( "encoding/json" @@ -8,20 +8,22 @@ import ( "github.com/kinbiko/jsonassert" "github.com/stretchr/testify/require" + "gotests/tests" + "github.com/algolia/algoliasearch-client-go/v4/algolia/monitoring" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -func createMonitoringClient() (*monitoring.APIClient, *echoRequester) { - echo := &echoRequester{} +func createMonitoringClient() (*monitoring.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} cfg := monitoring.Configuration{ - AppID: "appID", - ApiKey: "apiKey", - Requester: echo, + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, } - client := monitoring.NewClientWithConfig(cfg) - - // so that the linter doesn't complain - _ = jsonassert.New(nil) + client, _ := monitoring.NewClientWithConfig(cfg) return client, echo } @@ -37,10 +39,10 @@ func TestMonitoring_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow del method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomDelete(client.NewApiCustomDeleteRequest( @@ -50,14 +52,14 @@ func TestMonitoring_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -73,10 +75,10 @@ func TestMonitoring_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow get method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomGet(client.NewApiCustomGetRequest( @@ -86,14 +88,14 @@ func TestMonitoring_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -109,11 +111,11 @@ func TestMonitoring_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow post method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPost(client.NewApiCustomPostRequest( @@ -123,15 +125,15 @@ func TestMonitoring_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default query parameters", func(t *testing.T) { @@ -144,15 +146,15 @@ func TestMonitoring_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges query parameters with default ones", func(t *testing.T) { @@ -165,15 +167,15 @@ func TestMonitoring_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","query2":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default headers", func(t *testing.T) { @@ -186,20 +188,20 @@ func TestMonitoring_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges headers with default ones", func(t *testing.T) { @@ -212,20 +214,20 @@ func TestMonitoring_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts booleans", func(t *testing.T) { @@ -238,15 +240,15 @@ func TestMonitoring_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","isItWorking":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts integers", func(t *testing.T) { @@ -259,15 +261,15 @@ func TestMonitoring_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of string", func(t *testing.T) { @@ -281,15 +283,15 @@ func TestMonitoring_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"c,d"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of booleans", func(t *testing.T) { @@ -303,15 +305,15 @@ func TestMonitoring_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"true,true,false"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of integers", func(t *testing.T) { @@ -325,15 +327,15 @@ func TestMonitoring_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"1,2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -349,11 +351,11 @@ func TestMonitoring_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow put method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPut(client.NewApiCustomPutRequest( @@ -363,15 +365,15 @@ func TestMonitoring_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -387,10 +389,10 @@ func TestMonitoring_GetClusterIncidents(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/incidents/c1-de") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -405,10 +407,10 @@ func TestMonitoring_GetClusterStatus(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/status/c1-de") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -421,10 +423,10 @@ func TestMonitoring_GetIncidents(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/incidents") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -439,10 +441,10 @@ func TestMonitoring_GetIndexingTime(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexing/c1-de") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -455,10 +457,10 @@ func TestMonitoring_GetInventory(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/inventory/servers") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -473,10 +475,10 @@ func TestMonitoring_GetLatency(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/latency/c1-de") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -491,10 +493,10 @@ func TestMonitoring_GetMetrics(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/infrastructure/avg_build_time/period/minute") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -509,10 +511,10 @@ func TestMonitoring_GetReachability(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/reachability/c1-de/probes") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -525,9 +527,9 @@ func TestMonitoring_GetStatus(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/status") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } diff --git a/tests/output/go/tests/requests/personalization_test.go b/tests/output/go/tests/requests/personalization_test.go index e8977d9bdf..abd797dc7b 100644 --- a/tests/output/go/tests/requests/personalization_test.go +++ b/tests/output/go/tests/requests/personalization_test.go @@ -1,4 +1,4 @@ -package tests +package requests import ( "encoding/json" @@ -8,21 +8,23 @@ import ( "github.com/kinbiko/jsonassert" "github.com/stretchr/testify/require" + "gotests/tests" + "github.com/algolia/algoliasearch-client-go/v4/algolia/personalization" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -func createPersonalizationClient() (*personalization.APIClient, *echoRequester) { - echo := &echoRequester{} +func createPersonalizationClient() (*personalization.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} cfg := personalization.Configuration{ - AppID: "appID", - ApiKey: "apiKey", - Region: personalization.US, - Requester: echo, + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: personalization.US, } - client := personalization.NewClientWithConfig(cfg) - - // so that the linter doesn't complain - _ = jsonassert.New(nil) + client, _ := personalization.NewClientWithConfig(cfg) return client, echo } @@ -38,10 +40,10 @@ func TestPersonalization_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow del method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomDelete(client.NewApiCustomDeleteRequest( @@ -51,14 +53,14 @@ func TestPersonalization_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -74,10 +76,10 @@ func TestPersonalization_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow get method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomGet(client.NewApiCustomGetRequest( @@ -87,14 +89,14 @@ func TestPersonalization_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -110,11 +112,11 @@ func TestPersonalization_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow post method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPost(client.NewApiCustomPostRequest( @@ -124,15 +126,15 @@ func TestPersonalization_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default query parameters", func(t *testing.T) { @@ -145,15 +147,15 @@ func TestPersonalization_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges query parameters with default ones", func(t *testing.T) { @@ -166,15 +168,15 @@ func TestPersonalization_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","query2":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default headers", func(t *testing.T) { @@ -187,20 +189,20 @@ func TestPersonalization_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges headers with default ones", func(t *testing.T) { @@ -213,20 +215,20 @@ func TestPersonalization_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts booleans", func(t *testing.T) { @@ -239,15 +241,15 @@ func TestPersonalization_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","isItWorking":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts integers", func(t *testing.T) { @@ -260,15 +262,15 @@ func TestPersonalization_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of string", func(t *testing.T) { @@ -282,15 +284,15 @@ func TestPersonalization_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"c,d"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of booleans", func(t *testing.T) { @@ -304,15 +306,15 @@ func TestPersonalization_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"true,true,false"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of integers", func(t *testing.T) { @@ -326,15 +328,15 @@ func TestPersonalization_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"1,2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -350,11 +352,11 @@ func TestPersonalization_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow put method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPut(client.NewApiCustomPutRequest( @@ -364,15 +366,15 @@ func TestPersonalization_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -388,10 +390,10 @@ func TestPersonalization_DeleteUserProfile(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/profiles/UserToken") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -404,10 +406,10 @@ func TestPersonalization_GetPersonalizationStrategy(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/strategies/personalization") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -422,10 +424,10 @@ func TestPersonalization_GetUserTokenProfile(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/profiles/personalization/UserToken") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -443,10 +445,10 @@ func TestPersonalization_SetPersonalizationStrategy(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/strategies/personalization") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"eventScoring":[{"score":42,"eventName":"Algolia","eventType":"Event"}],"facetScoring":[{"score":42,"facetName":"Event"}],"personalizationImpact":42}`) + ja.Assertf(*echo.Body, `{"eventScoring":[{"score":42,"eventName":"Algolia","eventType":"Event"}],"facetScoring":[{"score":42,"facetName":"Event"}],"personalizationImpact":42}`) }) } diff --git a/tests/output/go/tests/requests/query-suggestions_test.go b/tests/output/go/tests/requests/query-suggestions_test.go index 9334537d44..79e5db6276 100644 --- a/tests/output/go/tests/requests/query-suggestions_test.go +++ b/tests/output/go/tests/requests/query-suggestions_test.go @@ -1,4 +1,4 @@ -package tests +package requests import ( "encoding/json" @@ -8,21 +8,23 @@ import ( "github.com/kinbiko/jsonassert" "github.com/stretchr/testify/require" + "gotests/tests" + suggestions "github.com/algolia/algoliasearch-client-go/v4/algolia/query-suggestions" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -func createSuggestionsClient() (*suggestions.APIClient, *echoRequester) { - echo := &echoRequester{} +func createSuggestionsClient() (*suggestions.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} cfg := suggestions.Configuration{ - AppID: "appID", - ApiKey: "apiKey", - Region: suggestions.US, - Requester: echo, + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, + Region: suggestions.US, } - client := suggestions.NewClientWithConfig(cfg) - - // so that the linter doesn't complain - _ = jsonassert.New(nil) + client, _ := suggestions.NewClientWithConfig(cfg) return client, echo } @@ -46,11 +48,11 @@ func TestSuggestions_CreateConfig(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/configs") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"indexName":"theIndexName","sourceIndices":[{"indexName":"testIndex","facets":[{"attribute":"test"}],"generate":[["facetA","facetB"],["facetC"]]}],"languages":["french"],"exclude":["test"]}`) + ja.Assertf(*echo.Body, `{"indexName":"theIndexName","sourceIndices":[{"indexName":"testIndex","facets":[{"attribute":"test"}],"generate":[["facetA","facetB"],["facetC"]]}],"languages":["french"],"exclude":["test"]}`) }) } @@ -65,10 +67,10 @@ func TestSuggestions_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow del method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomDelete(client.NewApiCustomDeleteRequest( @@ -78,14 +80,14 @@ func TestSuggestions_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -101,10 +103,10 @@ func TestSuggestions_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow get method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomGet(client.NewApiCustomGetRequest( @@ -114,14 +116,14 @@ func TestSuggestions_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -137,11 +139,11 @@ func TestSuggestions_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow post method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPost(client.NewApiCustomPostRequest( @@ -151,15 +153,15 @@ func TestSuggestions_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default query parameters", func(t *testing.T) { @@ -172,15 +174,15 @@ func TestSuggestions_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges query parameters with default ones", func(t *testing.T) { @@ -193,15 +195,15 @@ func TestSuggestions_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","query2":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default headers", func(t *testing.T) { @@ -214,20 +216,20 @@ func TestSuggestions_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges headers with default ones", func(t *testing.T) { @@ -240,20 +242,20 @@ func TestSuggestions_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts booleans", func(t *testing.T) { @@ -266,15 +268,15 @@ func TestSuggestions_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","isItWorking":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts integers", func(t *testing.T) { @@ -287,15 +289,15 @@ func TestSuggestions_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of string", func(t *testing.T) { @@ -309,15 +311,15 @@ func TestSuggestions_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"c,d"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of booleans", func(t *testing.T) { @@ -331,15 +333,15 @@ func TestSuggestions_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"true,true,false"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of integers", func(t *testing.T) { @@ -353,15 +355,15 @@ func TestSuggestions_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"1,2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -377,11 +379,11 @@ func TestSuggestions_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow put method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPut(client.NewApiCustomPutRequest( @@ -391,15 +393,15 @@ func TestSuggestions_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -415,10 +417,10 @@ func TestSuggestions_DeleteConfig(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/configs/theIndexName") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -431,10 +433,10 @@ func TestSuggestions_GetAllConfigs(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/configs") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -449,10 +451,10 @@ func TestSuggestions_GetConfig(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/configs/theIndexName") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -467,10 +469,10 @@ func TestSuggestions_GetConfigStatus(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/configs/theIndexName/status") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -485,10 +487,10 @@ func TestSuggestions_GetLogFile(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/logs/theIndexName") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -511,10 +513,10 @@ func TestSuggestions_UpdateConfig(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/configs/theIndexName") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"sourceIndices":[{"indexName":"testIndex","facets":[{"attribute":"test"}],"generate":[["facetA","facetB"],["facetC"]]}],"languages":["french"],"exclude":["test"]}`) + ja.Assertf(*echo.Body, `{"sourceIndices":[{"indexName":"testIndex","facets":[{"attribute":"test"}],"generate":[["facetA","facetB"],["facetC"]]}],"languages":["french"],"exclude":["test"]}`) }) } diff --git a/tests/output/go/tests/requests/recommend_test.go b/tests/output/go/tests/requests/recommend_test.go index 90aa97eb0d..bad1e12208 100644 --- a/tests/output/go/tests/requests/recommend_test.go +++ b/tests/output/go/tests/requests/recommend_test.go @@ -1,4 +1,4 @@ -package tests +package requests import ( "encoding/json" @@ -8,20 +8,22 @@ import ( "github.com/kinbiko/jsonassert" "github.com/stretchr/testify/require" + "gotests/tests" + "github.com/algolia/algoliasearch-client-go/v4/algolia/recommend" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -func createRecommendClient() (*recommend.APIClient, *echoRequester) { - echo := &echoRequester{} +func createRecommendClient() (*recommend.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} cfg := recommend.Configuration{ - AppID: "appID", - ApiKey: "apiKey", - Requester: echo, + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, } - client := recommend.NewClientWithConfig(cfg) - - // so that the linter doesn't complain - _ = jsonassert.New(nil) + client, _ := recommend.NewClientWithConfig(cfg) return client, echo } @@ -37,10 +39,10 @@ func TestRecommend_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow del method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomDelete(client.NewApiCustomDeleteRequest( @@ -50,14 +52,14 @@ func TestRecommend_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -73,10 +75,10 @@ func TestRecommend_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow get method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomGet(client.NewApiCustomGetRequest( @@ -86,14 +88,14 @@ func TestRecommend_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -109,11 +111,11 @@ func TestRecommend_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow post method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPost(client.NewApiCustomPostRequest( @@ -123,15 +125,15 @@ func TestRecommend_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default query parameters", func(t *testing.T) { @@ -144,15 +146,15 @@ func TestRecommend_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges query parameters with default ones", func(t *testing.T) { @@ -165,15 +167,15 @@ func TestRecommend_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","query2":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default headers", func(t *testing.T) { @@ -186,20 +188,20 @@ func TestRecommend_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges headers with default ones", func(t *testing.T) { @@ -212,20 +214,20 @@ func TestRecommend_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts booleans", func(t *testing.T) { @@ -238,15 +240,15 @@ func TestRecommend_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","isItWorking":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts integers", func(t *testing.T) { @@ -259,15 +261,15 @@ func TestRecommend_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of string", func(t *testing.T) { @@ -281,15 +283,15 @@ func TestRecommend_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"c,d"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of booleans", func(t *testing.T) { @@ -303,15 +305,15 @@ func TestRecommend_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"true,true,false"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of integers", func(t *testing.T) { @@ -325,15 +327,15 @@ func TestRecommend_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"1,2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -349,11 +351,11 @@ func TestRecommend_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow put method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPut(client.NewApiCustomPutRequest( @@ -363,15 +365,15 @@ func TestRecommend_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -387,10 +389,10 @@ func TestRecommend_DeleteRecommendRule(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/related-products/recommend/rules/objectID") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -405,10 +407,10 @@ func TestRecommend_GetRecommendRule(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/related-products/recommend/rules/objectID") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -423,10 +425,10 @@ func TestRecommend_GetRecommendStatus(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/related-products/task/12345") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -444,11 +446,11 @@ func TestRecommend_GetRecommendations(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/recommendations") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"indexName","objectID":"objectID","model":"related-products","threshold":42}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"indexName","objectID":"objectID","model":"related-products","threshold":42}]}`) }) t.Run("get recommendations for recommend model with all parameters", func(t *testing.T) { _, err := client.GetRecommendations(client.NewApiGetRecommendationsRequest( @@ -465,11 +467,11 @@ func TestRecommend_GetRecommendations(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/recommendations") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"indexName","objectID":"objectID","model":"related-products","threshold":42,"maxRecommendations":10,"queryParameters":{"query":"myQuery","facetFilters":["query"]},"fallbackParameters":{"query":"myQuery","facetFilters":["fallback"]}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"indexName","objectID":"objectID","model":"related-products","threshold":42,"maxRecommendations":10,"queryParameters":{"query":"myQuery","facetFilters":["query"]},"fallbackParameters":{"query":"myQuery","facetFilters":["fallback"]}}]}`) }) t.Run("get recommendations for trending model with minimal parameters", func(t *testing.T) { _, err := client.GetRecommendations(client.NewApiGetRecommendationsRequest( @@ -482,11 +484,11 @@ func TestRecommend_GetRecommendations(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/recommendations") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"indexName","model":"trending-items","threshold":42}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"indexName","model":"trending-items","threshold":42}]}`) }) t.Run("get recommendations for trending model with all parameters", func(t *testing.T) { _, err := client.GetRecommendations(client.NewApiGetRecommendationsRequest( @@ -503,11 +505,11 @@ func TestRecommend_GetRecommendations(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/recommendations") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"indexName","model":"trending-items","threshold":42,"maxRecommendations":10,"facetName":"myFacetName","facetValue":"myFacetValue","queryParameters":{"query":"myQuery","facetFilters":["query"]},"fallbackParameters":{"query":"myQuery","facetFilters":["fallback"]}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"indexName","model":"trending-items","threshold":42,"maxRecommendations":10,"facetName":"myFacetName","facetValue":"myFacetValue","queryParameters":{"query":"myQuery","facetFilters":["query"]},"fallbackParameters":{"query":"myQuery","facetFilters":["fallback"]}}]}`) }) t.Run("get multiple recommendations with minimal parameters", func(t *testing.T) { _, err := client.GetRecommendations(client.NewApiGetRecommendationsRequest( @@ -521,11 +523,11 @@ func TestRecommend_GetRecommendations(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/recommendations") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"indexName1","objectID":"objectID1","model":"related-products","threshold":21},{"indexName":"indexName2","objectID":"objectID2","model":"related-products","threshold":21}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"indexName1","objectID":"objectID1","model":"related-products","threshold":21},{"indexName":"indexName2","objectID":"objectID2","model":"related-products","threshold":21}]}`) }) t.Run("get multiple recommendations with all parameters", func(t *testing.T) { _, err := client.GetRecommendations(client.NewApiGetRecommendationsRequest( @@ -547,11 +549,11 @@ func TestRecommend_GetRecommendations(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/recommendations") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"indexName1","objectID":"objectID1","model":"related-products","threshold":21,"maxRecommendations":10,"queryParameters":{"query":"myQuery","facetFilters":["query1"]},"fallbackParameters":{"query":"myQuery","facetFilters":["fallback1"]}},{"indexName":"indexName2","objectID":"objectID2","model":"related-products","threshold":21,"maxRecommendations":10,"queryParameters":{"query":"myQuery","facetFilters":["query2"]},"fallbackParameters":{"query":"myQuery","facetFilters":["fallback2"]}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"indexName1","objectID":"objectID1","model":"related-products","threshold":21,"maxRecommendations":10,"queryParameters":{"query":"myQuery","facetFilters":["query1"]},"fallbackParameters":{"query":"myQuery","facetFilters":["fallback1"]}},{"indexName":"indexName2","objectID":"objectID2","model":"related-products","threshold":21,"maxRecommendations":10,"queryParameters":{"query":"myQuery","facetFilters":["query2"]},"fallbackParameters":{"query":"myQuery","facetFilters":["fallback2"]}}]}`) }) t.Run("get frequently bought together recommendations", func(t *testing.T) { _, err := client.GetRecommendations(client.NewApiGetRecommendationsRequest( @@ -564,11 +566,11 @@ func TestRecommend_GetRecommendations(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/recommendations") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"indexName1","objectID":"objectID1","model":"bought-together","threshold":42}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"indexName1","objectID":"objectID1","model":"bought-together","threshold":42}]}`) }) } @@ -583,10 +585,10 @@ func TestRecommend_SearchRecommendRules(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/related-products/recommend/rules/search") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) } diff --git a/tests/output/go/tests/requests/search_test.go b/tests/output/go/tests/requests/search_test.go index 8185aea717..1b4cdd23f4 100644 --- a/tests/output/go/tests/requests/search_test.go +++ b/tests/output/go/tests/requests/search_test.go @@ -1,4 +1,4 @@ -package tests +package requests import ( "encoding/json" @@ -8,20 +8,22 @@ import ( "github.com/kinbiko/jsonassert" "github.com/stretchr/testify/require" + "gotests/tests" + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" + "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) -func createSearchClient() (*search.APIClient, *echoRequester) { - echo := &echoRequester{} +func createSearchClient() (*search.APIClient, *tests.EchoRequester) { + echo := &tests.EchoRequester{} cfg := search.Configuration{ - AppID: "appID", - ApiKey: "apiKey", - Requester: echo, + Configuration: transport.Configuration{ + AppID: "appID", + ApiKey: "apiKey", + Requester: echo, + }, } - client := search.NewClientWithConfig(cfg) - - // so that the linter doesn't complain - _ = jsonassert.New(nil) + client, _ := search.NewClientWithConfig(cfg) return client, echo } @@ -39,11 +41,11 @@ func TestSearch_AddApiKey(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/keys") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"acl":["search","addObject"],"description":"my new api key","validity":300,"maxQueriesPerIPPerHour":100,"maxHitsPerQuery":20}`) + ja.Assertf(*echo.Body, `{"acl":["search","addObject"],"description":"my new api key","validity":300,"maxQueriesPerIPPerHour":100,"maxHitsPerQuery":20}`) }) } @@ -58,11 +60,11 @@ func TestSearch_AddOrUpdateObject(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/uniqueID") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"key":"value"}`) + ja.Assertf(*echo.Body, `{"key":"value"}`) }) } @@ -78,11 +80,11 @@ func TestSearch_AppendSource(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/security/sources/append") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"source":"theSource","description":"theDescription"}`) + ja.Assertf(*echo.Body, `{"source":"theSource","description":"theDescription"}`) }) } @@ -98,15 +100,15 @@ func TestSearch_AssignUserId(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/clusters/mapping") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"cluster":"theCluster"}`) + ja.Assertf(*echo.Body, `{"cluster":"theCluster"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-user-id":"userID"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } }) } @@ -124,11 +126,11 @@ func TestSearch_Batch(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"action":"addObject","body":{"key":"value"}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"action":"addObject","body":{"key":"value"}}]}`) }) t.Run("allows batch method with `clear` action", func(t *testing.T) { _, err := client.Batch(client.NewApiBatchRequest( @@ -140,11 +142,11 @@ func TestSearch_Batch(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"action":"clear","body":{"key":"value"}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"action":"clear","body":{"key":"value"}}]}`) }) t.Run("allows batch method with `delete` action", func(t *testing.T) { _, err := client.Batch(client.NewApiBatchRequest( @@ -156,11 +158,11 @@ func TestSearch_Batch(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"action":"delete","body":{"key":"value"}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"action":"delete","body":{"key":"value"}}]}`) }) t.Run("allows batch method with `deleteObject` action", func(t *testing.T) { _, err := client.Batch(client.NewApiBatchRequest( @@ -172,11 +174,11 @@ func TestSearch_Batch(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"action":"deleteObject","body":{"key":"value"}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"action":"deleteObject","body":{"key":"value"}}]}`) }) t.Run("allows batch method with `partialUpdateObject` action", func(t *testing.T) { _, err := client.Batch(client.NewApiBatchRequest( @@ -188,11 +190,11 @@ func TestSearch_Batch(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"action":"partialUpdateObject","body":{"key":"value"}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"action":"partialUpdateObject","body":{"key":"value"}}]}`) }) t.Run("allows batch method with `partialUpdateObjectNoCreate` action", func(t *testing.T) { _, err := client.Batch(client.NewApiBatchRequest( @@ -204,11 +206,11 @@ func TestSearch_Batch(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"action":"partialUpdateObjectNoCreate","body":{"key":"value"}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"action":"partialUpdateObjectNoCreate","body":{"key":"value"}}]}`) }) t.Run("allows batch method with `updateObject` action", func(t *testing.T) { _, err := client.Batch(client.NewApiBatchRequest( @@ -220,11 +222,11 @@ func TestSearch_Batch(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"action":"updateObject","body":{"key":"value"}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"action":"updateObject","body":{"key":"value"}}]}`) }) } @@ -241,15 +243,15 @@ func TestSearch_BatchAssignUserIds(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/clusters/mapping/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"cluster":"theCluster","users":["user1","user2"]}`) + ja.Assertf(*echo.Body, `{"cluster":"theCluster","users":["user1","user2"]}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-user-id":"userID"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } }) } @@ -269,11 +271,11 @@ func TestSearch_BatchDictionaryEntries(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/dictionaries/compounds/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"action":"addEntry","body":{"objectID":"1","language":"en"}},{"action":"deleteEntry","body":{"objectID":"2","language":"fr"}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"action":"addEntry","body":{"objectID":"1","language":"en"}},{"action":"deleteEntry","body":{"objectID":"2","language":"fr"}}]}`) }) t.Run("get batchDictionaryEntries results with all parameters", func(t *testing.T) { _, err := client.BatchDictionaryEntries(client.NewApiBatchDictionaryEntriesRequest( @@ -291,11 +293,11 @@ func TestSearch_BatchDictionaryEntries(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/dictionaries/compounds/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"clearExistingDictionaryEntries":false,"requests":[{"action":"addEntry","body":{"objectID":"1","language":"en","word":"fancy","words":["believe","algolia"],"decomposition":["trust","algolia"],"state":"enabled"}},{"action":"deleteEntry","body":{"objectID":"2","language":"fr","word":"humility","words":["candor","algolia"],"decomposition":["grit","algolia"],"state":"enabled"}}]}`) + ja.Assertf(*echo.Body, `{"clearExistingDictionaryEntries":false,"requests":[{"action":"addEntry","body":{"objectID":"1","language":"en","word":"fancy","words":["believe","algolia"],"decomposition":["trust","algolia"],"state":"enabled"}},{"action":"deleteEntry","body":{"objectID":"2","language":"fr","word":"humility","words":["candor","algolia"],"decomposition":["grit","algolia"],"state":"enabled"}}]}`) }) t.Run("get batchDictionaryEntries results additional properties", func(t *testing.T) { _, err := client.BatchDictionaryEntries(client.NewApiBatchDictionaryEntriesRequest( @@ -308,11 +310,11 @@ func TestSearch_BatchDictionaryEntries(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/dictionaries/compounds/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"action":"addEntry","body":{"objectID":"1","language":"en","additional":"try me"}}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"action":"addEntry","body":{"objectID":"1","language":"en","additional":"try me"}}]}`) }) } @@ -327,11 +329,11 @@ func TestSearch_Browse(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/cts_e2e_browse/browse") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("browse with search parameters", func(t *testing.T) { _, err := client.Browse(client.NewApiBrowseRequest( @@ -343,11 +345,11 @@ func TestSearch_Browse(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/browse") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"query":"myQuery","facetFilters":["tags:algolia"]}`) + ja.Assertf(*echo.Body, `{"query":"myQuery","facetFilters":["tags:algolia"]}`) }) t.Run("browse allow a cursor in parameters", func(t *testing.T) { _, err := client.Browse(client.NewApiBrowseRequest( @@ -358,11 +360,11 @@ func TestSearch_Browse(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/browse") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"cursor":"test"}`) + ja.Assertf(*echo.Body, `{"cursor":"test"}`) }) } @@ -377,10 +379,10 @@ func TestSearch_ClearObjects(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/clear") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) - require.Empty(t, echo.body) + require.Empty(t, echo.Body) }) } @@ -395,10 +397,10 @@ func TestSearch_ClearRules(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/rules/clear") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) - require.Empty(t, echo.body) + require.Empty(t, echo.Body) }) } @@ -413,10 +415,10 @@ func TestSearch_ClearSynonyms(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/synonyms/clear") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) - require.Empty(t, echo.body) + require.Empty(t, echo.Body) }) } @@ -431,10 +433,10 @@ func TestSearch_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow del method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomDelete(client.NewApiCustomDeleteRequest( @@ -444,14 +446,14 @@ func TestSearch_CustomDelete(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -467,10 +469,10 @@ func TestSearch_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("allow get method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomGet(client.NewApiCustomGetRequest( @@ -480,14 +482,14 @@ func TestSearch_CustomGet(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -503,11 +505,11 @@ func TestSearch_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow post method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPost(client.NewApiCustomPostRequest( @@ -517,15 +519,15 @@ func TestSearch_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default query parameters", func(t *testing.T) { @@ -538,15 +540,15 @@ func TestSearch_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges query parameters with default ones", func(t *testing.T) { @@ -559,15 +561,15 @@ func TestSearch_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","query2":"myQueryParameter"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions can override default headers", func(t *testing.T) { @@ -580,20 +582,20 @@ func TestSearch_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions merges headers with default ones", func(t *testing.T) { @@ -606,20 +608,20 @@ func TestSearch_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) headers := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"x-algolia-api-key":"myApiKey"}`), &headers)) for k, v := range headers { - require.Equal(t, v, echo.header.Get(k)) + require.Equal(t, v, echo.Header.Get(k)) } queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts booleans", func(t *testing.T) { @@ -632,15 +634,15 @@ func TestSearch_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","isItWorking":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts integers", func(t *testing.T) { @@ -653,15 +655,15 @@ func TestSearch_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of string", func(t *testing.T) { @@ -675,15 +677,15 @@ func TestSearch_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"c,d"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of booleans", func(t *testing.T) { @@ -697,15 +699,15 @@ func TestSearch_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"true,true,false"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("requestOptions queryParameters accepts list of integers", func(t *testing.T) { @@ -719,15 +721,15 @@ func TestSearch_CustomPost(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/requestOptions") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"facet":"filters"}`) + ja.Assertf(*echo.Body, `{"facet":"filters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters","myParam":"1,2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -743,11 +745,11 @@ func TestSearch_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/minimal") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("allow put method for a custom path with all parameters", func(t *testing.T) { _, err := client.CustomPut(client.NewApiCustomPutRequest( @@ -757,15 +759,15 @@ func TestSearch_CustomPut(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/test/all") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"body":"parameters"}`) + ja.Assertf(*echo.Body, `{"body":"parameters"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"query":"parameters"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -781,10 +783,10 @@ func TestSearch_DeleteApiKey(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/keys/myTestApiKey") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -800,11 +802,11 @@ func TestSearch_DeleteBy(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/deleteByQuery") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"filters":"brand:brandName"}`) + ja.Assertf(*echo.Body, `{"filters":"brand:brandName"}`) }) } @@ -819,10 +821,10 @@ func TestSearch_DeleteIndex(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -837,10 +839,10 @@ func TestSearch_DeleteObject(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/uniqueID") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -855,10 +857,10 @@ func TestSearch_DeleteRule(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/rules/id1") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("delete rule with simple characters to encode in objectID", func(t *testing.T) { _, err := client.DeleteRule(client.NewApiDeleteRuleRequest( @@ -868,10 +870,10 @@ func TestSearch_DeleteRule(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/rules/test%2Fwith%2Fslash") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -886,10 +888,10 @@ func TestSearch_DeleteSource(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/security/sources/theSource") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -904,10 +906,10 @@ func TestSearch_DeleteSynonym(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/synonyms/id1") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -922,10 +924,10 @@ func TestSearch_GetApiKey(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/keys/myTestApiKey") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -938,10 +940,10 @@ func TestSearch_GetDictionaryLanguages(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/dictionaries/*/languages") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -954,10 +956,10 @@ func TestSearch_GetDictionarySettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/dictionaries/*/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -970,10 +972,10 @@ func TestSearch_GetLogs(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/logs") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("getLogs with parameters", func(t *testing.T) { _, err := client.GetLogs(client.NewApiGetLogsRequest().WithOffset(5).WithLength(10).WithIndexName("theIndexName").WithType(search.LogType("all"))) @@ -981,14 +983,14 @@ func TestSearch_GetLogs(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/logs") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"offset":"5","length":"10","indexName":"theIndexName","type":"all"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1005,14 +1007,14 @@ func TestSearch_GetObject(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/uniqueID") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"attributesToRetrieve":"attr1,attr2"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1031,11 +1033,11 @@ func TestSearch_GetObjects(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/objects") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"attributesToRetrieve":["attr1","attr2"],"objectID":"uniqueID","indexName":"theIndexName"}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"attributesToRetrieve":["attr1","attr2"],"objectID":"uniqueID","indexName":"theIndexName"}]}`) }) } @@ -1050,10 +1052,10 @@ func TestSearch_GetRule(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/rules/id1") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -1068,10 +1070,10 @@ func TestSearch_GetSettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/cts_e2e_settings/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -1084,10 +1086,10 @@ func TestSearch_GetSources(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/security/sources") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -1102,10 +1104,10 @@ func TestSearch_GetSynonym(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/synonyms/id1") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -1120,10 +1122,10 @@ func TestSearch_GetTask(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/task/123") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -1136,10 +1138,10 @@ func TestSearch_GetTopUserIds(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/clusters/mapping/top") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -1154,10 +1156,10 @@ func TestSearch_GetUserId(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/clusters/mapping/uniqueID") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -1170,10 +1172,10 @@ func TestSearch_HasPendingMappings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/clusters/mapping/pending") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("hasPendingMappings with parameters", func(t *testing.T) { _, err := client.HasPendingMappings(client.NewApiHasPendingMappingsRequest().WithGetClusters(true)) @@ -1181,14 +1183,14 @@ func TestSearch_HasPendingMappings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/clusters/mapping/pending") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"getClusters":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1202,10 +1204,10 @@ func TestSearch_ListApiKeys(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/keys") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -1218,10 +1220,10 @@ func TestSearch_ListClusters(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/clusters") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -1234,10 +1236,10 @@ func TestSearch_ListIndices(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("listIndices with parameters", func(t *testing.T) { _, err := client.ListIndices(client.NewApiListIndicesRequest().WithPage(8).WithHitsPerPage(3)) @@ -1245,14 +1247,14 @@ func TestSearch_ListIndices(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"page":"8","hitsPerPage":"3"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1266,10 +1268,10 @@ func TestSearch_ListUserIds(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/clusters/mapping") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) t.Run("listUserIds with parameters", func(t *testing.T) { _, err := client.ListUserIds(client.NewApiListUserIdsRequest().WithPage(8).WithHitsPerPage(100)) @@ -1277,14 +1279,14 @@ func TestSearch_ListUserIds(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/clusters/mapping") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "GET", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "GET", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"page":"8","hitsPerPage":"100"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1302,11 +1304,11 @@ func TestSearch_MultipleBatch(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"action":"addObject","body":{"key":"value"},"indexName":"theIndexName"}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"action":"addObject","body":{"key":"value"},"indexName":"theIndexName"}]}`) }) } @@ -1323,11 +1325,11 @@ func TestSearch_OperationIndex(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/operation") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"operation":"copy","destination":"dest","scope":["rules","settings"]}`) + ja.Assertf(*echo.Body, `{"operation":"copy","destination":"dest","scope":["rules","settings"]}`) }) } @@ -1343,15 +1345,15 @@ func TestSearch_PartialUpdateObject(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/uniqueID/partial") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"id1":"test","id2":{"_operation":"AddUnique","value":"test2"}}`) + ja.Assertf(*echo.Body, `{"id1":"test","id2":{"_operation":"AddUnique","value":"test2"}}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"createIfNotExists":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1367,10 +1369,10 @@ func TestSearch_RemoveUserId(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/clusters/mapping/uniqueID") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "DELETE", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "DELETE", echo.Method) - require.Nil(t, echo.body) + require.Nil(t, echo.Body) }) } @@ -1386,11 +1388,11 @@ func TestSearch_ReplaceSources(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/security/sources") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `[{"source":"theSource","description":"theDescription"}]`) + ja.Assertf(*echo.Body, `[{"source":"theSource","description":"theDescription"}]`) }) } @@ -1405,10 +1407,10 @@ func TestSearch_RestoreApiKey(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/keys/myApiKey/restore") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) - require.Empty(t, echo.body) + require.Empty(t, echo.Body) }) } @@ -1423,11 +1425,11 @@ func TestSearch_SaveObject(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"objectID":"id","test":"val"}`) + ja.Assertf(*echo.Body, `{"objectID":"id","test":"val"}`) }) } @@ -1444,11 +1446,11 @@ func TestSearch_SaveRule(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/rules/id1") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"objectID":"id1","conditions":[{"pattern":"apple","anchoring":"contains"}]}`) + ja.Assertf(*echo.Body, `{"objectID":"id1","conditions":[{"pattern":"apple","anchoring":"contains"}]}`) }) t.Run("saveRule with all parameters", func(t *testing.T) { _, err := client.SaveRule(client.NewApiSaveRuleRequest( @@ -1471,15 +1473,15 @@ func TestSearch_SaveRule(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/rules/id1") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"objectID":"id1","conditions":[{"pattern":"apple","anchoring":"contains","alternatives":false,"context":"search"}],"consequence":{"params":{"filters":"brand:apple","query":{"remove":["algolia"],"edits":[{"type":"remove","delete":"abc","insert":"cde"},{"type":"replace","delete":"abc","insert":"cde"}]}},"hide":[{"objectID":"321"}],"filterPromotes":false,"userData":{"algolia":"aloglia"},"promote":[{"objectID":"abc","position":3},{"objectIDs":["abc","def"],"position":1}]},"description":"test","enabled":true,"validity":[{"from":1656670273,"until":1656670277}]}`) + ja.Assertf(*echo.Body, `{"objectID":"id1","conditions":[{"pattern":"apple","anchoring":"contains","alternatives":false,"context":"search"}],"consequence":{"params":{"filters":"brand:apple","query":{"remove":["algolia"],"edits":[{"type":"remove","delete":"abc","insert":"cde"},{"type":"replace","delete":"abc","insert":"cde"}]}},"hide":[{"objectID":"321"}],"filterPromotes":false,"userData":{"algolia":"aloglia"},"promote":[{"objectID":"abc","position":3},{"objectIDs":["abc","def"],"position":1}]},"description":"test","enabled":true,"validity":[{"from":1656670273,"until":1656670277}]}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1498,11 +1500,11 @@ func TestSearch_SaveRules(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/rules/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `[{"objectID":"a-rule-id","conditions":[{"pattern":"smartphone","anchoring":"contains"}]},{"objectID":"a-second-rule-id","conditions":[{"pattern":"apple","anchoring":"contains"}]}]`) + ja.Assertf(*echo.Body, `[{"objectID":"a-rule-id","conditions":[{"pattern":"smartphone","anchoring":"contains"}]},{"objectID":"a-second-rule-id","conditions":[{"pattern":"apple","anchoring":"contains"}]}]`) }) t.Run("saveRules with all parameters", func(t *testing.T) { _, err := client.SaveRules(client.NewApiSaveRulesRequest( @@ -1525,15 +1527,15 @@ func TestSearch_SaveRules(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/rules/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `[{"objectID":"id1","conditions":[{"pattern":"apple","anchoring":"contains","alternatives":false,"context":"search"}],"consequence":{"params":{"filters":"brand:apple","query":{"remove":["algolia"],"edits":[{"type":"remove","delete":"abc","insert":"cde"},{"type":"replace","delete":"abc","insert":"cde"}]}},"hide":[{"objectID":"321"}],"filterPromotes":false,"userData":{"algolia":"aloglia"},"promote":[{"objectID":"abc","position":3},{"objectIDs":["abc","def"],"position":1}]},"description":"test","enabled":true,"validity":[{"from":1656670273,"until":1656670277}]}]`) + ja.Assertf(*echo.Body, `[{"objectID":"id1","conditions":[{"pattern":"apple","anchoring":"contains","alternatives":false,"context":"search"}],"consequence":{"params":{"filters":"brand:apple","query":{"remove":["algolia"],"edits":[{"type":"remove","delete":"abc","insert":"cde"},{"type":"replace","delete":"abc","insert":"cde"}]}},"hide":[{"objectID":"321"}],"filterPromotes":false,"userData":{"algolia":"aloglia"},"promote":[{"objectID":"abc","position":3},{"objectIDs":["abc","def"],"position":1}]},"description":"test","enabled":true,"validity":[{"from":1656670273,"until":1656670277}]}]`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true","clearExistingRules":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1551,15 +1553,15 @@ func TestSearch_SaveSynonym(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/synonyms/id1") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"objectID":"id1","type":"synonym","synonyms":["car","vehicule","auto"]}`) + ja.Assertf(*echo.Body, `{"objectID":"id1","type":"synonym","synonyms":["car","vehicule","auto"]}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1578,15 +1580,15 @@ func TestSearch_SaveSynonyms(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/synonyms/batch") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `[{"objectID":"id1","type":"synonym","synonyms":["car","vehicule","auto"]},{"objectID":"id2","type":"onewaysynonym","input":"iphone","synonyms":["ephone","aphone","yphone"]}]`) + ja.Assertf(*echo.Body, `[{"objectID":"id1","type":"synonym","synonyms":["car","vehicule","auto"]},{"objectID":"id2","type":"onewaysynonym","input":"iphone","synonyms":["ephone","aphone","yphone"]}]`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true","replaceExistingSynonyms":"false"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1605,11 +1607,11 @@ func TestSearch_Search(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/queries") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"cts_e2e_search_empty_index"}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"cts_e2e_search_empty_index"}]}`) }) t.Run("search for a single facet request with minimal parameters", func(t *testing.T) { _, err := client.Search(client.NewApiSearchRequest( @@ -1622,11 +1624,11 @@ func TestSearch_Search(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/queries") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"cts_e2e_search_facet","type":"facet","facet":"editor"}],"strategy":"stopIfEnoughMatches"}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"cts_e2e_search_facet","type":"facet","facet":"editor"}],"strategy":"stopIfEnoughMatches"}`) }) t.Run("search for a single hits request with all parameters", func(t *testing.T) { _, err := client.Search(client.NewApiSearchRequest( @@ -1639,11 +1641,11 @@ func TestSearch_Search(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/queries") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"theIndexName","query":"myQuery","hitsPerPage":50,"type":"default"}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"theIndexName","query":"myQuery","hitsPerPage":50,"type":"default"}]}`) }) t.Run("search for a single facet request with all parameters", func(t *testing.T) { _, err := client.Search(client.NewApiSearchRequest( @@ -1656,11 +1658,11 @@ func TestSearch_Search(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/queries") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"theIndexName","type":"facet","facet":"theFacet","facetQuery":"theFacetQuery","query":"theQuery","maxFacetHits":50}],"strategy":"stopIfEnoughMatches"}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"theIndexName","type":"facet","facet":"theFacet","facetQuery":"theFacetQuery","query":"theQuery","maxFacetHits":50}],"strategy":"stopIfEnoughMatches"}`) }) t.Run("search for multiple mixed requests in multiple indices with minimal parameters", func(t *testing.T) { _, err := client.Search(client.NewApiSearchRequest( @@ -1675,11 +1677,11 @@ func TestSearch_Search(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/queries") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"theIndexName"},{"indexName":"theIndexName2","type":"facet","facet":"theFacet"},{"indexName":"theIndexName","type":"default"}],"strategy":"stopIfEnoughMatches"}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"theIndexName"},{"indexName":"theIndexName2","type":"facet","facet":"theFacet"},{"indexName":"theIndexName","type":"default"}],"strategy":"stopIfEnoughMatches"}`) }) t.Run("search for multiple mixed requests in multiple indices with all parameters", func(t *testing.T) { _, err := client.Search(client.NewApiSearchRequest( @@ -1693,11 +1695,11 @@ func TestSearch_Search(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/queries") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"theIndexName","type":"facet","facet":"theFacet","facetQuery":"theFacetQuery","query":"theQuery","maxFacetHits":50},{"indexName":"theIndexName","query":"myQuery","hitsPerPage":50,"type":"default"}],"strategy":"stopIfEnoughMatches"}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"theIndexName","type":"facet","facet":"theFacet","facetQuery":"theFacetQuery","query":"theQuery","maxFacetHits":50},{"indexName":"theIndexName","query":"myQuery","hitsPerPage":50,"type":"default"}],"strategy":"stopIfEnoughMatches"}`) }) t.Run("search filters accept all of the possible shapes", func(t *testing.T) { _, err := client.Search(client.NewApiSearchRequest( @@ -1721,11 +1723,11 @@ func TestSearch_Search(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/queries") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"indexName":"theIndexName","facetFilters":"mySearch:filters","reRankingApplyFilter":"mySearch:filters","tagFilters":"mySearch:filters","numericFilters":"mySearch:filters","optionalFilters":"mySearch:filters"},{"indexName":"theIndexName","facetFilters":["mySearch:filters",["mySearch:filters"]],"reRankingApplyFilter":["mySearch:filters",["mySearch:filters"]],"tagFilters":["mySearch:filters",["mySearch:filters"]],"numericFilters":["mySearch:filters",["mySearch:filters"]],"optionalFilters":["mySearch:filters",["mySearch:filters"]]}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"indexName":"theIndexName","facetFilters":"mySearch:filters","reRankingApplyFilter":"mySearch:filters","tagFilters":"mySearch:filters","numericFilters":"mySearch:filters","optionalFilters":"mySearch:filters"},{"indexName":"theIndexName","facetFilters":["mySearch:filters",["mySearch:filters"]],"reRankingApplyFilter":["mySearch:filters",["mySearch:filters"]],"tagFilters":["mySearch:filters",["mySearch:filters"]],"numericFilters":["mySearch:filters",["mySearch:filters"]],"optionalFilters":["mySearch:filters",["mySearch:filters"]]}]}`) }) t.Run("search with all search parameters", func(t *testing.T) { _, err := client.Search(client.NewApiSearchRequest( @@ -1773,11 +1775,11 @@ func TestSearch_Search(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/*/queries") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"requests":[{"advancedSyntax":true,"advancedSyntaxFeatures":["exactPhrase"],"allowTyposOnNumericTokens":true,"alternativesAsExact":["multiWordsSynonym"],"analytics":true,"analyticsTags":[""],"aroundLatLng":"","aroundLatLngViaIP":true,"aroundPrecision":0,"aroundRadius":"all","attributeCriteriaComputedByMinProximity":true,"attributesForFaceting":[""],"attributesToHighlight":[""],"attributesToRetrieve":[""],"attributesToSnippet":[""],"clickAnalytics":true,"customRanking":[""],"decompoundQuery":true,"disableExactOnAttributes":[""],"disableTypoToleranceOnAttributes":[""],"distinct":0,"enableABTest":true,"enablePersonalization":true,"enableReRanking":true,"enableRules":true,"exactOnSingleWordQuery":"attribute","explain":["foo","bar"],"facetFilters":[""],"facetingAfterDistinct":true,"facets":[""],"filters":"","getRankingInfo":true,"highlightPostTag":"","highlightPreTag":"","hitsPerPage":1,"ignorePlurals":false,"indexName":"theIndexName","insideBoundingBox":[[47.3165,4.9665,47.3424,5.0201],[40.9234,2.1185,38.643,1.9916]],"insidePolygon":[[47.3165,4.9665,47.3424,5.0201,47.32,4.9],[40.9234,2.1185,38.643,1.9916,39.2587,2.0104]],"keepDiacriticsOnCharacters":"","length":1,"maxValuesPerFacet":0,"minProximity":1,"minWordSizefor1Typo":0,"minWordSizefor2Typos":0,"minimumAroundRadius":1,"naturalLanguages":[""],"numericFilters":[""],"offset":0,"optionalFilters":[""],"optionalWords":[""],"page":0,"percentileComputation":true,"personalizationImpact":0,"query":"","queryLanguages":[""],"queryType":"prefixAll","ranking":[""],"reRankingApplyFilter":[""],"relevancyStrictness":0,"removeStopWords":true,"removeWordsIfNoResults":"allOptional","renderingContent":{"facetOrdering":{"facets":{"order":["a","b"]},"values":{"a":{"order":["b"],"sortRemainingBy":"count"}}}},"replaceSynonymsInHighlight":true,"responseFields":[""],"restrictHighlightAndSnippetArrays":true,"restrictSearchableAttributes":[""],"ruleContexts":[""],"similarQuery":"","snippetEllipsisText":"","sortFacetValuesBy":"","sumOrFiltersScores":true,"synonyms":true,"tagFilters":[""],"type":"default","typoTolerance":"min","userToken":""}]}`) + ja.Assertf(*echo.Body, `{"requests":[{"advancedSyntax":true,"advancedSyntaxFeatures":["exactPhrase"],"allowTyposOnNumericTokens":true,"alternativesAsExact":["multiWordsSynonym"],"analytics":true,"analyticsTags":[""],"aroundLatLng":"","aroundLatLngViaIP":true,"aroundPrecision":0,"aroundRadius":"all","attributeCriteriaComputedByMinProximity":true,"attributesForFaceting":[""],"attributesToHighlight":[""],"attributesToRetrieve":[""],"attributesToSnippet":[""],"clickAnalytics":true,"customRanking":[""],"decompoundQuery":true,"disableExactOnAttributes":[""],"disableTypoToleranceOnAttributes":[""],"distinct":0,"enableABTest":true,"enablePersonalization":true,"enableReRanking":true,"enableRules":true,"exactOnSingleWordQuery":"attribute","explain":["foo","bar"],"facetFilters":[""],"facetingAfterDistinct":true,"facets":[""],"filters":"","getRankingInfo":true,"highlightPostTag":"","highlightPreTag":"","hitsPerPage":1,"ignorePlurals":false,"indexName":"theIndexName","insideBoundingBox":[[47.3165,4.9665,47.3424,5.0201],[40.9234,2.1185,38.643,1.9916]],"insidePolygon":[[47.3165,4.9665,47.3424,5.0201,47.32,4.9],[40.9234,2.1185,38.643,1.9916,39.2587,2.0104]],"keepDiacriticsOnCharacters":"","length":1,"maxValuesPerFacet":0,"minProximity":1,"minWordSizefor1Typo":0,"minWordSizefor2Typos":0,"minimumAroundRadius":1,"naturalLanguages":[""],"numericFilters":[""],"offset":0,"optionalFilters":[""],"optionalWords":[""],"page":0,"percentileComputation":true,"personalizationImpact":0,"query":"","queryLanguages":[""],"queryType":"prefixAll","ranking":[""],"reRankingApplyFilter":[""],"relevancyStrictness":0,"removeStopWords":true,"removeWordsIfNoResults":"allOptional","renderingContent":{"facetOrdering":{"facets":{"order":["a","b"]},"values":{"a":{"order":["b"],"sortRemainingBy":"count"}}}},"replaceSynonymsInHighlight":true,"responseFields":[""],"restrictHighlightAndSnippetArrays":true,"restrictSearchableAttributes":[""],"ruleContexts":[""],"similarQuery":"","snippetEllipsisText":"","sortFacetValuesBy":"","sumOrFiltersScores":true,"synonyms":true,"tagFilters":[""],"type":"default","typoTolerance":"min","userToken":""}]}`) }) } @@ -1793,11 +1795,11 @@ func TestSearch_SearchDictionaryEntries(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/dictionaries/compounds/search") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"query":"foo"}`) + ja.Assertf(*echo.Body, `{"query":"foo"}`) }) t.Run("get searchDictionaryEntries results with all parameters", func(t *testing.T) { _, err := client.SearchDictionaryEntries(client.NewApiSearchDictionaryEntriesRequest( @@ -1808,11 +1810,11 @@ func TestSearch_SearchDictionaryEntries(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/dictionaries/compounds/search") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"query":"foo","page":4,"hitsPerPage":2,"language":"fr"}`) + ja.Assertf(*echo.Body, `{"query":"foo","page":4,"hitsPerPage":2,"language":"fr"}`) }) } @@ -1827,11 +1829,11 @@ func TestSearch_SearchForFacetValues(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/facets/facetName/query") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("get searchForFacetValues results with all parameters", func(t *testing.T) { _, err := client.SearchForFacetValues(client.NewApiSearchForFacetValuesRequest( @@ -1842,11 +1844,11 @@ func TestSearch_SearchForFacetValues(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/facets/facetName/query") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"params":"query=foo&facetFilters=['bar']","facetQuery":"foo","maxFacetHits":42}`) + ja.Assertf(*echo.Body, `{"params":"query=foo&facetFilters=['bar']","facetQuery":"foo","maxFacetHits":42}`) }) } @@ -1862,11 +1864,11 @@ func TestSearch_SearchRules(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/rules/search") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"query":"something"}`) + ja.Assertf(*echo.Body, `{"query":"something"}`) }) } @@ -1881,11 +1883,11 @@ func TestSearch_SearchSingleIndex(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/query") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("search with special characters in indexName", func(t *testing.T) { _, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest( @@ -1895,11 +1897,11 @@ func TestSearch_SearchSingleIndex(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/cts_e2e_space%20in%20index/query") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("search with searchParams", func(t *testing.T) { _, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest( @@ -1911,11 +1913,11 @@ func TestSearch_SearchSingleIndex(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/query") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"query":"myQuery","facetFilters":["tags:algolia"]}`) + ja.Assertf(*echo.Body, `{"query":"myQuery","facetFilters":["tags:algolia"]}`) }) } @@ -1930,11 +1932,11 @@ func TestSearch_SearchSynonyms(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/synonyms/search") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{}`) + ja.Assertf(*echo.Body, `{}`) }) t.Run("searchSynonyms with all parameters", func(t *testing.T) { _, err := client.SearchSynonyms(client.NewApiSearchSynonymsRequest( @@ -1945,15 +1947,15 @@ func TestSearch_SearchSynonyms(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/indexName/synonyms/search") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"query":"myQuery"}`) + ja.Assertf(*echo.Body, `{"query":"myQuery"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"type":"altcorrection1","page":"10","hitsPerPage":"10"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) } @@ -1970,11 +1972,11 @@ func TestSearch_SearchUserIds(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/clusters/mapping/search") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "POST", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "POST", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"query":"test","clusterName":"theClusterName","page":5,"hitsPerPage":10}`) + ja.Assertf(*echo.Body, `{"query":"test","clusterName":"theClusterName","page":5,"hitsPerPage":10}`) }) } @@ -1991,11 +1993,11 @@ func TestSearch_SetDictionarySettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/dictionaries/*/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"disableStandardEntries":{"plurals":{"fr":false,"en":false,"ru":true}}}`) + ja.Assertf(*echo.Body, `{"disableStandardEntries":{"plurals":{"fr":false,"en":false,"ru":true}}}`) }) t.Run("get setDictionarySettings results with all parameters", func(t *testing.T) { _, err := client.SetDictionarySettings(client.NewApiSetDictionarySettingsRequest( @@ -2007,11 +2009,11 @@ func TestSearch_SetDictionarySettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/dictionaries/*/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"disableStandardEntries":{"plurals":{"fr":false,"en":false,"ru":true},"stopwords":{"fr":false},"compounds":{"ru":true}}}`) + ja.Assertf(*echo.Body, `{"disableStandardEntries":{"plurals":{"fr":false,"en":false,"ru":true},"stopwords":{"fr":false},"compounds":{"ru":true}}}`) }) } @@ -2027,15 +2029,15 @@ func TestSearch_SetSettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/cts_e2e_settings/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"paginationLimitedTo":10}`) + ja.Assertf(*echo.Body, `{"paginationLimitedTo":10}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("setSettings allow boolean `typoTolerance`", func(t *testing.T) { @@ -2047,15 +2049,15 @@ func TestSearch_SetSettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"typoTolerance":true}`) + ja.Assertf(*echo.Body, `{"typoTolerance":true}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("setSettings allow enum `typoTolerance`", func(t *testing.T) { @@ -2067,15 +2069,15 @@ func TestSearch_SetSettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"typoTolerance":"min"}`) + ja.Assertf(*echo.Body, `{"typoTolerance":"min"}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("setSettings allow boolean `ignorePlurals`", func(t *testing.T) { @@ -2087,15 +2089,15 @@ func TestSearch_SetSettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"ignorePlurals":true}`) + ja.Assertf(*echo.Body, `{"ignorePlurals":true}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("setSettings allow list of string `ignorePlurals`", func(t *testing.T) { @@ -2108,15 +2110,15 @@ func TestSearch_SetSettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"ignorePlurals":["algolia"]}`) + ja.Assertf(*echo.Body, `{"ignorePlurals":["algolia"]}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("setSettings allow boolean `removeStopWords`", func(t *testing.T) { @@ -2128,15 +2130,15 @@ func TestSearch_SetSettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"removeStopWords":true}`) + ja.Assertf(*echo.Body, `{"removeStopWords":true}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("setSettings allow list of string `removeStopWords`", func(t *testing.T) { @@ -2149,15 +2151,15 @@ func TestSearch_SetSettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"removeStopWords":["algolia"]}`) + ja.Assertf(*echo.Body, `{"removeStopWords":["algolia"]}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("setSettings allow boolean `distinct`", func(t *testing.T) { @@ -2169,15 +2171,15 @@ func TestSearch_SetSettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"distinct":true}`) + ja.Assertf(*echo.Body, `{"distinct":true}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("setSettings allow integers for `distinct`", func(t *testing.T) { @@ -2189,15 +2191,15 @@ func TestSearch_SetSettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"distinct":1}`) + ja.Assertf(*echo.Body, `{"distinct":1}`) queryParams := map[string]string{} require.NoError(t, json.Unmarshal([]byte(`{"forwardToReplicas":"true"}`), &queryParams)) for k, v := range queryParams { - require.Equal(t, v, echo.query.Get(k)) + require.Equal(t, v, echo.Query.Get(k)) } }) t.Run("setSettings allow all `indexSettings`", func(t *testing.T) { @@ -2238,11 +2240,11 @@ func TestSearch_SetSettings(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/indexes/theIndexName/settings") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"advancedSyntax":true,"advancedSyntaxFeatures":["exactPhrase"],"allowCompressionOfIntegerArray":true,"allowTyposOnNumericTokens":true,"alternativesAsExact":["singleWordSynonym"],"attributeCriteriaComputedByMinProximity":true,"attributeForDistinct":"test","attributesForFaceting":["algolia"],"attributesToHighlight":["algolia"],"attributesToRetrieve":["algolia"],"attributesToSnippet":["algolia"],"attributesToTransliterate":["algolia"],"camelCaseAttributes":["algolia"],"customNormalization":{"algolia":{"aloglia":"aglolia"}},"customRanking":["algolia"],"decompoundQuery":false,"decompoundedAttributes":{"algolia":"aloglia"},"disableExactOnAttributes":["algolia"],"disablePrefixOnAttributes":["algolia"],"disableTypoToleranceOnAttributes":["algolia"],"disableTypoToleranceOnWords":["algolia"],"distinct":3,"enablePersonalization":true,"enableReRanking":false,"enableRules":true,"exactOnSingleWordQuery":"attribute","highlightPreTag":"","highlightPostTag":"","hitsPerPage":10,"ignorePlurals":false,"indexLanguages":["algolia"],"keepDiacriticsOnCharacters":"abc","maxFacetHits":20,"maxValuesPerFacet":30,"minProximity":6,"minWordSizefor1Typo":5,"minWordSizefor2Typos":11,"mode":"neuralSearch","numericAttributesForFiltering":["algolia"],"optionalWords":["myspace"],"paginationLimitedTo":0,"queryLanguages":["algolia"],"queryType":"prefixLast","ranking":["geo"],"reRankingApplyFilter":"mySearch:filters","relevancyStrictness":10,"removeStopWords":false,"removeWordsIfNoResults":"lastWords","renderingContent":{"facetOrdering":{"facets":{"order":["a","b"]},"values":{"a":{"order":["b"],"sortRemainingBy":"count"}}}},"replaceSynonymsInHighlight":true,"replicas":[""],"responseFields":["algolia"],"restrictHighlightAndSnippetArrays":true,"searchableAttributes":["foo"],"semanticSearch":{"eventSources":["foo"]},"separatorsToIndex":"bar","snippetEllipsisText":"---","sortFacetValuesBy":"date","typoTolerance":false,"unretrievableAttributes":["foo"],"userData":{"user":"data"}}`) + ja.Assertf(*echo.Body, `{"advancedSyntax":true,"advancedSyntaxFeatures":["exactPhrase"],"allowCompressionOfIntegerArray":true,"allowTyposOnNumericTokens":true,"alternativesAsExact":["singleWordSynonym"],"attributeCriteriaComputedByMinProximity":true,"attributeForDistinct":"test","attributesForFaceting":["algolia"],"attributesToHighlight":["algolia"],"attributesToRetrieve":["algolia"],"attributesToSnippet":["algolia"],"attributesToTransliterate":["algolia"],"camelCaseAttributes":["algolia"],"customNormalization":{"algolia":{"aloglia":"aglolia"}},"customRanking":["algolia"],"decompoundQuery":false,"decompoundedAttributes":{"algolia":"aloglia"},"disableExactOnAttributes":["algolia"],"disablePrefixOnAttributes":["algolia"],"disableTypoToleranceOnAttributes":["algolia"],"disableTypoToleranceOnWords":["algolia"],"distinct":3,"enablePersonalization":true,"enableReRanking":false,"enableRules":true,"exactOnSingleWordQuery":"attribute","highlightPreTag":"","highlightPostTag":"","hitsPerPage":10,"ignorePlurals":false,"indexLanguages":["algolia"],"keepDiacriticsOnCharacters":"abc","maxFacetHits":20,"maxValuesPerFacet":30,"minProximity":6,"minWordSizefor1Typo":5,"minWordSizefor2Typos":11,"mode":"neuralSearch","numericAttributesForFiltering":["algolia"],"optionalWords":["myspace"],"paginationLimitedTo":0,"queryLanguages":["algolia"],"queryType":"prefixLast","ranking":["geo"],"reRankingApplyFilter":"mySearch:filters","relevancyStrictness":10,"removeStopWords":false,"removeWordsIfNoResults":"lastWords","renderingContent":{"facetOrdering":{"facets":{"order":["a","b"]},"values":{"a":{"order":["b"],"sortRemainingBy":"count"}}}},"replaceSynonymsInHighlight":true,"replicas":[""],"responseFields":["algolia"],"restrictHighlightAndSnippetArrays":true,"searchableAttributes":["foo"],"semanticSearch":{"eventSources":["foo"]},"separatorsToIndex":"bar","snippetEllipsisText":"---","sortFacetValuesBy":"date","typoTolerance":false,"unretrievableAttributes":["foo"],"userData":{"user":"data"}}`) }) } @@ -2259,10 +2261,10 @@ func TestSearch_UpdateApiKey(t *testing.T) { expectedPath, err := url.QueryUnescape("/1/keys/myApiKey") require.NoError(t, err) - require.Equal(t, expectedPath, echo.path) - require.Equal(t, "PUT", echo.method) + require.Equal(t, expectedPath, echo.Path) + require.Equal(t, "PUT", echo.Method) ja := jsonassert.New(t) - ja.Assertf(*echo.body, `{"acl":["search","addObject"],"validity":300,"maxQueriesPerIPPerHour":100,"maxHitsPerQuery":20}`) + ja.Assertf(*echo.Body, `{"acl":["search","addObject"],"validity":300,"maxQueriesPerIPPerHour":100,"maxHitsPerQuery":20}`) }) }