Skip to content

Commit 32afc29

Browse files
release: 1.2.0 (#434)
* refactor(client): deduplicate page response classes (#433) feat(client): make pagination robust to missing data docs: add comments for page methods * refactor(client): migrate pages to builder pattern (#435) * release: 1.2.0 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
1 parent 412d7eb commit 32afc29

File tree

128 files changed

+14186
-6555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+14186
-6555
lines changed

.release-please-manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.1.1"
2+
".": "1.2.0"
33
}

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Changelog
22

3+
## 1.2.0 (2025-04-09)
4+
5+
Full Changelog: [v1.1.1...v1.2.0](https://github.com/openai/openai-java/compare/v1.1.1...v1.2.0)
6+
7+
### Features
8+
9+
* **client:** make pagination robust to missing data ([cbccde5](https://github.com/openai/openai-java/commit/cbccde5bbbea40289a7143d40ce5e8c7ac7643ff))
10+
11+
12+
### Documentation
13+
14+
* add comments for page methods ([cbccde5](https://github.com/openai/openai-java/commit/cbccde5bbbea40289a7143d40ce5e8c7ac7643ff))
15+
16+
17+
### Refactors
18+
19+
* **client:** deduplicate page response classes ([#433](https://github.com/openai/openai-java/issues/433)) ([cbccde5](https://github.com/openai/openai-java/commit/cbccde5bbbea40289a7143d40ce5e8c7ac7643ff))
20+
* **client:** migrate pages to builder pattern ([#435](https://github.com/openai/openai-java/issues/435)) ([8cb8878](https://github.com/openai/openai-java/commit/8cb8878becd07e31844f981bafd147c630606c07))
21+
322
## 1.1.1 (2025-04-09)
423

524
Full Changelog: [v1.1.0...v1.1.1](https://github.com/openai/openai-java/compare/v1.1.0...v1.1.1)

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
<!-- x-release-please-start-version -->
44

5-
[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/1.1.1)
6-
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/1.1.1/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/1.1.1)
5+
[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/1.2.0)
6+
[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/1.2.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/1.2.0)
77

88
<!-- x-release-please-end -->
99

1010
The OpenAI Java SDK provides convenient access to the [OpenAI REST API](https://platform.openai.com/docs) from applications written in Java.
1111

1212
<!-- x-release-please-start-version -->
1313

14-
The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/1.1.1).
14+
The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/1.2.0).
1515

1616
<!-- x-release-please-end -->
1717

@@ -22,7 +22,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor
2222
### Gradle
2323

2424
```kotlin
25-
implementation("com.openai:openai-java:1.1.1")
25+
implementation("com.openai:openai-java:1.2.0")
2626
```
2727

2828
### Maven
@@ -31,7 +31,7 @@ implementation("com.openai:openai-java:1.1.1")
3131
<dependency>
3232
<groupId>com.openai</groupId>
3333
<artifactId>openai-java</artifactId>
34-
<version>1.1.1</version>
34+
<version>1.2.0</version>
3535
</dependency>
3636
```
3737

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repositories {
88

99
allprojects {
1010
group = "com.openai"
11-
version = "1.1.1" // x-release-please-version
11+
version = "1.2.0" // x-release-please-version
1212
}
1313

1414
subprojects {

openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPage.kt

+87-140
Original file line numberDiff line numberDiff line change
@@ -2,180 +2,115 @@
22

33
package com.openai.models.batches
44

5-
import com.fasterxml.jackson.annotation.JsonAnyGetter
6-
import com.fasterxml.jackson.annotation.JsonAnySetter
7-
import com.fasterxml.jackson.annotation.JsonCreator
8-
import com.fasterxml.jackson.annotation.JsonProperty
9-
import com.openai.core.ExcludeMissing
10-
import com.openai.core.JsonField
11-
import com.openai.core.JsonMissing
12-
import com.openai.core.JsonValue
13-
import com.openai.errors.OpenAIInvalidDataException
5+
import com.openai.core.checkRequired
146
import com.openai.services.blocking.BatchService
15-
import java.util.Collections
167
import java.util.Objects
178
import java.util.Optional
189
import java.util.stream.Stream
1910
import java.util.stream.StreamSupport
2011
import kotlin.jvm.optionals.getOrNull
2112

22-
/** List your organization's batches. */
13+
/** @see [BatchService.list] */
2314
class BatchListPage
2415
private constructor(
25-
private val batchesService: BatchService,
16+
private val service: BatchService,
2617
private val params: BatchListParams,
27-
private val response: Response,
18+
private val response: BatchListPageResponse,
2819
) {
2920

30-
fun response(): Response = response
21+
/**
22+
* Delegates to [BatchListPageResponse], but gracefully handles missing data.
23+
*
24+
* @see [BatchListPageResponse.data]
25+
*/
26+
fun data(): List<Batch> = response._data().getOptional("data").getOrNull() ?: emptyList()
3127

32-
fun data(): List<Batch> = response().data()
28+
/**
29+
* Delegates to [BatchListPageResponse], but gracefully handles missing data.
30+
*
31+
* @see [BatchListPageResponse.hasMore]
32+
*/
33+
fun hasMore(): Optional<Boolean> = response._hasMore().getOptional("has_more")
3334

34-
fun hasMore(): Optional<Boolean> = response().hasMore()
35-
36-
override fun equals(other: Any?): Boolean {
37-
if (this === other) {
38-
return true
39-
}
40-
41-
return /* spotless:off */ other is BatchListPage && batchesService == other.batchesService && params == other.params && response == other.response /* spotless:on */
42-
}
43-
44-
override fun hashCode(): Int = /* spotless:off */ Objects.hash(batchesService, params, response) /* spotless:on */
45-
46-
override fun toString() =
47-
"BatchListPage{batchesService=$batchesService, params=$params, response=$response}"
48-
49-
fun hasNextPage(): Boolean {
50-
return !data().isEmpty()
51-
}
35+
fun hasNextPage(): Boolean = data().isNotEmpty()
5236

5337
fun getNextPageParams(): Optional<BatchListParams> {
5438
if (!hasNextPage()) {
5539
return Optional.empty()
5640
}
5741

58-
return Optional.of(params.toBuilder().after(data().last().id()).build())
42+
return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build())
5943
}
6044

61-
fun getNextPage(): Optional<BatchListPage> {
62-
return getNextPageParams().map { batchesService.list(it) }
63-
}
45+
fun getNextPage(): Optional<BatchListPage> = getNextPageParams().map { service.list(it) }
6446

6547
fun autoPager(): AutoPager = AutoPager(this)
6648

67-
companion object {
68-
69-
@JvmStatic
70-
fun of(batchesService: BatchService, params: BatchListParams, response: Response) =
71-
BatchListPage(batchesService, params, response)
72-
}
73-
74-
class Response(
75-
private val data: JsonField<List<Batch>>,
76-
private val hasMore: JsonField<Boolean>,
77-
private val additionalProperties: MutableMap<String, JsonValue>,
78-
) {
79-
80-
@JsonCreator
81-
private constructor(
82-
@JsonProperty("data") data: JsonField<List<Batch>> = JsonMissing.of(),
83-
@JsonProperty("has_more") hasMore: JsonField<Boolean> = JsonMissing.of(),
84-
) : this(data, hasMore, mutableMapOf())
85-
86-
fun data(): List<Batch> = data.getOptional("data").getOrNull() ?: listOf()
87-
88-
fun hasMore(): Optional<Boolean> = hasMore.getOptional("has_more")
89-
90-
@JsonProperty("data")
91-
fun _data(): Optional<JsonField<List<Batch>>> = Optional.ofNullable(data)
92-
93-
@JsonProperty("has_more")
94-
fun _hasMore(): Optional<JsonField<Boolean>> = Optional.ofNullable(hasMore)
49+
/** The parameters that were used to request this page. */
50+
fun params(): BatchListParams = params
9551

96-
@JsonAnySetter
97-
private fun putAdditionalProperty(key: String, value: JsonValue) {
98-
additionalProperties.put(key, value)
99-
}
100-
101-
@JsonAnyGetter
102-
@ExcludeMissing
103-
fun _additionalProperties(): Map<String, JsonValue> =
104-
Collections.unmodifiableMap(additionalProperties)
52+
/** The response that this page was parsed from. */
53+
fun response(): BatchListPageResponse = response
10554

106-
private var validated: Boolean = false
107-
108-
fun validate(): Response = apply {
109-
if (validated) {
110-
return@apply
111-
}
55+
fun toBuilder() = Builder().from(this)
11256

113-
data().map { it.validate() }
114-
hasMore()
115-
validated = true
116-
}
117-
118-
fun isValid(): Boolean =
119-
try {
120-
validate()
121-
true
122-
} catch (e: OpenAIInvalidDataException) {
123-
false
124-
}
125-
126-
fun toBuilder() = Builder().from(this)
127-
128-
override fun equals(other: Any?): Boolean {
129-
if (this === other) {
130-
return true
131-
}
132-
133-
return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */
134-
}
57+
companion object {
13558

136-
override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */
59+
/**
60+
* Returns a mutable builder for constructing an instance of [BatchListPage].
61+
*
62+
* The following fields are required:
63+
* ```java
64+
* .service()
65+
* .params()
66+
* .response()
67+
* ```
68+
*/
69+
@JvmStatic fun builder() = Builder()
70+
}
13771

138-
override fun toString() =
139-
"Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}"
72+
/** A builder for [BatchListPage]. */
73+
class Builder internal constructor() {
14074

141-
companion object {
75+
private var service: BatchService? = null
76+
private var params: BatchListParams? = null
77+
private var response: BatchListPageResponse? = null
14278

143-
/** Returns a mutable builder for constructing an instance of [BatchListPage]. */
144-
@JvmStatic fun builder() = Builder()
79+
@JvmSynthetic
80+
internal fun from(batchListPage: BatchListPage) = apply {
81+
service = batchListPage.service
82+
params = batchListPage.params
83+
response = batchListPage.response
14584
}
14685

147-
class Builder {
148-
149-
private var data: JsonField<List<Batch>> = JsonMissing.of()
150-
private var hasMore: JsonField<Boolean> = JsonMissing.of()
151-
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
152-
153-
@JvmSynthetic
154-
internal fun from(page: Response) = apply {
155-
this.data = page.data
156-
this.hasMore = page.hasMore
157-
this.additionalProperties.putAll(page.additionalProperties)
158-
}
159-
160-
fun data(data: List<Batch>) = data(JsonField.of(data))
161-
162-
fun data(data: JsonField<List<Batch>>) = apply { this.data = data }
163-
164-
fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore))
165-
166-
fun hasMore(hasMore: JsonField<Boolean>) = apply { this.hasMore = hasMore }
167-
168-
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
169-
this.additionalProperties.put(key, value)
170-
}
171-
172-
/**
173-
* Returns an immutable instance of [Response].
174-
*
175-
* Further updates to this [Builder] will not mutate the returned instance.
176-
*/
177-
fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap())
178-
}
86+
fun service(service: BatchService) = apply { this.service = service }
87+
88+
/** The parameters that were used to request this page. */
89+
fun params(params: BatchListParams) = apply { this.params = params }
90+
91+
/** The response that this page was parsed from. */
92+
fun response(response: BatchListPageResponse) = apply { this.response = response }
93+
94+
/**
95+
* Returns an immutable instance of [BatchListPage].
96+
*
97+
* Further updates to this [Builder] will not mutate the returned instance.
98+
*
99+
* The following fields are required:
100+
* ```java
101+
* .service()
102+
* .params()
103+
* .response()
104+
* ```
105+
*
106+
* @throws IllegalStateException if any required field is unset.
107+
*/
108+
fun build(): BatchListPage =
109+
BatchListPage(
110+
checkRequired("service", service),
111+
checkRequired("params", params),
112+
checkRequired("response", response),
113+
)
179114
}
180115

181116
class AutoPager(private val firstPage: BatchListPage) : Iterable<Batch> {
@@ -196,4 +131,16 @@ private constructor(
196131
return StreamSupport.stream(spliterator(), false)
197132
}
198133
}
134+
135+
override fun equals(other: Any?): Boolean {
136+
if (this === other) {
137+
return true
138+
}
139+
140+
return /* spotless:off */ other is BatchListPage && service == other.service && params == other.params && response == other.response /* spotless:on */
141+
}
142+
143+
override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
144+
145+
override fun toString() = "BatchListPage{service=$service, params=$params, response=$response}"
199146
}

0 commit comments

Comments
 (0)