Skip to content

Commit

Permalink
feat(client): allow passing null or optional for nullable fields (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Jan 6, 2025
1 parent df2e113 commit 92d428f
Show file tree
Hide file tree
Showing 100 changed files with 12,140 additions and 2,020 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.moderntreasury.api.core.http.QueryParams
import java.net.Proxy
import java.time.Clock
import java.time.Duration
import java.util.Optional

class ModernTreasuryOkHttpClient private constructor() {

Expand Down Expand Up @@ -134,7 +135,9 @@ class ModernTreasuryOkHttpClient private constructor() {
clientOptions.organizationId(organizationId)
}

fun webhookKey(webhookKey: String) = apply { clientOptions.webhookKey(webhookKey) }
fun webhookKey(webhookKey: String?) = apply { clientOptions.webhookKey(webhookKey) }

fun webhookKey(webhookKey: Optional<String>) = webhookKey(webhookKey.orElse(null))

fun fromEnv() = apply { clientOptions.fromEnv() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.moderntreasury.api.core.http.QueryParams
import java.net.Proxy
import java.time.Clock
import java.time.Duration
import java.util.Optional

class ModernTreasuryOkHttpClientAsync private constructor() {

Expand Down Expand Up @@ -134,7 +135,9 @@ class ModernTreasuryOkHttpClientAsync private constructor() {
clientOptions.organizationId(organizationId)
}

fun webhookKey(webhookKey: String) = apply { clientOptions.webhookKey(webhookKey) }
fun webhookKey(webhookKey: String?) = apply { clientOptions.webhookKey(webhookKey) }

fun webhookKey(webhookKey: Optional<String>) = webhookKey(webhookKey.orElse(null))

fun fromEnv() = apply { clientOptions.fromEnv() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.moderntreasury.api.core.http.QueryParams
import com.moderntreasury.api.core.http.RetryingHttpClient
import java.time.Clock
import java.util.Base64
import java.util.Optional

class ClientOptions
private constructor(
Expand Down Expand Up @@ -165,7 +166,9 @@ private constructor(

fun organizationId(organizationId: String) = apply { this.organizationId = organizationId }

fun webhookKey(webhookKey: String) = apply { this.webhookKey = webhookKey }
fun webhookKey(webhookKey: String?) = apply { this.webhookKey = webhookKey }

fun webhookKey(webhookKey: Optional<String>) = webhookKey(webhookKey.orElse(null))

fun fromEnv() = apply {
System.getenv("MODERN_TREASURY_API_KEY")?.let { apiKey(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ constructor(
paymentTypes = (paymentTypes ?: mutableListOf()).apply { add(paymentType) }
}

fun receivingCountries(receivingCountries: List<ReceivingCountry>) = apply {
this.receivingCountries = receivingCountries.toMutableList()
fun receivingCountries(receivingCountries: List<ReceivingCountry>?) = apply {
this.receivingCountries = receivingCountries?.toMutableList()
}

fun receivingCountries(receivingCountries: Optional<List<ReceivingCountry>>) =
receivingCountries(receivingCountries.orElse(null))

fun addReceivingCountry(receivingCountry: ReceivingCountry) = apply {
receivingCountries =
(receivingCountries ?: mutableListOf()).apply { add(receivingCountry) }
Expand Down Expand Up @@ -195,10 +198,13 @@ constructor(

fun addPaymentType(paymentType: String) = apply { body.addPaymentType(paymentType) }

fun receivingCountries(receivingCountries: List<ReceivingCountry>) = apply {
fun receivingCountries(receivingCountries: List<ReceivingCountry>?) = apply {
body.receivingCountries(receivingCountries)
}

fun receivingCountries(receivingCountries: Optional<List<ReceivingCountry>>) =
receivingCountries(receivingCountries.orElse(null))

fun addReceivingCountry(receivingCountry: ReceivingCountry) = apply {
body.addReceivingCountry(receivingCountry)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,36 @@ constructor(
accountCollectionFlowListParams.additionalQueryParams.toBuilder()
}

fun afterCursor(afterCursor: String) = apply { this.afterCursor = afterCursor }
fun afterCursor(afterCursor: String?) = apply { this.afterCursor = afterCursor }

fun clientToken(clientToken: String) = apply { this.clientToken = clientToken }
fun afterCursor(afterCursor: Optional<String>) = afterCursor(afterCursor.orElse(null))

fun counterpartyId(counterpartyId: String) = apply { this.counterpartyId = counterpartyId }
fun clientToken(clientToken: String?) = apply { this.clientToken = clientToken }

fun externalAccountId(externalAccountId: String) = apply {
fun clientToken(clientToken: Optional<String>) = clientToken(clientToken.orElse(null))

fun counterpartyId(counterpartyId: String?) = apply { this.counterpartyId = counterpartyId }

fun counterpartyId(counterpartyId: Optional<String>) =
counterpartyId(counterpartyId.orElse(null))

fun externalAccountId(externalAccountId: String?) = apply {
this.externalAccountId = externalAccountId
}

fun perPage(perPage: Long) = apply { this.perPage = perPage }
fun externalAccountId(externalAccountId: Optional<String>) =
externalAccountId(externalAccountId.orElse(null))

fun perPage(perPage: Long?) = apply { this.perPage = perPage }

fun perPage(perPage: Long) = perPage(perPage as Long?)

@Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228
fun perPage(perPage: Optional<Long>) = perPage(perPage.orElse(null) as Long?)

fun status(status: String?) = apply { this.status = status }

fun status(status: String) = apply { this.status = status }
fun status(status: Optional<String>) = status(status.orElse(null))

fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,17 @@ constructor(
* One of `iban`, `clabe`, `wallet_address`, or `other`. Use `other` if the bank account
* number is in a generic format.
*/
fun accountNumberType(accountNumberType: AccountNumberType) = apply {
fun accountNumberType(accountNumberType: AccountNumberType?) = apply {
this.accountNumberType = accountNumberType
}

/**
* One of `iban`, `clabe`, `wallet_address`, or `other`. Use `other` if the bank account
* number is in a generic format.
*/
fun accountNumberType(accountNumberType: Optional<AccountNumberType>) =
accountNumberType(accountNumberType.orElse(null))

fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
this.additionalProperties.clear()
putAllAdditionalProperties(additionalProperties)
Expand Down Expand Up @@ -198,10 +205,17 @@ constructor(
* One of `iban`, `clabe`, `wallet_address`, or `other`. Use `other` if the bank account
* number is in a generic format.
*/
fun accountNumberType(accountNumberType: AccountNumberType) = apply {
fun accountNumberType(accountNumberType: AccountNumberType?) = apply {
body.accountNumberType(accountNumberType)
}

/**
* One of `iban`, `clabe`, `wallet_address`, or `other`. Use `other` if the bank account
* number is in a generic format.
*/
fun accountNumberType(accountNumberType: Optional<AccountNumberType>) =
accountNumberType(accountNumberType.orElse(null))

fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
putAllAdditionalHeaders(additionalHeaders)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,16 @@ constructor(

fun accountId(accountId: String) = apply { this.accountId = accountId }

fun afterCursor(afterCursor: String) = apply { this.afterCursor = afterCursor }
fun afterCursor(afterCursor: String?) = apply { this.afterCursor = afterCursor }

fun perPage(perPage: Long) = apply { this.perPage = perPage }
fun afterCursor(afterCursor: Optional<String>) = afterCursor(afterCursor.orElse(null))

fun perPage(perPage: Long?) = apply { this.perPage = perPage }

fun perPage(perPage: Long) = perPage(perPage as Long?)

@Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228
fun perPage(perPage: Optional<Long>) = perPage(perPage.orElse(null) as Long?)

fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,19 @@ constructor(
* `evolve`, `goldman_sachs`, `iso20022`, `jpmc`, `mx`, `signet`, `silvergate`, `swift`,
* or `us_bank`.
*/
fun vendorCodeType(vendorCodeType: String) = apply {
fun vendorCodeType(vendorCodeType: String?) = apply {
this.vendorCodeType = vendorCodeType
}

/**
* The type of `vendor_code` being reported. Can be one of `bai2`, `bankprov`,
* `bnk_dev`, `cleartouch`, `currencycloud`, `cross_river`, `dc_bank`, `dwolla`,
* `evolve`, `goldman_sachs`, `iso20022`, `jpmc`, `mx`, `signet`, `silvergate`, `swift`,
* or `us_bank`.
*/
fun vendorCodeType(vendorCodeType: Optional<String>) =
vendorCodeType(vendorCodeType.orElse(null))

fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
this.additionalProperties.clear()
putAllAdditionalProperties(additionalProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,37 @@ constructor(
this.internalAccountId = internalAccountId
}

fun afterCursor(afterCursor: String) = apply { this.afterCursor = afterCursor }
fun afterCursor(afterCursor: String?) = apply { this.afterCursor = afterCursor }

fun afterCursor(afterCursor: Optional<String>) = afterCursor(afterCursor.orElse(null))

/** The date of the balance report in local time. */
fun asOfDate(asOfDate: LocalDate?) = apply { this.asOfDate = asOfDate }

/** The date of the balance report in local time. */
fun asOfDate(asOfDate: LocalDate) = apply { this.asOfDate = asOfDate }
fun asOfDate(asOfDate: Optional<LocalDate>) = asOfDate(asOfDate.orElse(null))

/**
* The specific type of balance report. One of `intraday`, `previous_day`, `real_time`, or
* `other`.
*/
fun balanceReportType(balanceReportType: BalanceReportType) = apply {
fun balanceReportType(balanceReportType: BalanceReportType?) = apply {
this.balanceReportType = balanceReportType
}

fun perPage(perPage: Long) = apply { this.perPage = perPage }
/**
* The specific type of balance report. One of `intraday`, `previous_day`, `real_time`, or
* `other`.
*/
fun balanceReportType(balanceReportType: Optional<BalanceReportType>) =
balanceReportType(balanceReportType.orElse(null))

fun perPage(perPage: Long?) = apply { this.perPage = perPage }

fun perPage(perPage: Long) = perPage(perPage as Long?)

@Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228
fun perPage(perPage: Optional<Long>) = perPage(perPage.orElse(null) as Long?)

fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
Expand Down
Loading

0 comments on commit 92d428f

Please sign in to comment.