Skip to content

Commit 2df671c

Browse files
fix(api): add missing @MustBeClosed annotations (#479)
fix(api): switch `CompletableFuture<Void>` to `CompletableFuture<Void?>` fix(client): always provide a body for `PATCH` methods fix(client): add missing validation calls on response chore(internal): minor formatting/style changes chore(internal): rename some tests
1 parent c6d80c5 commit 2df671c

246 files changed

Lines changed: 1491 additions & 1638 deletions

File tree

Some content is hidden

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

lithic-java-client-okhttp/src/main/kotlin/com/lithic/api/client/okhttp/OkHttpClient.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
106106

107107
private fun HttpRequest.toRequest(client: okhttp3.OkHttpClient): Request {
108108
var body: RequestBody? = body?.toRequestBody()
109-
// OkHttpClient always requires a request body for PUT and POST methods.
110-
if (body == null && (method == HttpMethod.PUT || method == HttpMethod.POST)) {
109+
if (body == null && requiresBody(method)) {
111110
body = "".toRequestBody()
112111
}
113112

@@ -134,6 +133,15 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
134133
return builder.build()
135134
}
136135

136+
/** `OkHttpClient` always requires a request body for some methods. */
137+
private fun requiresBody(method: HttpMethod): Boolean =
138+
when (method) {
139+
HttpMethod.POST,
140+
HttpMethod.PUT,
141+
HttpMethod.PATCH -> true
142+
else -> false
143+
}
144+
137145
private fun HttpRequest.toUrl(): String {
138146
url?.let {
139147
return it

lithic-java-core/src/main/kotlin/com/lithic/api/client/LithicClientAsyncImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ class LithicClientAsyncImpl(
260260
.thenApply { response ->
261261
response
262262
.use { apiStatusHandler.handle(it) }
263-
.apply {
263+
.also {
264264
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
265-
validate()
265+
it.validate()
266266
}
267267
}
268268
}

lithic-java-core/src/main/kotlin/com/lithic/api/client/LithicClientImpl.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,14 @@ class LithicClientImpl(
239239
.addPathSegments("v1", "status")
240240
.build()
241241
.prepare(clientOptions, params)
242-
return clientOptions.httpClient.execute(request, requestOptions).let { response ->
243-
response
244-
.use { apiStatusHandler.handle(it) }
245-
.apply {
246-
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
247-
validate()
248-
}
242+
val response = clientOptions.httpClient.execute(request, requestOptions)
243+
return response
244+
.use { apiStatusHandler.handle(it) }
245+
.also {
246+
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
247+
it.validate()
249248
}
250-
}
249+
}
251250
}
252251

253252
override fun close() = clientOptions.httpClient.close()

lithic-java-core/src/main/kotlin/com/lithic/api/services/async/AccountHolderServiceAsyncImpl.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ internal constructor(
7474
.thenApply { response ->
7575
response
7676
.use { createHandler.handle(it) }
77-
.apply {
77+
.also {
7878
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
79-
validate()
79+
it.validate()
8080
}
8181
}
8282
}
@@ -101,9 +101,9 @@ internal constructor(
101101
.thenApply { response ->
102102
response
103103
.use { retrieveHandler.handle(it) }
104-
.apply {
104+
.also {
105105
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
106-
validate()
106+
it.validate()
107107
}
108108
}
109109
}
@@ -130,9 +130,9 @@ internal constructor(
130130
.thenApply { response ->
131131
response
132132
.use { updateHandler.handle(it) }
133-
.apply {
133+
.also {
134134
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
135-
validate()
135+
it.validate()
136136
}
137137
}
138138
}
@@ -160,9 +160,9 @@ internal constructor(
160160
.thenApply { response ->
161161
response
162162
.use { listHandler.handle(it) }
163-
.apply {
163+
.also {
164164
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
165-
validate()
165+
it.validate()
166166
}
167167
}
168168
.let { AccountHolderListPageAsync.of(this, params, it) }
@@ -203,9 +203,9 @@ internal constructor(
203203
.thenApply { response ->
204204
response
205205
.use { listDocumentsHandler.handle(it) }
206-
.apply {
206+
.also {
207207
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
208-
validate()
208+
it.validate()
209209
}
210210
}
211211
}
@@ -250,9 +250,9 @@ internal constructor(
250250
.thenApply { response ->
251251
response
252252
.use { retrieveDocumentHandler.handle(it) }
253-
.apply {
253+
.also {
254254
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
255-
validate()
255+
it.validate()
256256
}
257257
}
258258
}
@@ -278,9 +278,9 @@ internal constructor(
278278
.thenApply { response ->
279279
response
280280
.use { simulateEnrollmentDocumentReviewHandler.handle(it) }
281-
.apply {
281+
.also {
282282
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
283-
validate()
283+
it.validate()
284284
}
285285
}
286286
}
@@ -311,9 +311,9 @@ internal constructor(
311311
.thenApply { response ->
312312
response
313313
.use { simulateEnrollmentReviewHandler.handle(it) }
314-
.apply {
314+
.also {
315315
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
316-
validate()
316+
it.validate()
317317
}
318318
}
319319
}
@@ -356,9 +356,9 @@ internal constructor(
356356
.thenApply { response ->
357357
response
358358
.use { uploadDocumentHandler.handle(it) }
359-
.apply {
359+
.also {
360360
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
361-
validate()
361+
it.validate()
362362
}
363363
}
364364
}

lithic-java-core/src/main/kotlin/com/lithic/api/services/async/AccountServiceAsyncImpl.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ internal constructor(
4848
.thenApply { response ->
4949
response
5050
.use { retrieveHandler.handle(it) }
51-
.apply {
51+
.also {
5252
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
53-
validate()
53+
it.validate()
5454
}
5555
}
5656
}
@@ -80,9 +80,9 @@ internal constructor(
8080
.thenApply { response ->
8181
response
8282
.use { updateHandler.handle(it) }
83-
.apply {
83+
.also {
8484
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
85-
validate()
85+
it.validate()
8686
}
8787
}
8888
}
@@ -108,9 +108,9 @@ internal constructor(
108108
.thenApply { response ->
109109
response
110110
.use { listHandler.handle(it) }
111-
.apply {
111+
.also {
112112
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
113-
validate()
113+
it.validate()
114114
}
115115
}
116116
.let { AccountListPageAsync.of(this, params, it) }
@@ -141,9 +141,9 @@ internal constructor(
141141
.thenApply { response ->
142142
response
143143
.use { retrieveSpendLimitsHandler.handle(it) }
144-
.apply {
144+
.also {
145145
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
146-
validate()
146+
it.validate()
147147
}
148148
}
149149
}

lithic-java-core/src/main/kotlin/com/lithic/api/services/async/AggregateBalanceServiceAsyncImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ internal constructor(
4343
.thenApply { response ->
4444
response
4545
.use { listHandler.handle(it) }
46-
.apply {
46+
.also {
4747
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
48-
validate()
48+
it.validate()
4949
}
5050
}
5151
.let { AggregateBalanceListPageAsync.of(this, params, it) }

lithic-java-core/src/main/kotlin/com/lithic/api/services/async/AuthStreamEnrollmentServiceAsync.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ interface AuthStreamEnrollmentServiceAsync {
3535
fun rotateSecret(
3636
params: AuthStreamEnrollmentRotateSecretParams,
3737
requestOptions: RequestOptions = RequestOptions.none()
38-
): CompletableFuture<Void>
38+
): CompletableFuture<Void?>
3939
}

lithic-java-core/src/main/kotlin/com/lithic/api/services/async/AuthStreamEnrollmentServiceAsyncImpl.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ internal constructor(
5151
.thenApply { response ->
5252
response
5353
.use { retrieveSecretHandler.handle(it) }
54-
.apply {
54+
.also {
5555
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
56-
validate()
56+
it.validate()
5757
}
5858
}
5959
}
@@ -70,7 +70,7 @@ internal constructor(
7070
override fun rotateSecret(
7171
params: AuthStreamEnrollmentRotateSecretParams,
7272
requestOptions: RequestOptions
73-
): CompletableFuture<Void> {
73+
): CompletableFuture<Void?> {
7474
val request =
7575
HttpRequest.builder()
7676
.method(HttpMethod.POST)

lithic-java-core/src/main/kotlin/com/lithic/api/services/async/BalanceServiceAsyncImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ internal constructor(
4343
.thenApply { response ->
4444
response
4545
.use { listHandler.handle(it) }
46-
.apply {
46+
.also {
4747
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
48-
validate()
48+
it.validate()
4949
}
5050
}
5151
.let { BalanceListPageAsync.of(this, params, it) }

lithic-java-core/src/main/kotlin/com/lithic/api/services/async/BookTransferServiceAsyncImpl.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ internal constructor(
5050
.thenApply { response ->
5151
response
5252
.use { createHandler.handle(it) }
53-
.apply {
53+
.also {
5454
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
55-
validate()
55+
it.validate()
5656
}
5757
}
5858
}
@@ -77,9 +77,9 @@ internal constructor(
7777
.thenApply { response ->
7878
response
7979
.use { retrieveHandler.handle(it) }
80-
.apply {
80+
.also {
8181
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
82-
validate()
82+
it.validate()
8383
}
8484
}
8585
}
@@ -105,9 +105,9 @@ internal constructor(
105105
.thenApply { response ->
106106
response
107107
.use { listHandler.handle(it) }
108-
.apply {
108+
.also {
109109
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
110-
validate()
110+
it.validate()
111111
}
112112
}
113113
.let { BookTransferListPageAsync.of(this, params, it) }
@@ -134,9 +134,9 @@ internal constructor(
134134
.thenApply { response ->
135135
response
136136
.use { reverseHandler.handle(it) }
137-
.apply {
137+
.also {
138138
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
139-
validate()
139+
it.validate()
140140
}
141141
}
142142
}

0 commit comments

Comments
 (0)