Skip to content

Commit 8987388

Browse files
feat(specs): introduce multifeed composition behavior for beta release (generated)
algolia/api-clients-automation#5828 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Gavin Wade <[email protected]>
1 parent 0078ca9 commit 8987388

File tree

3 files changed

+165
-19
lines changed

3 files changed

+165
-19
lines changed

algoliasearch/src/main/java/com/algolia/internal/HttpRequester.java

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ private <T> T execute(@Nonnull HttpRequest httpRequest, RequestOptions requestOp
8181

8282
Request request = requestBuilder.build();
8383

84-
// Get or adjust the HTTP client according to request options.
85-
OkHttpClient client = getOkHttpClient(requestOptions);
84+
// Get or adjust the HTTP client according to request.
85+
OkHttpClient client = getOkHttpClient(httpRequest, requestOptions);
8686

8787
// Execute the request.
8888
Call call = client.newCall(request);
@@ -165,22 +165,52 @@ private Headers createHeaders(@Nonnull HttpRequest request, RequestOptions reque
165165

166166
/** Returns a suitable OkHttpClient instance based on the provided request options. */
167167
@Nonnull
168-
private OkHttpClient getOkHttpClient(RequestOptions requestOptions) {
169-
// Return the default client if no request options are provided.
170-
if (requestOptions == null) return httpClient;
171-
172-
// Create a new client builder from the default client and adjust timeouts if provided.
168+
private OkHttpClient getOkHttpClient(HttpRequest httpRequest, RequestOptions requestOptions) {
173169
OkHttpClient.Builder builder = httpClient.newBuilder();
174-
if (requestOptions.getReadTimeout() != null) {
175-
builder.readTimeout(requestOptions.getReadTimeout());
176-
}
177-
if (requestOptions.getWriteTimeout() != null) {
178-
builder.writeTimeout(requestOptions.getWriteTimeout());
170+
// Determine if this is a read operation: either explicitly marked as read, or using GET method
171+
boolean isRead = httpRequest.isRead() || "GET".equalsIgnoreCase(httpRequest.getMethod());
172+
boolean changed = false;
173+
174+
// If this is a write operation, set readTimeout to the default writeTimeout value
175+
if (!isRead) {
176+
builder.readTimeout(Duration.ofMillis(httpClient.writeTimeoutMillis()));
177+
changed = true;
179178
}
180-
if (requestOptions.getConnectTimeout() != null) {
181-
builder.connectTimeout(requestOptions.getConnectTimeout());
179+
180+
if (isRead && requestOptions != null) {
181+
// For read operations, apply connectTimeout if provided
182+
if (requestOptions.getConnectTimeout() != null) {
183+
builder.connectTimeout(requestOptions.getConnectTimeout());
184+
changed = true;
185+
}
186+
// For read operations, use the explicit readTimeout if provided
187+
if (requestOptions.getReadTimeout() != null) {
188+
builder.readTimeout(requestOptions.getReadTimeout());
189+
changed = true;
190+
}
191+
// For read operations, set writeTimeout if provided
192+
if (requestOptions.getWriteTimeout() != null) {
193+
builder.writeTimeout(requestOptions.getWriteTimeout());
194+
changed = true;
195+
}
196+
} else if (!isRead && requestOptions != null) {
197+
// For write operations, apply connectTimeout if provided
198+
if (requestOptions.getConnectTimeout() != null) {
199+
builder.connectTimeout(requestOptions.getConnectTimeout());
200+
changed = true;
201+
}
202+
// For write operations, use the explicit writeTimeout for both readTimeout and writeTimeout
203+
// if provided
204+
if (requestOptions.getWriteTimeout() != null) {
205+
builder.readTimeout(requestOptions.getWriteTimeout());
206+
builder.writeTimeout(requestOptions.getWriteTimeout());
207+
changed = true;
208+
}
182209
}
183-
return builder.build();
210+
211+
// Return a new OkHttpClient instance if any timeout was changed, otherwise reuse the default
212+
// client
213+
return changed ? builder.build() : httpClient;
184214
}
185215

186216
@Override

algoliasearch/src/main/java/com/algolia/model/composition/CompositionBehavior.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,37 @@
77
import com.fasterxml.jackson.databind.annotation.*;
88
import java.util.Objects;
99

10-
/** CompositionBehavior */
10+
/** An object containing either an `injection` or `multifeed` behavior schema, but not both. */
1111
public class CompositionBehavior {
1212

1313
@JsonProperty("injection")
1414
private Injection injection;
1515

16+
@JsonProperty("multifeed")
17+
private Multifeed multifeed;
18+
1619
public CompositionBehavior setInjection(Injection injection) {
1720
this.injection = injection;
1821
return this;
1922
}
2023

2124
/** Get injection */
22-
@javax.annotation.Nonnull
25+
@javax.annotation.Nullable
2326
public Injection getInjection() {
2427
return injection;
2528
}
2629

30+
public CompositionBehavior setMultifeed(Multifeed multifeed) {
31+
this.multifeed = multifeed;
32+
return this;
33+
}
34+
35+
/** Get multifeed */
36+
@javax.annotation.Nullable
37+
public Multifeed getMultifeed() {
38+
return multifeed;
39+
}
40+
2741
@Override
2842
public boolean equals(Object o) {
2943
if (this == o) {
@@ -33,19 +47,20 @@ public boolean equals(Object o) {
3347
return false;
3448
}
3549
CompositionBehavior compositionBehavior = (CompositionBehavior) o;
36-
return Objects.equals(this.injection, compositionBehavior.injection);
50+
return Objects.equals(this.injection, compositionBehavior.injection) && Objects.equals(this.multifeed, compositionBehavior.multifeed);
3751
}
3852

3953
@Override
4054
public int hashCode() {
41-
return Objects.hash(injection);
55+
return Objects.hash(injection, multifeed);
4256
}
4357

4458
@Override
4559
public String toString() {
4660
StringBuilder sb = new StringBuilder();
4761
sb.append("class CompositionBehavior {\n");
4862
sb.append(" injection: ").append(toIndentedString(injection)).append("\n");
63+
sb.append(" multifeed: ").append(toIndentedString(multifeed)).append("\n");
4964
sb.append("}");
5065
return sb.toString();
5166
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost
2+
// - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
3+
4+
package com.algolia.model.composition;
5+
6+
import com.fasterxml.jackson.annotation.*;
7+
import com.fasterxml.jackson.databind.annotation.*;
8+
import java.util.ArrayList;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
import java.util.Objects;
13+
14+
/** Multifeed */
15+
public class Multifeed {
16+
17+
@JsonProperty("feeds")
18+
private Map<String, Injection> feeds = new HashMap<>();
19+
20+
@JsonProperty("feedsOrder")
21+
private List<String> feedsOrder;
22+
23+
public Multifeed setFeeds(Map<String, Injection> feeds) {
24+
this.feeds = feeds;
25+
return this;
26+
}
27+
28+
public Multifeed putFeeds(String key, Injection feedsItem) {
29+
this.feeds.put(key, feedsItem);
30+
return this;
31+
}
32+
33+
/**
34+
* A key-value store of Feed ID to Feed. Currently, the only supported Feed type is an Injection.
35+
*/
36+
@javax.annotation.Nonnull
37+
public Map<String, Injection> getFeeds() {
38+
return feeds;
39+
}
40+
41+
public Multifeed setFeedsOrder(List<String> feedsOrder) {
42+
this.feedsOrder = feedsOrder;
43+
return this;
44+
}
45+
46+
public Multifeed addFeedsOrder(String feedsOrderItem) {
47+
if (this.feedsOrder == null) {
48+
this.feedsOrder = new ArrayList<>();
49+
}
50+
this.feedsOrder.add(feedsOrderItem);
51+
return this;
52+
}
53+
54+
/**
55+
* A list of Feed IDs that specifies the order in which to order the results in the response. The
56+
* IDs should be a subset of those in the Feeds object, and only those specified will be
57+
* processed. When this field is not set, all Feeds are processed and returned with a default
58+
* ordering.
59+
*/
60+
@javax.annotation.Nullable
61+
public List<String> getFeedsOrder() {
62+
return feedsOrder;
63+
}
64+
65+
@Override
66+
public boolean equals(Object o) {
67+
if (this == o) {
68+
return true;
69+
}
70+
if (o == null || getClass() != o.getClass()) {
71+
return false;
72+
}
73+
Multifeed multifeed = (Multifeed) o;
74+
return Objects.equals(this.feeds, multifeed.feeds) && Objects.equals(this.feedsOrder, multifeed.feedsOrder);
75+
}
76+
77+
@Override
78+
public int hashCode() {
79+
return Objects.hash(feeds, feedsOrder);
80+
}
81+
82+
@Override
83+
public String toString() {
84+
StringBuilder sb = new StringBuilder();
85+
sb.append("class Multifeed {\n");
86+
sb.append(" feeds: ").append(toIndentedString(feeds)).append("\n");
87+
sb.append(" feedsOrder: ").append(toIndentedString(feedsOrder)).append("\n");
88+
sb.append("}");
89+
return sb.toString();
90+
}
91+
92+
/**
93+
* Convert the given object to string with each line indented by 4 spaces (except the first line).
94+
*/
95+
private String toIndentedString(Object o) {
96+
if (o == null) {
97+
return "null";
98+
}
99+
return o.toString().replace("\n", "\n ");
100+
}
101+
}

0 commit comments

Comments
 (0)