Skip to content

Commit

Permalink
fix(specs): body is not required in multiple batch request (#3454) (g…
Browse files Browse the repository at this point in the history
…enerated) [skip ci]

Co-authored-by: Kai Welke <kai.welke@algolia.com>
  • Loading branch information
algolia-bot and kai687 committed Aug 3, 2024
1 parent 7af1e75 commit 28182ef
Show file tree
Hide file tree
Showing 37 changed files with 125 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ public MultipleBatchRequest() { }
/// Initializes a new instance of the MultipleBatchRequest class.
/// </summary>
/// <param name="action">action (required).</param>
/// <param name="body">Operation arguments (varies with specified &#x60;action&#x60;). (required).</param>
/// <param name="indexName">Index name (case-sensitive). (required).</param>
public MultipleBatchRequest(Action? action, object body, string indexName)
public MultipleBatchRequest(Action? action, string indexName)
{
Action = action;
Body = body ?? throw new ArgumentNullException(nameof(body));
IndexName = indexName ?? throw new ArgumentNullException(nameof(indexName));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class MultipleBatchRequest {
/// Returns a new [MultipleBatchRequest] instance.
const MultipleBatchRequest({
required this.action,
required this.body,
this.body,
required this.indexName,
});

Expand All @@ -20,7 +20,7 @@ final class MultipleBatchRequest {

/// Operation arguments (varies with specified `action`).
@JsonKey(name: r'body')
final Object body;
final Object? body;

/// Index name (case-sensitive).
@JsonKey(name: r'indexName')
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public MultipleBatchRequest setBody(Object body) {
}

/** Operation arguments (varies with specified `action`). */
@javax.annotation.Nonnull
@javax.annotation.Nullable
public Object getBody() {
return body;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type MultipleBatchRequest = {
/**
* Operation arguments (varies with specified `action`).
*/
body: Record<string, any>;
body?: Record<string, any>;

/**
* Index name (case-sensitive).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import kotlinx.serialization.json.*
* MultipleBatchRequest
*
* @param action
* @param body Operation arguments (varies with specified `action`).
* @param indexName Index name (case-sensitive).
* @param body Operation arguments (varies with specified `action`).
*/
@Serializable
public data class MultipleBatchRequest(

@SerialName(value = "action") val action: Action,

/** Operation arguments (varies with specified `action`). */
@SerialName(value = "body") val body: JsonObject,

/** Index name (case-sensitive). */
@SerialName(value = "indexName") val indexName: String,

/** Operation arguments (varies with specified `action`). */
@SerialName(value = "body") val body: JsonObject? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ public function listInvalidProperties()
if (!isset($this->container['action']) || null === $this->container['action']) {
$invalidProperties[] = "'action' can't be null";
}
if (!isset($this->container['body']) || null === $this->container['body']) {
$invalidProperties[] = "'body' can't be null";
}
if (!isset($this->container['indexName']) || null === $this->container['indexName']) {
$invalidProperties[] = "'indexName' can't be null";
}
Expand Down Expand Up @@ -205,7 +202,7 @@ public function setAction($action)
/**
* Gets body.
*
* @return object
* @return null|object
*/
public function getBody()
{
Expand All @@ -215,7 +212,7 @@ public function getBody()
/**
* Sets body.
*
* @param object $body operation arguments (varies with specified `action`)
* @param null|object $body operation arguments (varies with specified `action`)
*
* @return self
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from __future__ import annotations

from json import loads
from typing import Any, Dict, Self
from typing import Any, Dict, Optional, Self

from pydantic import BaseModel, ConfigDict, Field, StrictStr

Expand All @@ -20,8 +20,9 @@ class MultipleBatchRequest(BaseModel):
"""

action: Action
body: Dict[str, Any] = Field(
description="Operation arguments (varies with specified `action`)."
body: Optional[Dict[str, Any]] = Field(
default=None,
description="Operation arguments (varies with specified `action`).",
)
index_name: StrictStr = Field(
description="Index name (case-sensitive).", alias="indexName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ def initialize(attributes = {})

if attributes.key?(:body)
self.body = attributes[:body]
else
self.body = nil
end

if attributes.key?(:index_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ import algoliasearch.search.Action._
*/
case class MultipleBatchRequest(
action: Action,
body: Any,
body: Option[Any] = scala.None,
indexName: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import Foundation
public struct MultipleBatchRequest: Codable, JSONEncodable {
public var action: SearchAction
/// Operation arguments (varies with specified `action`).
public var body: AnyCodable
public var body: AnyCodable?
/// Index name (case-sensitive).
public var indexName: String

public init(action: SearchAction, body: AnyCodable, indexName: String) {
public init(action: SearchAction, body: AnyCodable? = nil, indexName: String) {
self.action = action
self.body = body
self.indexName = indexName
Expand All @@ -30,7 +30,7 @@ public struct MultipleBatchRequest: Codable, JSONEncodable {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.action, forKey: .action)
try container.encode(self.body, forKey: .body)
try container.encodeIfPresent(self.body, forKey: .body)
try container.encode(self.indexName, forKey: .indexName)
}
}
Expand All @@ -46,7 +46,7 @@ extension MultipleBatchRequest: Equatable {
extension MultipleBatchRequest: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(self.action.hashValue)
hasher.combine(self.body.hashValue)
hasher.combine(self.body?.hashValue)
hasher.combine(self.indexName.hashValue)
}
}
2 changes: 1 addition & 1 deletion snippets/guides/search-snippets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@
"default": "val response = client.listUserIds(\n)\n\n// Use the response\nval value = Await.result(response, Duration(100, \"sec\"))"
},
"multipleBatch": {
"default": "val response = client.multipleBatch(\n batchParams = BatchParams(\n requests = Seq(\n MultipleBatchRequest(\n action = Action.withName(\"addObject\"),\n body = JObject(List(JField(\"key\", JString(\"value\")))),\n indexName = \"theIndexName\"\n )\n )\n )\n)\n\n// Use the response\nval value = Await.result(response, Duration(100, \"sec\"))"
"default": "val response = client.multipleBatch(\n batchParams = BatchParams(\n requests = Seq(\n MultipleBatchRequest(\n action = Action.withName(\"addObject\"),\n body = Some(JObject(List(JField(\"key\", JString(\"value\"))))),\n indexName = \"theIndexName\"\n )\n )\n )\n)\n\n// Use the response\nval value = Await.result(response, Duration(100, \"sec\"))"
},
"operationIndex": {
"scopes": "val response = client.operationIndex(\n indexName = \"<SOURCE_INDEX_NAME>\",\n operationIndexParams = OperationIndexParams(\n operation = OperationType.withName(\"move\"),\n destination = \"<DESTINATION_INDEX_NAME>\",\n scope = Some(Seq(ScopeType.withName(\"rules\"), ScopeType.withName(\"settings\")))\n )\n)\n\n// Use the response\nval value = Await.result(response, Duration(100, \"sec\"))",
Expand Down
2 changes: 1 addition & 1 deletion snippets/scala/src/main/scala/Search.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ class SnippetSearchClient {
requests = Seq(
MultipleBatchRequest(
action = Action.withName("addObject"),
body = JObject(List(JField("key", JString("value")))),
body = Some(JObject(List(JField("key", JString("value"))))),
indexName = "theIndexName"
)
)
Expand Down
3 changes: 1 addition & 2 deletions specs/bundled/search.doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4413,7 +4413,6 @@ paths:
$ref: '#/components/schemas/indexName'
required:
- action
- body
- indexName
required:
- requests
Expand Down Expand Up @@ -4691,7 +4690,7 @@ paths:
requests = Seq(
MultipleBatchRequest(
action = Action.withName("addObject"),
body = JObject(List(JField("key", JString("value")))),
body = Some(JObject(List(JField("key", JString("value"))))),
indexName = "theIndexName"
)
)
Expand Down
1 change: 0 additions & 1 deletion specs/bundled/search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,6 @@ paths:
$ref: '#/components/schemas/indexName'
required:
- action
- body
- indexName
required:
- requests
Expand Down
4 changes: 2 additions & 2 deletions tests/output/csharp/src/generated/e2e/Insights.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task PushEventsTest1()
Index = "products",
UserToken = "user-123456",
AuthenticatedUserToken = "user-123456",
Timestamp = 1722384000000L,
Timestamp = 1722643200000L,
ObjectIDs = new List<string> { "9780545139700", "9780439784542" },
QueryID = "43b15df305339e827f0ac0bdc5ebcaa7",
}
Expand All @@ -76,7 +76,7 @@ public async Task PushEventsTest1()
Index = "products",
UserToken = "user-123456",
AuthenticatedUserToken = "user-123456",
Timestamp = 1722384000000L,
Timestamp = 1722643200000L,
ObjectIDs = new List<string> { "9780545139700", "9780439784542" },
}
)
Expand Down
6 changes: 3 additions & 3 deletions tests/output/csharp/src/generated/requests/Insights.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ await client.PushEventsAsync(
Index = "products",
UserToken = "user-123456",
AuthenticatedUserToken = "user-123456",
Timestamp = 1722384000000L,
Timestamp = 1722643200000L,
ObjectIDs = new List<string> { "9780545139700", "9780439784542" },
QueryID = "43b15df305339e827f0ac0bdc5ebcaa7",
}
Expand All @@ -593,7 +593,7 @@ await client.PushEventsAsync(
Index = "products",
UserToken = "user-123456",
AuthenticatedUserToken = "user-123456",
Timestamp = 1722384000000L,
Timestamp = 1722643200000L,
ObjectIDs = new List<string> { "9780545139700", "9780439784542" },
}
)
Expand All @@ -605,7 +605,7 @@ await client.PushEventsAsync(
Assert.Equal("/1/events", req.Path);
Assert.Equal("POST", req.Method.ToString());
JsonAssert.EqualOverrideDefault(
"{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722384000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722384000000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}",
"{\"events\":[{\"eventType\":\"conversion\",\"eventName\":\"Product Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722643200000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"},{\"eventType\":\"view\",\"eventName\":\"Product Detail Page Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"authenticatedUserToken\":\"user-123456\",\"timestamp\":1722643200000,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]}]}",
req.Body,
new JsonDiffConfig(false)
);
Expand Down
Loading

0 comments on commit 28182ef

Please sign in to comment.