diff --git a/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift b/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift index 19c158320c..8f00f6d840 100644 --- a/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift +++ b/clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift @@ -426,7 +426,7 @@ public extension SearchClient { func chunkedBatch( indexName: String, objects: [some Encodable], - action: Action = .addObject, + action: SearchAction = .addObject, waitForTasks: Bool = false, batchSize: Int = 1000, requestOptions: RequestOptions? = nil @@ -439,7 +439,7 @@ public extension SearchClient { for batch in batches { let batchResponse = try await self.batch( indexName: indexName, - batchWriteParams: BatchWriteParams( + batchWriteParams: SearchBatchWriteParams( requests: batch.map { .init(action: action, body: AnyCodable($0)) } diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java index 78a9f25092..9570a139a0 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java @@ -32,6 +32,7 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen { private static final List reservedModelNames = List.of( + "action", "advancedsyntaxfeatures", "alternativesasexact", "anchoring", @@ -44,6 +45,8 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen { "basesearchparams", "basesearchparamswithoutquery", "basesearchresponse", + "batchrequest", + "batchwriteparams", "condition", "configuration", "consequence", diff --git a/specs/common/schemas/Batch.yml b/specs/common/schemas/Batch.yml new file mode 100644 index 0000000000..2f04d63fb3 --- /dev/null +++ b/specs/common/schemas/Batch.yml @@ -0,0 +1,54 @@ +batchWriteParams: + title: batchWriteParams + description: Batch parameters. + type: object + additionalProperties: false + properties: + requests: + type: array + items: + title: batchRequest + type: object + additionalProperties: false + properties: + action: + $ref: '#/action' + body: + type: object + description: Operation arguments (varies with specified `action`). + example: + name: Betty Jane McCamey + company: Vita Foods Inc. + email: betty@mccamey.com + required: + - action + - body + required: + - requests + example: + batch: + summary: Batch indexing request + value: + requests: + - action: addObject + body: + name: Betty Jane McCamey + company: Vita Foods Inc. + email: betty@mccamey.com + - action: addObject + body: + name: Gayla geimer + company: Ortman McCain Co. + email: gayla@geimer.com + +action: + type: string + enum: + - addObject + - updateObject + - partialUpdateObject + - partialUpdateObjectNoCreate + - deleteObject + - delete + - clear + description: Type of indexing operation. diff --git a/specs/ingestion/paths/tasks/v2/pushTask.yml b/specs/ingestion/paths/tasks/v2/pushTask.yml new file mode 100644 index 0000000000..b1dc799f84 --- /dev/null +++ b/specs/ingestion/paths/tasks/v2/pushTask.yml @@ -0,0 +1,28 @@ +post: + tags: + - tasks + summary: Push a `batch` request payload through the Pipeline + description: Push a `batch` request payload through the Pipeline. You can check the status of task pushes with the observability endpoints. + operationId: pushTask + x-acl: + - addObject + - deleteIndex + - editSettings + parameters: + - $ref: '../../../common/parameters.yml#/pathTaskID' + requestBody: + description: Request body of a Search API `batch` request that will be pushed in the Connectors pipeline. + content: + application/json: + schema: + $ref: '../../../../common/schemas/Batch.yml#/batchWriteParams' + required: true + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '../../../common/schemas/run.yml#/RunResponse' + '400': + $ref: '../../../../common/responses/BadRequest.yml' diff --git a/specs/ingestion/spec.yml b/specs/ingestion/spec.yml index 6de5a2384d..56b12b90e0 100644 --- a/specs/ingestion/spec.yml +++ b/specs/ingestion/spec.yml @@ -159,6 +159,8 @@ paths: $ref: 'paths/tasks/v2/taskID.yml' /2/tasks/{taskID}/run: $ref: 'paths/tasks/v2/runTask.yml' + /2/tasks/{taskID}/push: + $ref: 'paths/tasks/v2/pushTask.yml' /2/tasks/{taskID}/enable: $ref: 'paths/tasks/v2/enableTask.yml' /2/tasks/{taskID}/disable: diff --git a/specs/search/helpers/chunkedBatch.yml b/specs/search/helpers/chunkedBatch.yml index dbe3b85516..e0139e4a4f 100644 --- a/specs/search/helpers/chunkedBatch.yml +++ b/specs/search/helpers/chunkedBatch.yml @@ -27,7 +27,7 @@ method: description: The `batch` `action` to perform on the given array of `objects`, defaults to `addObject`. required: false schema: - $ref: '../paths/objects/common/schemas.yml#/action' + $ref: '../../common/schemas/Batch.yml#/action' - in: query name: waitForTasks description: Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable. diff --git a/specs/search/paths/objects/batch.yml b/specs/search/paths/objects/batch.yml index a27a65f329..adc6cbbdcc 100644 --- a/specs/search/paths/objects/batch.yml +++ b/specs/search/paths/objects/batch.yml @@ -12,53 +12,13 @@ post: - Actions are equivalent to the individual API requests of the same name. parameters: - $ref: '../../../common/parameters.yml#/IndexName' + x-codegen-request-body-name: batchWriteParams requestBody: - required: true content: application/json: schema: - title: batchWriteParams - description: Batch parameters. - type: object - additionalProperties: false - properties: - requests: - type: array - items: - title: batchRequest - type: object - additionalProperties: false - properties: - action: - $ref: 'common/schemas.yml#/action' - body: - type: object - description: Operation arguments (varies with specified `action`). - example: - name: Betty Jane McCamey - company: Vita Foods Inc. - email: betty@mccamey.com - - required: - - action - - body - required: - - requests - examples: - batch: - summary: Batch indexing request - value: - requests: - - action: addObject - body: - name: Betty Jane McCamey - company: Vita Foods Inc. - email: betty@mccamey.com - - action: addObject - body: - name: Gayla geimer - company: Ortman McCain Co. - email: gayla@geimer.com + $ref: '../../../common/schemas/Batch.yml#/batchWriteParams' + required: true responses: '200': description: OK diff --git a/specs/search/paths/objects/common/schemas.yml b/specs/search/paths/objects/common/schemas.yml index 7acf46499f..63c849da6a 100644 --- a/specs/search/paths/objects/common/schemas.yml +++ b/specs/search/paths/objects/common/schemas.yml @@ -1,15 +1,3 @@ -action: - type: string - enum: - - addObject - - updateObject - - partialUpdateObject - - partialUpdateObjectNoCreate - - deleteObject - - delete - - clear - description: Type of indexing operation. - builtInOperationType: type: string enum: diff --git a/specs/search/paths/objects/multipleBatch.yml b/specs/search/paths/objects/multipleBatch.yml index e7d695929b..73c240ca78 100644 --- a/specs/search/paths/objects/multipleBatch.yml +++ b/specs/search/paths/objects/multipleBatch.yml @@ -26,7 +26,7 @@ post: additionalProperties: false properties: action: - $ref: 'common/schemas.yml#/action' + $ref: '../../../common/schemas/Batch.yml#/action' body: type: object description: Operation arguments (varies with specified `action`). diff --git a/templates/csharp/snippets/method.mustache b/templates/csharp/snippets/method.mustache index deb8be086a..e4fbf39bce 100644 --- a/templates/csharp/snippets/method.mustache +++ b/templates/csharp/snippets/method.mustache @@ -4,7 +4,12 @@ using Algolia.Search.Http; using Algolia.Search.Clients; // IMPORT< using Algolia.Search.Models.{{clientPrefix}}; +{{#isSearchClient}} using Action = Algolia.Search.Models.Search.Action; +{{/isSearchClient}} +{{^isSearchClient}} +using Action = Algolia.Search.Models.Ingestion.Action; +{{/isSearchClient}} public class Snippet{{client}} { diff --git a/templates/csharp/tests/e2e/e2e.mustache b/templates/csharp/tests/e2e/e2e.mustache index 7ad0e92400..61fcb2a2b9 100644 --- a/templates/csharp/tests/e2e/e2e.mustache +++ b/templates/csharp/tests/e2e/e2e.mustache @@ -8,7 +8,12 @@ using Xunit; using System.Text.Json; using Quibble.Xunit; using dotenv.net; +{{#isSearchClient}} using Action = Algolia.Search.Models.Search.Action; +{{/isSearchClient}} +{{^isSearchClient}} +using Action = Algolia.Search.Models.Ingestion.Action; +{{/isSearchClient}} namespace Algolia.Search.e2e; diff --git a/templates/csharp/tests/requests/requests.mustache b/templates/csharp/tests/requests/requests.mustache index f95002673b..835ca835c6 100644 --- a/templates/csharp/tests/requests/requests.mustache +++ b/templates/csharp/tests/requests/requests.mustache @@ -8,7 +8,12 @@ using Xunit; using System.Text.Json; using Quibble.Xunit; using dotenv.net; +{{#isSearchClient}} using Action = Algolia.Search.Models.Search.Action; +{{/isSearchClient}} +{{^isSearchClient}} +using Action = Algolia.Search.Models.Ingestion.Action; +{{/isSearchClient}} namespace Algolia.Search.requests; diff --git a/tests/CTS/requests/ingestion/pushTask.json b/tests/CTS/requests/ingestion/pushTask.json new file mode 100644 index 0000000000..49d22a2b1e --- /dev/null +++ b/tests/CTS/requests/ingestion/pushTask.json @@ -0,0 +1,47 @@ +[ + { + "parameters": { + "taskID": "6c02aeb1-775e-418e-870b-1faccd4b2c0f", + "batchWriteParams": { + "requests": [ + { + "action": "addObject", + "body": { + "key": "bar", + "foo": "1" + } + }, + { + "action": "addObject", + "body": { + "key": "baz", + "foo": "2" + } + } + ] + } + }, + "request": { + "path": "/2/tasks/6c02aeb1-775e-418e-870b-1faccd4b2c0f/push", + "method": "POST", + "body": { + "requests": [ + { + "action": "addObject", + "body": { + "key": "bar", + "foo": "1" + } + }, + { + "action": "addObject", + "body": { + "key": "baz", + "foo": "2" + } + } + ] + } + } + } +]