Skip to content

Commit bce1e00

Browse files
fix(client): mark request body as required
1 parent 74dcc48 commit bce1e00

6 files changed

Lines changed: 81 additions & 71 deletions

File tree

lithic-java-core/src/main/kotlin/com/lithic/api/models/ExternalBankAccountCreateParams.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ import kotlin.jvm.optionals.getOrNull
3535
/** Creates an external bank account within a program or Lithic account. */
3636
class ExternalBankAccountCreateParams
3737
private constructor(
38-
private val body: Body?,
38+
private val body: Body,
3939
private val additionalHeaders: Headers,
4040
private val additionalQueryParams: QueryParams,
4141
) : Params {
4242

43-
fun body(): Optional<Body> = Optional.ofNullable(body)
43+
fun body(): Body = body
4444

4545
/** Additional headers to send with the request. */
4646
fun _additionalHeaders(): Headers = additionalHeaders
@@ -52,11 +52,14 @@ private constructor(
5252

5353
companion object {
5454

55-
@JvmStatic fun none(): ExternalBankAccountCreateParams = builder().build()
56-
5755
/**
5856
* Returns a mutable builder for constructing an instance of
5957
* [ExternalBankAccountCreateParams].
58+
*
59+
* The following fields are required:
60+
* ```java
61+
* .body()
62+
* ```
6063
*/
6164
@JvmStatic fun builder() = Builder()
6265
}
@@ -77,10 +80,7 @@ private constructor(
7780
externalBankAccountCreateParams.additionalQueryParams.toBuilder()
7881
}
7982

80-
fun body(body: Body?) = apply { this.body = body }
81-
82-
/** Alias for calling [Builder.body] with `body.orElse(null)`. */
83-
fun body(body: Optional<Body>) = body(body.getOrNull())
83+
fun body(body: Body) = apply { this.body = body }
8484

8585
/**
8686
* Alias for calling [body] with
@@ -205,16 +205,23 @@ private constructor(
205205
* Returns an immutable instance of [ExternalBankAccountCreateParams].
206206
*
207207
* Further updates to this [Builder] will not mutate the returned instance.
208+
*
209+
* The following fields are required:
210+
* ```java
211+
* .body()
212+
* ```
213+
*
214+
* @throws IllegalStateException if any required field is unset.
208215
*/
209216
fun build(): ExternalBankAccountCreateParams =
210217
ExternalBankAccountCreateParams(
211-
body,
218+
checkRequired("body", body),
212219
additionalHeaders.build(),
213220
additionalQueryParams.build(),
214221
)
215222
}
216223

217-
fun _body(): Optional<Body> = Optional.ofNullable(body)
224+
fun _body(): Body = body
218225

219226
override fun _headers(): Headers = additionalHeaders
220227

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

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,15 @@ interface ExternalBankAccountServiceAsync {
3939
fun microDeposits(): MicroDepositServiceAsync
4040

4141
/** Creates an external bank account within a program or Lithic account. */
42-
fun create(): CompletableFuture<ExternalBankAccountCreateResponse> =
43-
create(ExternalBankAccountCreateParams.none())
44-
45-
/** @see create */
46-
fun create(
47-
params: ExternalBankAccountCreateParams = ExternalBankAccountCreateParams.none(),
48-
requestOptions: RequestOptions = RequestOptions.none(),
49-
): CompletableFuture<ExternalBankAccountCreateResponse>
50-
51-
/** @see create */
5242
fun create(
53-
params: ExternalBankAccountCreateParams = ExternalBankAccountCreateParams.none()
43+
params: ExternalBankAccountCreateParams
5444
): CompletableFuture<ExternalBankAccountCreateResponse> = create(params, RequestOptions.none())
5545

5646
/** @see create */
5747
fun create(
58-
requestOptions: RequestOptions
59-
): CompletableFuture<ExternalBankAccountCreateResponse> =
60-
create(ExternalBankAccountCreateParams.none(), requestOptions)
48+
params: ExternalBankAccountCreateParams,
49+
requestOptions: RequestOptions = RequestOptions.none(),
50+
): CompletableFuture<ExternalBankAccountCreateResponse>
6151

6252
/** Get the external bank account by token. */
6353
fun retrieve(
@@ -320,26 +310,16 @@ interface ExternalBankAccountServiceAsync {
320310
* Returns a raw HTTP response for `post /v1/external_bank_accounts`, but is otherwise the
321311
* same as [ExternalBankAccountServiceAsync.create].
322312
*/
323-
fun create(): CompletableFuture<HttpResponseFor<ExternalBankAccountCreateResponse>> =
324-
create(ExternalBankAccountCreateParams.none())
325-
326-
/** @see create */
327-
fun create(
328-
params: ExternalBankAccountCreateParams = ExternalBankAccountCreateParams.none(),
329-
requestOptions: RequestOptions = RequestOptions.none(),
330-
): CompletableFuture<HttpResponseFor<ExternalBankAccountCreateResponse>>
331-
332-
/** @see create */
333313
fun create(
334-
params: ExternalBankAccountCreateParams = ExternalBankAccountCreateParams.none()
314+
params: ExternalBankAccountCreateParams
335315
): CompletableFuture<HttpResponseFor<ExternalBankAccountCreateResponse>> =
336316
create(params, RequestOptions.none())
337317

338318
/** @see create */
339319
fun create(
340-
requestOptions: RequestOptions
341-
): CompletableFuture<HttpResponseFor<ExternalBankAccountCreateResponse>> =
342-
create(ExternalBankAccountCreateParams.none(), requestOptions)
320+
params: ExternalBankAccountCreateParams,
321+
requestOptions: RequestOptions = RequestOptions.none(),
322+
): CompletableFuture<HttpResponseFor<ExternalBankAccountCreateResponse>>
343323

344324
/**
345325
* Returns a raw HTTP response for `get

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalBankAcc
139139
.method(HttpMethod.POST)
140140
.baseUrl(clientOptions.baseUrl())
141141
.addPathSegments("v1", "external_bank_accounts")
142-
.apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } }
142+
.body(json(clientOptions.jsonMapper, params._body()))
143143
.build()
144144
.prepareAsync(clientOptions, params)
145145
val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions))

lithic-java-core/src/main/kotlin/com/lithic/api/services/blocking/ExternalBankAccountService.kt

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,15 @@ interface ExternalBankAccountService {
3939
fun microDeposits(): MicroDepositService
4040

4141
/** Creates an external bank account within a program or Lithic account. */
42-
fun create(): ExternalBankAccountCreateResponse = create(ExternalBankAccountCreateParams.none())
42+
fun create(params: ExternalBankAccountCreateParams): ExternalBankAccountCreateResponse =
43+
create(params, RequestOptions.none())
4344

4445
/** @see create */
4546
fun create(
46-
params: ExternalBankAccountCreateParams = ExternalBankAccountCreateParams.none(),
47+
params: ExternalBankAccountCreateParams,
4748
requestOptions: RequestOptions = RequestOptions.none(),
4849
): ExternalBankAccountCreateResponse
4950

50-
/** @see create */
51-
fun create(
52-
params: ExternalBankAccountCreateParams = ExternalBankAccountCreateParams.none()
53-
): ExternalBankAccountCreateResponse = create(params, RequestOptions.none())
54-
55-
/** @see create */
56-
fun create(requestOptions: RequestOptions): ExternalBankAccountCreateResponse =
57-
create(ExternalBankAccountCreateParams.none(), requestOptions)
58-
5951
/** Get the external bank account by token. */
6052
fun retrieve(externalBankAccountToken: String): ExternalBankAccountRetrieveResponse =
6153
retrieve(externalBankAccountToken, ExternalBankAccountRetrieveParams.none())
@@ -307,29 +299,17 @@ interface ExternalBankAccountService {
307299
* same as [ExternalBankAccountService.create].
308300
*/
309301
@MustBeClosed
310-
fun create(): HttpResponseFor<ExternalBankAccountCreateResponse> =
311-
create(ExternalBankAccountCreateParams.none())
312-
313-
/** @see create */
314-
@MustBeClosed
315302
fun create(
316-
params: ExternalBankAccountCreateParams = ExternalBankAccountCreateParams.none(),
317-
requestOptions: RequestOptions = RequestOptions.none(),
318-
): HttpResponseFor<ExternalBankAccountCreateResponse>
319-
320-
/** @see create */
321-
@MustBeClosed
322-
fun create(
323-
params: ExternalBankAccountCreateParams = ExternalBankAccountCreateParams.none()
303+
params: ExternalBankAccountCreateParams
324304
): HttpResponseFor<ExternalBankAccountCreateResponse> =
325305
create(params, RequestOptions.none())
326306

327307
/** @see create */
328308
@MustBeClosed
329309
fun create(
330-
requestOptions: RequestOptions
331-
): HttpResponseFor<ExternalBankAccountCreateResponse> =
332-
create(ExternalBankAccountCreateParams.none(), requestOptions)
310+
params: ExternalBankAccountCreateParams,
311+
requestOptions: RequestOptions = RequestOptions.none(),
312+
): HttpResponseFor<ExternalBankAccountCreateResponse>
333313

334314
/**
335315
* Returns a raw HTTP response for `get

lithic-java-core/src/main/kotlin/com/lithic/api/services/blocking/ExternalBankAccountServiceImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalBankAcc
135135
.method(HttpMethod.POST)
136136
.baseUrl(clientOptions.baseUrl())
137137
.addPathSegments("v1", "external_bank_accounts")
138-
.apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } }
138+
.body(json(clientOptions.jsonMapper, params._body()))
139139
.build()
140140
.prepare(clientOptions, params)
141141
val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions))

lithic-java-core/src/test/kotlin/com/lithic/api/models/ExternalBankAccountCreateParamsTest.kt

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package com.lithic.api.models
44

55
import java.time.LocalDate
6-
import kotlin.jvm.optionals.getOrNull
76
import org.assertj.core.api.Assertions.assertThat
87
import org.junit.jupiter.api.Test
98

@@ -92,7 +91,7 @@ internal class ExternalBankAccountCreateParamsTest {
9291
)
9392
.build()
9493

95-
val body = params._body().getOrNull()
94+
val body = params._body()
9695

9796
assertThat(body)
9897
.isEqualTo(
@@ -137,8 +136,52 @@ internal class ExternalBankAccountCreateParamsTest {
137136

138137
@Test
139138
fun bodyWithoutOptionalFields() {
140-
val params = ExternalBankAccountCreateParams.builder().build()
139+
val params =
140+
ExternalBankAccountCreateParams.builder()
141+
.body(
142+
ExternalBankAccountCreateParams.Body.BankVerifiedCreateBankAccountApiRequest
143+
.builder()
144+
.accountNumber("13719713158835300")
145+
.country("USA")
146+
.currency("USD")
147+
.financialAccountToken("dabadb3b-700c-41e3-8801-d5dfc84ebea0")
148+
.owner("John Doe")
149+
.ownerType(OwnerType.BUSINESS)
150+
.routingNumber("011103093")
151+
.type(
152+
ExternalBankAccountCreateParams.Body
153+
.BankVerifiedCreateBankAccountApiRequest
154+
.AccountType
155+
.CHECKING
156+
)
157+
.verificationMethod(VerificationMethod.MICRO_DEPOSIT)
158+
.build()
159+
)
160+
.build()
161+
162+
val body = params._body()
141163

142-
val body = params._body().getOrNull()
164+
assertThat(body)
165+
.isEqualTo(
166+
ExternalBankAccountCreateParams.Body.ofBankVerifiedCreateBankAccountApiRequest(
167+
ExternalBankAccountCreateParams.Body.BankVerifiedCreateBankAccountApiRequest
168+
.builder()
169+
.accountNumber("13719713158835300")
170+
.country("USA")
171+
.currency("USD")
172+
.financialAccountToken("dabadb3b-700c-41e3-8801-d5dfc84ebea0")
173+
.owner("John Doe")
174+
.ownerType(OwnerType.BUSINESS)
175+
.routingNumber("011103093")
176+
.type(
177+
ExternalBankAccountCreateParams.Body
178+
.BankVerifiedCreateBankAccountApiRequest
179+
.AccountType
180+
.CHECKING
181+
)
182+
.verificationMethod(VerificationMethod.MICRO_DEPOSIT)
183+
.build()
184+
)
185+
)
143186
}
144187
}

0 commit comments

Comments
 (0)