Skip to content

Commit 3aad06f

Browse files
committed
rebase with main
1 parent cde5d91 commit 3aad06f

File tree

11 files changed

+117
-157
lines changed

11 files changed

+117
-157
lines changed

clients/algoliasearch-client-go/.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ linters:
5050
presets:
5151
- comments
5252
- std-error-handling
53+
rules:
54+
- path: api_search.go
55+
linters:
56+
- wrapcheck
5357
formatters:
5458
enable:
5559
- gofmt

generators/src/main/java/com/algolia/codegen/AlgoliaGoGenerator.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public void processOpts() {
4949
typeMapping.put("AnyType", "any");
5050

5151
modelNameMapping.put("range", "modelRange");
52+
typeMapping.put("integer", "int");
5253

5354
apiTestTemplateFiles.clear();
5455
modelTestTemplateFiles.clear();
@@ -85,7 +86,10 @@ public void processOpenAPI(OpenAPI openAPI) {
8586
Timeouts.enrichBundle(openAPI, additionalProperties);
8687
additionalProperties.put(
8788
"appDescription",
88-
Arrays.stream(openAPI.getInfo().getDescription().split("\n")).map(line -> "// " + line).collect(Collectors.joining("\n")).trim()
89+
Arrays.stream(openAPI.getInfo().getDescription().split("\n"))
90+
.map(line -> "// " + line)
91+
.collect(Collectors.joining("\n"))
92+
.trim()
8993
);
9094
}
9195

@@ -127,7 +131,8 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
127131
String modelName = entry.getKey();
128132
CodegenModel model = entry.getValue().getModels().get(0).getModel();
129133

130-
// for some reason the property additionalPropertiesIsAnyType is not propagated to the
134+
// for some reason the property additionalPropertiesIsAnyType is not propagated
135+
// to the
131136
// property
132137
for (CodegenProperty prop : model.getVars()) {
133138
ModelsMap propertyModel = models.get(prop.datatypeWithEnum);
@@ -154,7 +159,12 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
154159
for (CodegenOperation ope : operations.getOperations().getOperation()) {
155160
// clean up the description
156161
String[] lines = ope.unescapedNotes.split("\n");
157-
ope.notes = (lines[0] + "\n" + Arrays.stream(lines).skip(1).map(line -> "// " + line).collect(Collectors.joining("\n"))).trim();
162+
ope.notes = (lines[0] +
163+
"\n" +
164+
Arrays.stream(lines)
165+
.skip(1)
166+
.map(line -> "// " + line)
167+
.collect(Collectors.joining("\n"))).trim();
158168

159169
// enrich the params
160170
for (CodegenParameter param : ope.optionalParams) {
@@ -171,15 +181,13 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
171181
CodegenParameter param = ope.optionalParams.get(0);
172182

173183
// move it to required, it's easier to handle im mustache
174-
ope.hasOptionalParams = false;
175184
ope.optionalParams.clear();
176185

177-
ope.hasRequiredParams = true;
178186
ope.requiredParams.add(param);
179187
}
180188
}
181189

182-
ModelPruner.removeOrphans(this, operations, models);
190+
ModelPruner.removeOrphanModelFiles(this, operations, models);
183191
Helpers.removeHelpers(operations);
184192
GenericPropagator.propagateGenericsToOperations(operations, models);
185193
return operations;
@@ -218,10 +226,8 @@ private void flattenBody(CodegenOperation ope) {
218226

219227
if (prop.required) {
220228
ope.requiredParams.add(param);
221-
ope.hasRequiredParams = true;
222229
} else {
223230
ope.optionalParams.add(param);
224-
ope.hasOptionalParams = true;
225231
}
226232
ope.allParams.add(param);
227233
}

generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ private String getObjectNameForLanguage(String objectName) {
578578
case "Double":
579579
return "float64";
580580
case "Integer":
581-
return "int32";
581+
return "int";
582582
case "Long":
583583
return "int64";
584584
case "Boolean":
@@ -787,7 +787,11 @@ private boolean couldMatchEnum(Object value, CodegenProperty model) {
787787

788788
private void sortParameters(IJsonSchemaValidationProperties spec, List<Map<String, Object>> parameters) {
789789
// Store ordered params from the spec
790-
var orderedParams = spec.getVars().stream().map(v -> v.baseName).toList();
790+
var orderedParams = spec
791+
.getVars()
792+
.stream()
793+
.map(v -> v.baseName)
794+
.toList();
791795

792796
// Create a map to store the indices of each string in orderedParams
793797
Map<String, Integer> indexMap = IntStream.range(0, orderedParams.size()).boxed().collect(Collectors.toMap(orderedParams::get, i -> i));

generators/src/main/java/com/algolia/codegen/cts/tests/TestsGenerator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ public static void setOptionalParameters(
151151

152152
if (AlgoliaGoGenerator.canFlattenBody(ope) && ope.bodyParam != null) {
153153
List<CodegenProperty> vars = ope.bodyParam.getVars();
154-
bodyPropsOptional = (int) vars.stream().filter(p -> !p.required).count();
154+
bodyPropsOptional = (int) vars
155+
.stream()
156+
.filter(p -> !p.required)
157+
.count();
155158
isBodyTooBig = vars.isEmpty();
156159

157160
Map<String, Object> paramBody = parameters;

templates/go/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ func (c *APIClient) {{nickname}}(ctx context.Context, {{#requiredParams}}{{param
365365
if res == nil {
366366
return {{#returnType}}returnValue, {{/returnType}}reportError("res is nil")
367367
}
368+
defer res.Body.Close()
368369

369370
if res.StatusCode >= 300 {
370371
return {{#returnType}}returnValue, {{/returnType}}c.decodeError(res, resBody)

templates/go/client.mustache

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -312,24 +312,6 @@ func reportError(format string, a ...any) error {
312312
return fmt.Errorf(format, a...)
313313
}
314314

315-
// A wrapper for strict JSON decoding
316-
func newStrictDecoder(data []byte) *json.Decoder {
317-
dec := json.NewDecoder(bytes.NewBuffer(data))
318-
dec.DisallowUnknownFields()
319-
return dec
320-
}
321-
322-
// A wrapper for validating a struct, returns nil if value is not a struct
323-
func validateStruct(v any) error {
324-
err := validator.New().Struct(v)
325-
validationErrors, ok := err.(validator.ValidationErrors)
326-
if ok && len(validationErrors) > 0 {
327-
return validationErrors
328-
}
329-
330-
return nil
331-
}
332-
333315
// Set request body from an any
334316
func setBody(body any, c compression.Compression) (*bytes.Buffer, error) {
335317
if body == nil {

templates/go/ingestion_helpers.mustache

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
/*
2-
ChunkedPush Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `push` requests by leveraging the Transformation pipeline setup in the Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/).
3-
4-
@param indexName string - the index name to save objects into.
5-
@param objects []map[string]any - List of objects to save.
6-
@param action Action - The action to perform on the objects.
7-
@param referenceIndexName *string - This is required when targeting an index that does not have a push connector setup (e.g. a tmp index), but you wish to attach another index's transformation to it (e.g. the source index name).
8-
@param opts ...ChunkedBatchOption - Optional parameters for the request.
9-
@return []WatchResponse - List of push responses.
10-
@return error - Error if any.
11-
*/
12-
func (c *APIClient) ChunkedPush(indexName string, objects []map[string]any, action Action, referenceIndexName *string, opts ...ChunkedBatchOption) ([]WatchResponse, error) {
1+
// ChunkedPush Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `push` requests by leveraging the Transformation pipeline setup in the Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/).
2+
//
3+
// Parameters:
4+
// - transformationID - Unique identifier of a transformation.
5+
// - indexName string - the index name to save objects into.
6+
// - objects []map[string]any - List of objects to save.
7+
// - action Action - The action to perform on the objects.
8+
// - referenceIndexName *string - This is required when targeting an index that does not have a push connector setup (e.g. a tmp index), but you wish to attach another index's transformation to it (e.g. the source index name).
9+
// - opts - Optional parameters for the API call (e.g. WithHeaderParam, WithReadTimeout...)
10+
func (c *APIClient) ChunkedPush(ctx context.Context, indexName string, objects []map[string]any, action Action, referenceIndexName *string, opts ...ChunkedBatchOption) ([]WatchResponse, error) {
1311
conf := config{
1412
headerParams: map[string]string{},
1513
waitForTasks: false,
@@ -45,18 +43,12 @@ func (c *APIClient) ChunkedPush(indexName string, objects []map[string]any, acti
4543
return nil, reportError("unable to unmarshal the given `objects` to an `[]PushTaskRecords` payload: %w", err)
4644
}
4745

48-
request := c.NewApiPushRequest(
49-
indexName,
50-
NewEmptyPushTaskPayload().
51-
SetAction(action).
52-
SetRecords(pushRecords),
53-
)
54-
55-
if referenceIndexName != nil {
56-
request = request.WithReferenceIndexName(*referenceIndexName)
57-
}
46+
opts := NewPushOptions()
47+
if referenceIndexName != nil {
48+
opts = opts.WithReferenceIndexName(*referenceIndexName)
49+
}
5850

59-
resp, err := c.Push(request)
51+
resp, err := c.Push(ctx, indexName, action, pushRecords, opts)
6052
if err != nil {
6153
return nil, err //nolint: wrapcheck
6254
}
@@ -65,7 +57,6 @@ func (c *APIClient) ChunkedPush(indexName string, objects []map[string]any, acti
6557
records = make([]map[string]any, 0, len(objects)%conf.batchSize)
6658
}
6759

68-
6960
if conf.waitForTasks && len(responses) > 0 && (len(responses)%waitBatchSize == 0 || i == len(objects)-1) {
7061
var waitableResponses []WatchResponse
7162
@@ -82,7 +73,7 @@ func (c *APIClient) ChunkedPush(indexName string, objects []map[string]any, acti
8273
return nil, reportError("received unexpected response from the push endpoint, eventID must not be undefined")
8374
}
8475

85-
return c.GetEvent(c.NewApiGetEventRequest(resp.RunID, *resp.EventID))
76+
return c.GetEvent(ctx, resp.RunID, *resp.EventID)
8677
},
8778
func(response *Event, err error) (bool, error) {
8879
var apiErr *APIError
@@ -104,4 +95,4 @@ func (c *APIClient) ChunkedPush(indexName string, objects []map[string]any, acti
10495
}
10596

10697
return responses, nil
107-
}
98+
}

0 commit comments

Comments
 (0)