Skip to content

Commit 183b132

Browse files
feat(pagination): avoid fetching when has_more: false (#209)
1 parent 8eb2394 commit 183b132

25 files changed

+601
-97
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 61
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-7c699d4503077d06a4a44f52c0c1f902d19a87c766b8be75b97c8dfd484ad4aa.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-dfb00c627f58e5180af7a9b29ed2f2aa0764a3b9daa6a32a1cc45bc8e48dfe15.yml

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ private constructor(
3131

3232
fun data(): List<Batch> = response().data()
3333

34+
fun hasMore(): Optional<Boolean> = response().hasMore()
35+
3436
override fun equals(other: Any?): Boolean {
3537
if (this === other) {
3638
return true
@@ -78,15 +80,21 @@ private constructor(
7880
@JsonCreator
7981
constructor(
8082
@JsonProperty("data") private val data: JsonField<List<Batch>> = JsonMissing.of(),
83+
@JsonProperty("has_more") private val hasMore: JsonField<Boolean> = JsonMissing.of(),
8184
@JsonAnySetter
8285
private val additionalProperties: Map<String, JsonValue> = immutableEmptyMap(),
8386
) {
8487

8588
fun data(): List<Batch> = data.getNullable("data") ?: listOf()
8689

90+
fun hasMore(): Optional<Boolean> = Optional.ofNullable(hasMore.getNullable("has_more"))
91+
8792
@JsonProperty("data")
8893
fun _data(): Optional<JsonField<List<Batch>>> = Optional.ofNullable(data)
8994

95+
@JsonProperty("has_more")
96+
fun _hasMore(): Optional<JsonField<Boolean>> = Optional.ofNullable(hasMore)
97+
9098
@JsonAnyGetter
9199
@ExcludeMissing
92100
fun _additionalProperties(): Map<String, JsonValue> = additionalProperties
@@ -99,6 +107,7 @@ private constructor(
99107
}
100108

101109
data().map { it.validate() }
110+
hasMore()
102111
validated = true
103112
}
104113

@@ -109,12 +118,13 @@ private constructor(
109118
return true
110119
}
111120

112-
return /* spotless:off */ other is Response && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */
121+
return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */
113122
}
114123

115-
override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */
124+
override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */
116125

117-
override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}"
126+
override fun toString() =
127+
"Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}"
118128

119129
companion object {
120130

@@ -124,23 +134,34 @@ private constructor(
124134
class Builder {
125135

126136
private var data: JsonField<List<Batch>> = JsonMissing.of()
137+
private var hasMore: JsonField<Boolean> = JsonMissing.of()
127138
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
128139

129140
@JvmSynthetic
130141
internal fun from(page: Response) = apply {
131142
this.data = page.data
143+
this.hasMore = page.hasMore
132144
this.additionalProperties.putAll(page.additionalProperties)
133145
}
134146

135147
fun data(data: List<Batch>) = data(JsonField.of(data))
136148

137149
fun data(data: JsonField<List<Batch>>) = apply { this.data = data }
138150

151+
fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore))
152+
153+
fun hasMore(hasMore: JsonField<Boolean>) = apply { this.hasMore = hasMore }
154+
139155
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
140156
this.additionalProperties.put(key, value)
141157
}
142158

143-
fun build() = Response(data, additionalProperties.toImmutable())
159+
fun build() =
160+
Response(
161+
data,
162+
hasMore,
163+
additionalProperties.toImmutable(),
164+
)
144165
}
145166
}
146167

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ private constructor(
3232

3333
fun data(): List<Batch> = response().data()
3434

35+
fun hasMore(): Optional<Boolean> = response().hasMore()
36+
3537
override fun equals(other: Any?): Boolean {
3638
if (this === other) {
3739
return true
@@ -81,15 +83,21 @@ private constructor(
8183
@JsonCreator
8284
constructor(
8385
@JsonProperty("data") private val data: JsonField<List<Batch>> = JsonMissing.of(),
86+
@JsonProperty("has_more") private val hasMore: JsonField<Boolean> = JsonMissing.of(),
8487
@JsonAnySetter
8588
private val additionalProperties: Map<String, JsonValue> = immutableEmptyMap(),
8689
) {
8790

8891
fun data(): List<Batch> = data.getNullable("data") ?: listOf()
8992

93+
fun hasMore(): Optional<Boolean> = Optional.ofNullable(hasMore.getNullable("has_more"))
94+
9095
@JsonProperty("data")
9196
fun _data(): Optional<JsonField<List<Batch>>> = Optional.ofNullable(data)
9297

98+
@JsonProperty("has_more")
99+
fun _hasMore(): Optional<JsonField<Boolean>> = Optional.ofNullable(hasMore)
100+
93101
@JsonAnyGetter
94102
@ExcludeMissing
95103
fun _additionalProperties(): Map<String, JsonValue> = additionalProperties
@@ -102,6 +110,7 @@ private constructor(
102110
}
103111

104112
data().map { it.validate() }
113+
hasMore()
105114
validated = true
106115
}
107116

@@ -112,12 +121,13 @@ private constructor(
112121
return true
113122
}
114123

115-
return /* spotless:off */ other is Response && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */
124+
return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */
116125
}
117126

118-
override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */
127+
override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */
119128

120-
override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}"
129+
override fun toString() =
130+
"Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}"
121131

122132
companion object {
123133

@@ -127,23 +137,34 @@ private constructor(
127137
class Builder {
128138

129139
private var data: JsonField<List<Batch>> = JsonMissing.of()
140+
private var hasMore: JsonField<Boolean> = JsonMissing.of()
130141
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
131142

132143
@JvmSynthetic
133144
internal fun from(page: Response) = apply {
134145
this.data = page.data
146+
this.hasMore = page.hasMore
135147
this.additionalProperties.putAll(page.additionalProperties)
136148
}
137149

138150
fun data(data: List<Batch>) = data(JsonField.of(data))
139151

140152
fun data(data: JsonField<List<Batch>>) = apply { this.data = data }
141153

154+
fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore))
155+
156+
fun hasMore(hasMore: JsonField<Boolean>) = apply { this.hasMore = hasMore }
157+
142158
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
143159
this.additionalProperties.put(key, value)
144160
}
145161

146-
fun build() = Response(data, additionalProperties.toImmutable())
162+
fun build() =
163+
Response(
164+
data,
165+
hasMore,
166+
additionalProperties.toImmutable(),
167+
)
147168
}
148169
}
149170

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ private constructor(
3131

3232
fun data(): List<Assistant> = response().data()
3333

34+
fun hasMore(): Optional<Boolean> = response().hasMore()
35+
3436
override fun equals(other: Any?): Boolean {
3537
if (this === other) {
3638
return true
@@ -84,15 +86,21 @@ private constructor(
8486
@JsonCreator
8587
constructor(
8688
@JsonProperty("data") private val data: JsonField<List<Assistant>> = JsonMissing.of(),
89+
@JsonProperty("has_more") private val hasMore: JsonField<Boolean> = JsonMissing.of(),
8790
@JsonAnySetter
8891
private val additionalProperties: Map<String, JsonValue> = immutableEmptyMap(),
8992
) {
9093

9194
fun data(): List<Assistant> = data.getNullable("data") ?: listOf()
9295

96+
fun hasMore(): Optional<Boolean> = Optional.ofNullable(hasMore.getNullable("has_more"))
97+
9398
@JsonProperty("data")
9499
fun _data(): Optional<JsonField<List<Assistant>>> = Optional.ofNullable(data)
95100

101+
@JsonProperty("has_more")
102+
fun _hasMore(): Optional<JsonField<Boolean>> = Optional.ofNullable(hasMore)
103+
96104
@JsonAnyGetter
97105
@ExcludeMissing
98106
fun _additionalProperties(): Map<String, JsonValue> = additionalProperties
@@ -105,6 +113,7 @@ private constructor(
105113
}
106114

107115
data().map { it.validate() }
116+
hasMore()
108117
validated = true
109118
}
110119

@@ -115,12 +124,13 @@ private constructor(
115124
return true
116125
}
117126

118-
return /* spotless:off */ other is Response && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */
127+
return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */
119128
}
120129

121-
override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */
130+
override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */
122131

123-
override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}"
132+
override fun toString() =
133+
"Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}"
124134

125135
companion object {
126136

@@ -130,23 +140,34 @@ private constructor(
130140
class Builder {
131141

132142
private var data: JsonField<List<Assistant>> = JsonMissing.of()
143+
private var hasMore: JsonField<Boolean> = JsonMissing.of()
133144
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
134145

135146
@JvmSynthetic
136147
internal fun from(page: Response) = apply {
137148
this.data = page.data
149+
this.hasMore = page.hasMore
138150
this.additionalProperties.putAll(page.additionalProperties)
139151
}
140152

141153
fun data(data: List<Assistant>) = data(JsonField.of(data))
142154

143155
fun data(data: JsonField<List<Assistant>>) = apply { this.data = data }
144156

157+
fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore))
158+
159+
fun hasMore(hasMore: JsonField<Boolean>) = apply { this.hasMore = hasMore }
160+
145161
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
146162
this.additionalProperties.put(key, value)
147163
}
148164

149-
fun build() = Response(data, additionalProperties.toImmutable())
165+
fun build() =
166+
Response(
167+
data,
168+
hasMore,
169+
additionalProperties.toImmutable(),
170+
)
150171
}
151172
}
152173

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ private constructor(
3232

3333
fun data(): List<Assistant> = response().data()
3434

35+
fun hasMore(): Optional<Boolean> = response().hasMore()
36+
3537
override fun equals(other: Any?): Boolean {
3638
if (this === other) {
3739
return true
@@ -87,15 +89,21 @@ private constructor(
8789
@JsonCreator
8890
constructor(
8991
@JsonProperty("data") private val data: JsonField<List<Assistant>> = JsonMissing.of(),
92+
@JsonProperty("has_more") private val hasMore: JsonField<Boolean> = JsonMissing.of(),
9093
@JsonAnySetter
9194
private val additionalProperties: Map<String, JsonValue> = immutableEmptyMap(),
9295
) {
9396

9497
fun data(): List<Assistant> = data.getNullable("data") ?: listOf()
9598

99+
fun hasMore(): Optional<Boolean> = Optional.ofNullable(hasMore.getNullable("has_more"))
100+
96101
@JsonProperty("data")
97102
fun _data(): Optional<JsonField<List<Assistant>>> = Optional.ofNullable(data)
98103

104+
@JsonProperty("has_more")
105+
fun _hasMore(): Optional<JsonField<Boolean>> = Optional.ofNullable(hasMore)
106+
99107
@JsonAnyGetter
100108
@ExcludeMissing
101109
fun _additionalProperties(): Map<String, JsonValue> = additionalProperties
@@ -108,6 +116,7 @@ private constructor(
108116
}
109117

110118
data().map { it.validate() }
119+
hasMore()
111120
validated = true
112121
}
113122

@@ -118,12 +127,13 @@ private constructor(
118127
return true
119128
}
120129

121-
return /* spotless:off */ other is Response && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */
130+
return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */
122131
}
123132

124-
override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */
133+
override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */
125134

126-
override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}"
135+
override fun toString() =
136+
"Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}"
127137

128138
companion object {
129139

@@ -133,23 +143,34 @@ private constructor(
133143
class Builder {
134144

135145
private var data: JsonField<List<Assistant>> = JsonMissing.of()
146+
private var hasMore: JsonField<Boolean> = JsonMissing.of()
136147
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
137148

138149
@JvmSynthetic
139150
internal fun from(page: Response) = apply {
140151
this.data = page.data
152+
this.hasMore = page.hasMore
141153
this.additionalProperties.putAll(page.additionalProperties)
142154
}
143155

144156
fun data(data: List<Assistant>) = data(JsonField.of(data))
145157

146158
fun data(data: JsonField<List<Assistant>>) = apply { this.data = data }
147159

160+
fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore))
161+
162+
fun hasMore(hasMore: JsonField<Boolean>) = apply { this.hasMore = hasMore }
163+
148164
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
149165
this.additionalProperties.put(key, value)
150166
}
151167

152-
fun build() = Response(data, additionalProperties.toImmutable())
168+
fun build() =
169+
Response(
170+
data,
171+
hasMore,
172+
additionalProperties.toImmutable(),
173+
)
153174
}
154175
}
155176

0 commit comments

Comments
 (0)