Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(specs): add v2 endpoints for ingestion #3416

Merged
merged 15 commits into from
Jul 25, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
public class AlgoliaSwiftGenerator extends Swift5ClientCodegen {

private static final List<String> reservedModelNames = List.of(
"action",
"advancedsyntaxfeatures",
"alternativesasexact",
"anchoring",
Expand All @@ -44,6 +45,8 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen {
"basesearchparams",
"basesearchparamswithoutquery",
"basesearchresponse",
"batchrequest",
"batchwriteparams",
"condition",
"configuration",
"consequence",
Expand Down
54 changes: 54 additions & 0 deletions specs/common/schemas/Batch.yml
Original file line number Diff line number Diff line change
@@ -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.
28 changes: 28 additions & 0 deletions specs/ingestion/paths/tasks/v2/pushTask.yml
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 2 additions & 0 deletions specs/ingestion/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion specs/search/helpers/chunkedBatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
46 changes: 3 additions & 43 deletions specs/search/paths/objects/batch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no I thought so for the swift issue but it's a leftover indeed

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
Expand Down
12 changes: 0 additions & 12 deletions specs/search/paths/objects/common/schemas.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
action:
type: string
enum:
- addObject
- updateObject
- partialUpdateObject
- partialUpdateObjectNoCreate
- deleteObject
- delete
- clear
description: Type of indexing operation.

builtInOperationType:
type: string
enum:
Expand Down
2 changes: 1 addition & 1 deletion specs/search/paths/objects/multipleBatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
5 changes: 5 additions & 0 deletions templates/csharp/snippets/method.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
{
Expand Down
5 changes: 5 additions & 0 deletions templates/csharp/tests/e2e/e2e.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions templates/csharp/tests/requests/requests.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
47 changes: 47 additions & 0 deletions tests/CTS/requests/ingestion/pushTask.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
}
}
]
Loading