diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index 1b5dc400b..0a40b9d77 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.39.0"
+ ".": "0.40.0"
}
\ No newline at end of file
diff --git a/.stats.yml b/.stats.yml
index 5776427f3..715ea230c 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,2 +1,2 @@
configured_endpoints: 103
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-c8fc7d0bf70bf7ed91a141f346a02929e4d25a6fac7b59f58b68136ed6ff024f.yml
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-48084a007f009b4358484f09a3a7b74a990c402669f9d15adfbb60e4f835f951.yml
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dc29c2738..94504c3c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,32 @@
# Changelog
+## 0.40.0 (2025-03-05)
+
+Full Changelog: [v0.39.0...v0.40.0](https://github.com/orbcorp/orb-java/compare/v0.39.0...v0.40.0)
+
+### ⚠ BREAKING CHANGES
+
+* **client:** refactor multipart formdata impl ([#296](https://github.com/orbcorp/orb-java/issues/296))
+
+### Features
+
+* **api:** api update ([#300](https://github.com/orbcorp/orb-java/issues/300)) ([d5cb74a](https://github.com/orbcorp/orb-java/commit/d5cb74a47458809ba335447204b1b21166df0ede))
+* **client:** allow configuring timeouts granularly ([#294](https://github.com/orbcorp/orb-java/issues/294)) ([fd71049](https://github.com/orbcorp/orb-java/commit/fd7104918a50f62d44769d167cd3d0c665710c5e))
+* **client:** support raw response access ([#295](https://github.com/orbcorp/orb-java/issues/295)) ([70b0eb8](https://github.com/orbcorp/orb-java/commit/70b0eb8d409fdf3c4c1369d089c9c0f52f674268))
+
+
+### Chores
+
+* **client:** expose `Optional`, not nullable, from `ClientOptions` ([#299](https://github.com/orbcorp/orb-java/issues/299)) ([20f1914](https://github.com/orbcorp/orb-java/commit/20f191444e7d58a9ed38174f7a7f5ce027e39101))
+* **client:** refactor multipart formdata impl ([#296](https://github.com/orbcorp/orb-java/issues/296)) ([22e538b](https://github.com/orbcorp/orb-java/commit/22e538b1422b5bef07a22d0d84bf4a86dd77cea1))
+* **internal:** refactor `ErrorHandlingTest` ([#292](https://github.com/orbcorp/orb-java/issues/292)) ([d1ec6ff](https://github.com/orbcorp/orb-java/commit/d1ec6ff7570f4751c55862bd687009ff1f9e4b74))
+
+
+### Documentation
+
+* add raw response readme documentation ([#297](https://github.com/orbcorp/orb-java/issues/297)) ([648e2e6](https://github.com/orbcorp/orb-java/commit/648e2e6fe04d533a22fdbd730d84a39705f85561))
+* note required fields in `builder` javadoc ([#298](https://github.com/orbcorp/orb-java/issues/298)) ([1af73ac](https://github.com/orbcorp/orb-java/commit/1af73ac23511ae32f4c4c051c45e95384cbb7c25))
+
## 0.39.0 (2025-03-01)
Full Changelog: [v0.38.0...v0.39.0](https://github.com/orbcorp/orb-java/compare/v0.38.0...v0.39.0)
diff --git a/README.md b/README.md
index 7ee11951e..d2dd42fba 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
-[](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.39.0)
+[](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.40.0)
@@ -19,7 +19,7 @@ The REST API documentation can be found on [docs.withorb.com](https://docs.witho
### Gradle
```kotlin
-implementation("com.withorb.api:orb-java:0.39.0")
+implementation("com.withorb.api:orb-java:0.40.0")
```
### Maven
@@ -28,7 +28,7 @@ implementation("com.withorb.api:orb-java:0.39.0")
com.withorb.api
orb-java
- 0.39.0
+ 0.40.0
```
@@ -43,8 +43,8 @@ This library requires Java 8 or later.
```java
import com.withorb.api.client.OrbClient;
import com.withorb.api.client.okhttp.OrbOkHttpClient;
-import com.withorb.api.models.Customer;
import com.withorb.api.models.CustomerCreateParams;
+import com.withorb.api.models.CustomerModel;
// Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables
OrbClient client = OrbOkHttpClient.fromEnv();
@@ -53,7 +53,7 @@ CustomerCreateParams params = CustomerCreateParams.builder()
.email("example-customer@withorb.com")
.name("My Customer")
.build();
-Customer customer = client.customers().create(params);
+CustomerModel customerModel = client.customers().create(params);
```
## Client configuration
@@ -107,7 +107,7 @@ See this table for the available options:
To send a request to the Orb API, build an instance of some `Params` class and pass it to the corresponding client method. When the response is received, it will be deserialized into an instance of a Java class.
-For example, `client.customers().create(...)` should be called with an instance of `CustomerCreateParams`, and it will return an instance of `Customer`.
+For example, `client.customers().create(...)` should be called with an instance of `CustomerCreateParams`, and it will return an instance of `CustomerModel`.
## Immutability
@@ -124,8 +124,8 @@ The default client is synchronous. To switch to asynchronous execution, call the
```java
import com.withorb.api.client.OrbClient;
import com.withorb.api.client.okhttp.OrbOkHttpClient;
-import com.withorb.api.models.Customer;
import com.withorb.api.models.CustomerCreateParams;
+import com.withorb.api.models.CustomerModel;
import java.util.concurrent.CompletableFuture;
// Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables
@@ -135,7 +135,7 @@ CustomerCreateParams params = CustomerCreateParams.builder()
.email("example-customer@withorb.com")
.name("My Customer")
.build();
-CompletableFuture customer = client.async().customers().create(params);
+CompletableFuture customerModel = client.async().customers().create(params);
```
Or create an asynchronous client from the beginning:
@@ -143,8 +143,8 @@ Or create an asynchronous client from the beginning:
```java
import com.withorb.api.client.OrbClientAsync;
import com.withorb.api.client.okhttp.OrbOkHttpClientAsync;
-import com.withorb.api.models.Customer;
import com.withorb.api.models.CustomerCreateParams;
+import com.withorb.api.models.CustomerModel;
import java.util.concurrent.CompletableFuture;
// Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables
@@ -154,11 +154,41 @@ CustomerCreateParams params = CustomerCreateParams.builder()
.email("example-customer@withorb.com")
.name("My Customer")
.build();
-CompletableFuture customer = client.customers().create(params);
+CompletableFuture customerModel = client.customers().create(params);
```
The asynchronous client supports the same options as the synchronous one, except most methods return `CompletableFuture`s.
+## Raw responses
+
+The SDK defines methods that deserialize responses into instances of Java classes. However, these methods don't provide access to the response headers, status code, or the raw response body.
+
+To access this data, prefix any HTTP method call on a client or service with `withRawResponse()`:
+
+```java
+import com.withorb.api.core.http.Headers;
+import com.withorb.api.core.http.HttpResponseFor;
+import com.withorb.api.models.CustomerCreateParams;
+import com.withorb.api.models.CustomerModel;
+
+CustomerCreateParams params = CustomerCreateParams.builder()
+ .email("example-customer@withorb.com")
+ .name("My Customer")
+ .build();
+HttpResponseFor customerModel = client.customers().withRawResponse().create(params);
+
+int statusCode = customerModel.statusCode();
+Headers headers = customerModel.headers();
+```
+
+You can still deserialize the response into an instance of a Java class if needed:
+
+```java
+import com.withorb.api.models.CustomerModel;
+
+CustomerModel parsedCustomerModel = customerModel.parse();
+```
+
## Error handling
The SDK throws custom unchecked exception types:
@@ -193,12 +223,12 @@ To iterate through all results across all pages, you can use `autoPager`, which
### Synchronous
```java
-import com.withorb.api.models.Coupon;
import com.withorb.api.models.CouponListPage;
+import com.withorb.api.models.CouponModel;
// As an Iterable:
CouponListPage page = client.coupons().list(params);
-for (Coupon coupon : page.autoPager()) {
+for (CouponModel coupon : page.autoPager()) {
System.out.println(coupon);
};
@@ -221,12 +251,12 @@ asyncClient.coupons().list(params).autoPager()
If none of the above helpers meet your needs, you can also manually request pages one-by-one. A page of results has a `data()` method to fetch the list of objects, as well as top-level `response` and other methods to fetch top-level data about the page. It also has methods `hasNextPage`, `getNextPage`, and `getNextPageParams` methods to help with pagination.
```java
-import com.withorb.api.models.Coupon;
import com.withorb.api.models.CouponListPage;
+import com.withorb.api.models.CouponModel;
CouponListPage page = client.coupons().list(params);
while (page != null) {
- for (Coupon coupon : page.data()) {
+ for (CouponModel coupon : page.data()) {
System.out.println(coupon);
}
@@ -295,10 +325,10 @@ Requests time out after 1 minute by default.
To set a custom timeout, configure the method call using the `timeout` method:
```java
-import com.withorb.api.models.Customer;
import com.withorb.api.models.CustomerCreateParams;
+import com.withorb.api.models.CustomerModel;
-Customer customer = client.customers().create(
+CustomerModel customerModel = client.customers().create(
params, RequestOptions.builder().timeout(Duration.ofSeconds(30)).build()
);
```
@@ -432,18 +462,18 @@ By default, the SDK will not throw an exception in this case. It will throw [`Or
If you would prefer to check that the response is completely well-typed upfront, then either call `validate()`:
```java
-import com.withorb.api.models.Customer;
+import com.withorb.api.models.CustomerModel;
-Customer customer = client.customers().create(params).validate();
+CustomerModel customerModel = client.customers().create(params).validate();
```
Or configure the method call to validate the response using the `responseValidation` method:
```java
-import com.withorb.api.models.Customer;
import com.withorb.api.models.CustomerCreateParams;
+import com.withorb.api.models.CustomerModel;
-Customer customer = client.customers().create(
+CustomerModel customerModel = client.customers().create(
params, RequestOptions.builder().responseValidation(true).build()
);
```
diff --git a/build.gradle.kts b/build.gradle.kts
index 0300a4717..d0b92cf0d 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,4 +1,4 @@
allprojects {
group = "com.withorb.api"
- version = "0.39.0" // x-release-please-version
+ version = "0.40.0" // x-release-please-version
}
diff --git a/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OkHttpClient.kt b/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OkHttpClient.kt
index 7cdd0e026..655da4e8b 100644
--- a/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OkHttpClient.kt
+++ b/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OkHttpClient.kt
@@ -1,6 +1,7 @@
package com.withorb.api.client.okhttp
import com.withorb.api.core.RequestOptions
+import com.withorb.api.core.Timeout
import com.withorb.api.core.checkRequired
import com.withorb.api.core.http.Headers
import com.withorb.api.core.http.HttpClient
@@ -88,13 +89,12 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
)
}
- val timeout = requestOptions.timeout
- if (timeout != null) {
+ requestOptions.timeout?.let {
clientBuilder
- .connectTimeout(timeout)
- .readTimeout(timeout)
- .writeTimeout(timeout)
- .callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
+ .connectTimeout(it.connect())
+ .readTimeout(it.read())
+ .writeTimeout(it.write())
+ .callTimeout(it.request())
}
val client = clientBuilder.build()
@@ -195,23 +195,24 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
class Builder internal constructor() {
private var baseUrl: HttpUrl? = null
- // The default timeout is 1 minute.
- private var timeout: Duration = Duration.ofSeconds(60)
+ private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl.toHttpUrl() }
- fun timeout(timeout: Duration) = apply { this.timeout = timeout }
+ fun timeout(timeout: Timeout) = apply { this.timeout = timeout }
+
+ fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
fun build(): OkHttpClient =
OkHttpClient(
okhttp3.OkHttpClient.Builder()
- .connectTimeout(timeout)
- .readTimeout(timeout)
- .writeTimeout(timeout)
- .callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
+ .connectTimeout(timeout.connect())
+ .readTimeout(timeout.read())
+ .writeTimeout(timeout.write())
+ .callTimeout(timeout.request())
.proxy(proxy)
.build(),
checkRequired("baseUrl", baseUrl),
diff --git a/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt b/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt
index 442c58242..ba060e8a7 100644
--- a/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt
+++ b/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper
import com.withorb.api.client.OrbClient
import com.withorb.api.client.OrbClientImpl
import com.withorb.api.core.ClientOptions
+import com.withorb.api.core.Timeout
import com.withorb.api.core.http.Headers
import com.withorb.api.core.http.QueryParams
import java.net.Proxy
@@ -17,6 +18,7 @@ class OrbOkHttpClient private constructor() {
companion object {
+ /** Returns a mutable builder for constructing an instance of [OrbOkHttpClient]. */
@JvmStatic fun builder() = Builder()
@JvmStatic fun fromEnv(): OrbClient = builder().fromEnv().build()
@@ -27,8 +29,7 @@ class OrbOkHttpClient private constructor() {
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
private var baseUrl: String = ClientOptions.PRODUCTION_URL
- // The default timeout for the client is 1 minute.
- private var timeout: Duration = Duration.ofSeconds(60)
+ private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
fun baseUrl(baseUrl: String) = apply {
@@ -120,7 +121,19 @@ class OrbOkHttpClient private constructor() {
clientOptions.removeAllQueryParams(keys)
}
- fun timeout(timeout: Duration) = apply { this.timeout = timeout }
+ fun timeout(timeout: Timeout) = apply {
+ clientOptions.timeout(timeout)
+ this.timeout = timeout
+ }
+
+ /**
+ * Sets the maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * See [Timeout.request] for more details.
+ *
+ * For fine-grained control, pass a [Timeout] object.
+ */
+ fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
diff --git a/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt b/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt
index 3c9e6f228..b8ec34517 100644
--- a/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt
+++ b/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper
import com.withorb.api.client.OrbClientAsync
import com.withorb.api.client.OrbClientAsyncImpl
import com.withorb.api.core.ClientOptions
+import com.withorb.api.core.Timeout
import com.withorb.api.core.http.Headers
import com.withorb.api.core.http.QueryParams
import java.net.Proxy
@@ -17,6 +18,7 @@ class OrbOkHttpClientAsync private constructor() {
companion object {
+ /** Returns a mutable builder for constructing an instance of [OrbOkHttpClientAsync]. */
@JvmStatic fun builder() = Builder()
@JvmStatic fun fromEnv(): OrbClientAsync = builder().fromEnv().build()
@@ -27,8 +29,7 @@ class OrbOkHttpClientAsync private constructor() {
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
private var baseUrl: String = ClientOptions.PRODUCTION_URL
- // The default timeout for the client is 1 minute.
- private var timeout: Duration = Duration.ofSeconds(60)
+ private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
fun baseUrl(baseUrl: String) = apply {
@@ -120,7 +121,19 @@ class OrbOkHttpClientAsync private constructor() {
clientOptions.removeAllQueryParams(keys)
}
- fun timeout(timeout: Duration) = apply { this.timeout = timeout }
+ fun timeout(timeout: Timeout) = apply {
+ clientOptions.timeout(timeout)
+ this.timeout = timeout
+ }
+
+ /**
+ * Sets the maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * See [Timeout.request] for more details.
+ *
+ * For fine-grained control, pass a [Timeout] object.
+ */
+ fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
diff --git a/orb-java-core/build.gradle.kts b/orb-java-core/build.gradle.kts
index 8d8043759..b53bd811e 100644
--- a/orb-java-core/build.gradle.kts
+++ b/orb-java-core/build.gradle.kts
@@ -6,6 +6,7 @@ plugins {
dependencies {
api("com.fasterxml.jackson.core:jackson-core:2.18.1")
api("com.fasterxml.jackson.core:jackson-databind:2.18.1")
+ api("com.google.errorprone:error_prone_annotations:2.33.0")
implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.1")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.1")
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClient.kt b/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClient.kt
index b256deff2..a35901a57 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClient.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClient.kt
@@ -42,6 +42,11 @@ interface OrbClient {
*/
fun async(): OrbClientAsync
+ /**
+ * Returns a view of this service that provides access to raw HTTP responses for each method.
+ */
+ fun withRawResponse(): WithRawResponse
+
fun topLevel(): TopLevelService
fun coupons(): CouponService
@@ -84,4 +89,36 @@ interface OrbClient {
* method.
*/
fun close()
+
+ /** A view of [OrbClient] that provides access to raw HTTP responses for each method. */
+ interface WithRawResponse {
+
+ fun topLevel(): TopLevelService.WithRawResponse
+
+ fun coupons(): CouponService.WithRawResponse
+
+ fun creditNotes(): CreditNoteService.WithRawResponse
+
+ fun customers(): CustomerService.WithRawResponse
+
+ fun events(): EventService.WithRawResponse
+
+ fun invoiceLineItems(): InvoiceLineItemService.WithRawResponse
+
+ fun invoices(): InvoiceService.WithRawResponse
+
+ fun items(): ItemService.WithRawResponse
+
+ fun metrics(): MetricService.WithRawResponse
+
+ fun plans(): PlanService.WithRawResponse
+
+ fun prices(): PriceService.WithRawResponse
+
+ fun subscriptions(): SubscriptionService.WithRawResponse
+
+ fun alerts(): AlertService.WithRawResponse
+
+ fun dimensionalPriceGroups(): DimensionalPriceGroupService.WithRawResponse
+ }
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsync.kt
index 61f2d9d71..20b04b5ce 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsync.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsync.kt
@@ -41,6 +41,11 @@ interface OrbClientAsync {
*/
fun sync(): OrbClient
+ /**
+ * Returns a view of this service that provides access to raw HTTP responses for each method.
+ */
+ fun withRawResponse(): WithRawResponse
+
fun topLevel(): TopLevelServiceAsync
fun coupons(): CouponServiceAsync
@@ -81,4 +86,36 @@ interface OrbClientAsync {
* method.
*/
fun close()
+
+ /** A view of [OrbClientAsync] that provides access to raw HTTP responses for each method. */
+ interface WithRawResponse {
+
+ fun topLevel(): TopLevelServiceAsync.WithRawResponse
+
+ fun coupons(): CouponServiceAsync.WithRawResponse
+
+ fun creditNotes(): CreditNoteServiceAsync.WithRawResponse
+
+ fun customers(): CustomerServiceAsync.WithRawResponse
+
+ fun events(): EventServiceAsync.WithRawResponse
+
+ fun invoiceLineItems(): InvoiceLineItemServiceAsync.WithRawResponse
+
+ fun invoices(): InvoiceServiceAsync.WithRawResponse
+
+ fun items(): ItemServiceAsync.WithRawResponse
+
+ fun metrics(): MetricServiceAsync.WithRawResponse
+
+ fun plans(): PlanServiceAsync.WithRawResponse
+
+ fun prices(): PriceServiceAsync.WithRawResponse
+
+ fun subscriptions(): SubscriptionServiceAsync.WithRawResponse
+
+ fun alerts(): AlertServiceAsync.WithRawResponse
+
+ fun dimensionalPriceGroups(): DimensionalPriceGroupServiceAsync.WithRawResponse
+ }
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt
index 6f8eadd5e..c74456d9b 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientAsyncImpl.kt
@@ -46,6 +46,10 @@ class OrbClientAsyncImpl(private val clientOptions: ClientOptions) : OrbClientAs
// Pass the original clientOptions so that this client sets its own User-Agent.
private val sync: OrbClient by lazy { OrbClientImpl(clientOptions) }
+ private val withRawResponse: OrbClientAsync.WithRawResponse by lazy {
+ WithRawResponseImpl(clientOptions)
+ }
+
private val topLevel: TopLevelServiceAsync by lazy {
TopLevelServiceAsyncImpl(clientOptionsWithUserAgent)
}
@@ -100,6 +104,8 @@ class OrbClientAsyncImpl(private val clientOptions: ClientOptions) : OrbClientAs
override fun sync(): OrbClient = sync
+ override fun withRawResponse(): OrbClientAsync.WithRawResponse = withRawResponse
+
override fun topLevel(): TopLevelServiceAsync = topLevel
override fun coupons(): CouponServiceAsync = coupons
@@ -130,4 +136,95 @@ class OrbClientAsyncImpl(private val clientOptions: ClientOptions) : OrbClientAs
dimensionalPriceGroups
override fun close() = clientOptions.httpClient.close()
+
+ class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
+ OrbClientAsync.WithRawResponse {
+
+ private val topLevel: TopLevelServiceAsync.WithRawResponse by lazy {
+ TopLevelServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val coupons: CouponServiceAsync.WithRawResponse by lazy {
+ CouponServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val creditNotes: CreditNoteServiceAsync.WithRawResponse by lazy {
+ CreditNoteServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val customers: CustomerServiceAsync.WithRawResponse by lazy {
+ CustomerServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val events: EventServiceAsync.WithRawResponse by lazy {
+ EventServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val invoiceLineItems: InvoiceLineItemServiceAsync.WithRawResponse by lazy {
+ InvoiceLineItemServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val invoices: InvoiceServiceAsync.WithRawResponse by lazy {
+ InvoiceServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val items: ItemServiceAsync.WithRawResponse by lazy {
+ ItemServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val metrics: MetricServiceAsync.WithRawResponse by lazy {
+ MetricServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val plans: PlanServiceAsync.WithRawResponse by lazy {
+ PlanServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val prices: PriceServiceAsync.WithRawResponse by lazy {
+ PriceServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val subscriptions: SubscriptionServiceAsync.WithRawResponse by lazy {
+ SubscriptionServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val alerts: AlertServiceAsync.WithRawResponse by lazy {
+ AlertServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val dimensionalPriceGroups:
+ DimensionalPriceGroupServiceAsync.WithRawResponse by lazy {
+ DimensionalPriceGroupServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ override fun topLevel(): TopLevelServiceAsync.WithRawResponse = topLevel
+
+ override fun coupons(): CouponServiceAsync.WithRawResponse = coupons
+
+ override fun creditNotes(): CreditNoteServiceAsync.WithRawResponse = creditNotes
+
+ override fun customers(): CustomerServiceAsync.WithRawResponse = customers
+
+ override fun events(): EventServiceAsync.WithRawResponse = events
+
+ override fun invoiceLineItems(): InvoiceLineItemServiceAsync.WithRawResponse =
+ invoiceLineItems
+
+ override fun invoices(): InvoiceServiceAsync.WithRawResponse = invoices
+
+ override fun items(): ItemServiceAsync.WithRawResponse = items
+
+ override fun metrics(): MetricServiceAsync.WithRawResponse = metrics
+
+ override fun plans(): PlanServiceAsync.WithRawResponse = plans
+
+ override fun prices(): PriceServiceAsync.WithRawResponse = prices
+
+ override fun subscriptions(): SubscriptionServiceAsync.WithRawResponse = subscriptions
+
+ override fun alerts(): AlertServiceAsync.WithRawResponse = alerts
+
+ override fun dimensionalPriceGroups(): DimensionalPriceGroupServiceAsync.WithRawResponse =
+ dimensionalPriceGroups
+ }
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt
index 46d45ebf7..1c5d79f42 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/client/OrbClientImpl.kt
@@ -48,6 +48,10 @@ class OrbClientImpl(private val clientOptions: ClientOptions) : OrbClient {
// Pass the original clientOptions so that this client sets its own User-Agent.
private val async: OrbClientAsync by lazy { OrbClientAsyncImpl(clientOptions) }
+ private val withRawResponse: OrbClient.WithRawResponse by lazy {
+ WithRawResponseImpl(clientOptions)
+ }
+
private val topLevel: TopLevelService by lazy {
TopLevelServiceImpl(clientOptionsWithUserAgent)
}
@@ -92,6 +96,8 @@ class OrbClientImpl(private val clientOptions: ClientOptions) : OrbClient {
override fun async(): OrbClientAsync = async
+ override fun withRawResponse(): OrbClient.WithRawResponse = withRawResponse
+
override fun topLevel(): TopLevelService = topLevel
override fun coupons(): CouponService = coupons
@@ -123,4 +129,93 @@ class OrbClientImpl(private val clientOptions: ClientOptions) : OrbClient {
override fun dimensionalPriceGroups(): DimensionalPriceGroupService = dimensionalPriceGroups
override fun close() = clientOptions.httpClient.close()
+
+ class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
+ OrbClient.WithRawResponse {
+
+ private val topLevel: TopLevelService.WithRawResponse by lazy {
+ TopLevelServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val coupons: CouponService.WithRawResponse by lazy {
+ CouponServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val creditNotes: CreditNoteService.WithRawResponse by lazy {
+ CreditNoteServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val customers: CustomerService.WithRawResponse by lazy {
+ CustomerServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val events: EventService.WithRawResponse by lazy {
+ EventServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val invoiceLineItems: InvoiceLineItemService.WithRawResponse by lazy {
+ InvoiceLineItemServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val invoices: InvoiceService.WithRawResponse by lazy {
+ InvoiceServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val items: ItemService.WithRawResponse by lazy {
+ ItemServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val metrics: MetricService.WithRawResponse by lazy {
+ MetricServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val plans: PlanService.WithRawResponse by lazy {
+ PlanServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val prices: PriceService.WithRawResponse by lazy {
+ PriceServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val subscriptions: SubscriptionService.WithRawResponse by lazy {
+ SubscriptionServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val alerts: AlertService.WithRawResponse by lazy {
+ AlertServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val dimensionalPriceGroups: DimensionalPriceGroupService.WithRawResponse by lazy {
+ DimensionalPriceGroupServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ override fun topLevel(): TopLevelService.WithRawResponse = topLevel
+
+ override fun coupons(): CouponService.WithRawResponse = coupons
+
+ override fun creditNotes(): CreditNoteService.WithRawResponse = creditNotes
+
+ override fun customers(): CustomerService.WithRawResponse = customers
+
+ override fun events(): EventService.WithRawResponse = events
+
+ override fun invoiceLineItems(): InvoiceLineItemService.WithRawResponse = invoiceLineItems
+
+ override fun invoices(): InvoiceService.WithRawResponse = invoices
+
+ override fun items(): ItemService.WithRawResponse = items
+
+ override fun metrics(): MetricService.WithRawResponse = metrics
+
+ override fun plans(): PlanService.WithRawResponse = plans
+
+ override fun prices(): PriceService.WithRawResponse = prices
+
+ override fun subscriptions(): SubscriptionService.WithRawResponse = subscriptions
+
+ override fun alerts(): AlertService.WithRawResponse = alerts
+
+ override fun dimensionalPriceGroups(): DimensionalPriceGroupService.WithRawResponse =
+ dimensionalPriceGroups
+ }
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/Check.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/Check.kt
index 561abe1d9..4a68492fc 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/core/Check.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/core/Check.kt
@@ -5,6 +5,18 @@ package com.withorb.api.core
fun checkRequired(name: String, value: T?): T =
checkNotNull(value) { "`$name` is required, but was not set" }
+@JvmSynthetic
+internal fun checkKnown(name: String, value: JsonField): T =
+ value.asKnown().orElseThrow {
+ IllegalStateException("`$name` is not a known type: ${value.javaClass.simpleName}")
+ }
+
+@JvmSynthetic
+internal fun checkKnown(name: String, value: MultipartField): T =
+ value.value.asKnown().orElseThrow {
+ IllegalStateException("`$name` is not a known type: ${value.javaClass.simpleName}")
+ }
+
@JvmSynthetic
internal fun checkLength(name: String, value: String, length: Int): String =
value.also {
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt
index 796f695d9..2c3ce89b9 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt
@@ -21,17 +21,29 @@ private constructor(
@get:JvmName("headers") val headers: Headers,
@get:JvmName("queryParams") val queryParams: QueryParams,
@get:JvmName("responseValidation") val responseValidation: Boolean,
+ @get:JvmName("timeout") val timeout: Timeout,
@get:JvmName("maxRetries") val maxRetries: Int,
@get:JvmName("apiKey") val apiKey: String,
- @get:JvmName("webhookSecret") val webhookSecret: String?,
+ private val webhookSecret: String?,
) {
+ fun webhookSecret(): Optional = Optional.ofNullable(webhookSecret)
+
fun toBuilder() = Builder().from(this)
companion object {
const val PRODUCTION_URL = "https://api.withorb.com/v1"
+ /**
+ * Returns a mutable builder for constructing an instance of [ClientOptions].
+ *
+ * The following fields are required:
+ * ```java
+ * .httpClient()
+ * .apiKey()
+ * ```
+ */
@JvmStatic fun builder() = Builder()
@JvmStatic fun fromEnv(): ClientOptions = builder().fromEnv().build()
@@ -47,6 +59,7 @@ private constructor(
private var headers: Headers.Builder = Headers.builder()
private var queryParams: QueryParams.Builder = QueryParams.builder()
private var responseValidation: Boolean = false
+ private var timeout: Timeout = Timeout.default()
private var maxRetries: Int = 2
private var apiKey: String? = null
private var webhookSecret: String? = null
@@ -60,6 +73,7 @@ private constructor(
headers = clientOptions.headers.toBuilder()
queryParams = clientOptions.queryParams.toBuilder()
responseValidation = clientOptions.responseValidation
+ timeout = clientOptions.timeout
maxRetries = clientOptions.maxRetries
apiKey = clientOptions.apiKey
webhookSecret = clientOptions.webhookSecret
@@ -77,6 +91,8 @@ private constructor(
this.responseValidation = responseValidation
}
+ fun timeout(timeout: Timeout) = apply { this.timeout = timeout }
+
fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries }
fun apiKey(apiKey: String) = apply { this.apiKey = apiKey }
@@ -208,6 +224,7 @@ private constructor(
headers.build(),
queryParams.build(),
responseValidation,
+ timeout,
maxRetries,
apiKey,
webhookSecret,
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/HttpRequestBodies.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/HttpRequestBodies.kt
deleted file mode 100644
index 020e86467..000000000
--- a/orb-java-core/src/main/kotlin/com/withorb/api/core/HttpRequestBodies.kt
+++ /dev/null
@@ -1,108 +0,0 @@
-@file:JvmName("HttpRequestBodies")
-
-package com.withorb.api.core
-
-import com.fasterxml.jackson.databind.json.JsonMapper
-import com.withorb.api.core.http.HttpRequestBody
-import com.withorb.api.errors.OrbException
-import java.io.ByteArrayOutputStream
-import java.io.OutputStream
-import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder
-
-@JvmSynthetic
-internal inline fun json(jsonMapper: JsonMapper, value: T): HttpRequestBody {
- return object : HttpRequestBody {
- private var cachedBytes: ByteArray? = null
-
- private fun serialize(): ByteArray {
- if (cachedBytes != null) return cachedBytes!!
-
- val buffer = ByteArrayOutputStream()
- try {
- jsonMapper.writeValue(buffer, value)
- cachedBytes = buffer.toByteArray()
- return cachedBytes!!
- } catch (e: Exception) {
- throw OrbException("Error writing request", e)
- }
- }
-
- override fun writeTo(outputStream: OutputStream) {
- outputStream.write(serialize())
- }
-
- override fun contentType(): String = "application/json"
-
- override fun contentLength(): Long {
- return serialize().size.toLong()
- }
-
- override fun repeatable(): Boolean = true
-
- override fun close() {}
- }
-}
-
-@JvmSynthetic
-internal fun multipartFormData(
- jsonMapper: JsonMapper,
- parts: Array?>,
-): HttpRequestBody {
- val builder = MultipartEntityBuilder.create()
- parts.forEach { part ->
- if (part?.value != null) {
- when (part.value) {
- is JsonValue -> {
- val buffer = ByteArrayOutputStream()
- try {
- jsonMapper.writeValue(buffer, part.value)
- } catch (e: Exception) {
- throw OrbException("Error serializing value to json", e)
- }
- builder.addBinaryBody(
- part.name,
- buffer.toByteArray(),
- part.contentType,
- part.filename,
- )
- }
- is Boolean ->
- builder.addTextBody(
- part.name,
- if (part.value) "true" else "false",
- part.contentType,
- )
- is Int -> builder.addTextBody(part.name, part.value.toString(), part.contentType)
- is Long -> builder.addTextBody(part.name, part.value.toString(), part.contentType)
- is Double -> builder.addTextBody(part.name, part.value.toString(), part.contentType)
- is ByteArray ->
- builder.addBinaryBody(part.name, part.value, part.contentType, part.filename)
- is String -> builder.addTextBody(part.name, part.value, part.contentType)
- is Enum -> builder.addTextBody(part.name, part.value.toString(), part.contentType)
- else ->
- throw IllegalArgumentException(
- "Unsupported content type: ${part.value::class.java.simpleName}"
- )
- }
- }
- }
- val entity = builder.build()
-
- return object : HttpRequestBody {
- override fun writeTo(outputStream: OutputStream) {
- try {
- return entity.writeTo(outputStream)
- } catch (e: Exception) {
- throw OrbException("Error writing request", e)
- }
- }
-
- override fun contentType(): String = entity.contentType
-
- override fun contentLength(): Long = -1
-
- override fun repeatable(): Boolean = entity.isRepeatable
-
- override fun close() = entity.close()
- }
-}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/RequestOptions.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/RequestOptions.kt
index c1c6b76bd..1f3b64291 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/core/RequestOptions.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/core/RequestOptions.kt
@@ -2,13 +2,7 @@ package com.withorb.api.core
import java.time.Duration
-class RequestOptions private constructor(val responseValidation: Boolean?, val timeout: Duration?) {
- fun applyDefaults(options: RequestOptions): RequestOptions {
- return RequestOptions(
- responseValidation = this.responseValidation ?: options.responseValidation,
- timeout = this.timeout ?: options.timeout,
- )
- }
+class RequestOptions private constructor(val responseValidation: Boolean?, val timeout: Timeout?) {
companion object {
@@ -16,22 +10,37 @@ class RequestOptions private constructor(val responseValidation: Boolean?, val t
@JvmStatic fun none() = NONE
+ @JvmSynthetic
+ internal fun from(clientOptions: ClientOptions): RequestOptions =
+ builder()
+ .responseValidation(clientOptions.responseValidation)
+ .timeout(clientOptions.timeout)
+ .build()
+
@JvmStatic fun builder() = Builder()
}
+ fun applyDefaults(options: RequestOptions): RequestOptions =
+ RequestOptions(
+ responseValidation = responseValidation ?: options.responseValidation,
+ timeout =
+ if (options.timeout != null && timeout != null) timeout.assign(options.timeout)
+ else timeout ?: options.timeout,
+ )
+
class Builder internal constructor() {
private var responseValidation: Boolean? = null
- private var timeout: Duration? = null
+ private var timeout: Timeout? = null
fun responseValidation(responseValidation: Boolean) = apply {
this.responseValidation = responseValidation
}
- fun timeout(timeout: Duration) = apply { this.timeout = timeout }
+ fun timeout(timeout: Timeout) = apply { this.timeout = timeout }
- fun build(): RequestOptions {
- return RequestOptions(responseValidation, timeout)
- }
+ fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
+
+ fun build(): RequestOptions = RequestOptions(responseValidation, timeout)
}
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/Timeout.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/Timeout.kt
new file mode 100644
index 000000000..65438bf43
--- /dev/null
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/core/Timeout.kt
@@ -0,0 +1,188 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.withorb.api.core
+
+import java.time.Duration
+import java.util.Objects
+import java.util.Optional
+
+/** A class containing timeouts for various processing phases of a request. */
+class Timeout
+private constructor(
+ private val connect: Duration?,
+ private val read: Duration?,
+ private val write: Duration?,
+ private val request: Duration?,
+) {
+
+ /**
+ * The maximum time allowed to establish a connection with a host.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun connect(): Duration = connect ?: Duration.ofMinutes(1)
+
+ /**
+ * The maximum time allowed between two data packets when waiting for the server’s response.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun read(): Duration = read ?: request()
+
+ /**
+ * The maximum time allowed between two data packets when sending the request to the server.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun write(): Duration = write ?: request()
+
+ /**
+ * The maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * This includes resolving DNS, connecting, writing the request body, server processing, as well
+ * as reading the response body.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun request(): Duration = request ?: Duration.ofMinutes(1)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ @JvmStatic fun default() = builder().build()
+
+ /** Returns a mutable builder for constructing an instance of [Timeout]. */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Timeout]. */
+ class Builder internal constructor() {
+
+ private var connect: Duration? = null
+ private var read: Duration? = null
+ private var write: Duration? = null
+ private var request: Duration? = null
+
+ @JvmSynthetic
+ internal fun from(timeout: Timeout) = apply {
+ connect = timeout.connect
+ read = timeout.read
+ write = timeout.write
+ request = timeout.request
+ }
+
+ /**
+ * The maximum time allowed to establish a connection with a host.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun connect(connect: Duration?) = apply { this.connect = connect }
+
+ /**
+ * The maximum time allowed to establish a connection with a host.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun connect(connect: Optional) = connect(connect.orElse(null))
+
+ /**
+ * The maximum time allowed between two data packets when waiting for the server’s response.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun read(read: Duration?) = apply { this.read = read }
+
+ /**
+ * The maximum time allowed between two data packets when waiting for the server’s response.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun read(read: Optional) = read(read.orElse(null))
+
+ /**
+ * The maximum time allowed between two data packets when sending the request to the server.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun write(write: Duration?) = apply { this.write = write }
+
+ /**
+ * The maximum time allowed between two data packets when sending the request to the server.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun write(write: Optional) = write(write.orElse(null))
+
+ /**
+ * The maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * This includes resolving DNS, connecting, writing the request body, server processing, as
+ * well as reading the response body.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun request(request: Duration?) = apply { this.request = request }
+
+ /**
+ * The maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * This includes resolving DNS, connecting, writing the request body, server processing, as
+ * well as reading the response body.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun request(request: Optional) = request(request.orElse(null))
+
+ fun build(): Timeout = Timeout(connect, read, write, request)
+ }
+
+ @JvmSynthetic
+ internal fun assign(target: Timeout): Timeout =
+ target
+ .toBuilder()
+ .apply {
+ connect?.let(this::connect)
+ read?.let(this::read)
+ write?.let(this::write)
+ request?.let(this::request)
+ }
+ .build()
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is Timeout && connect == other.connect && read == other.read && write == other.write && request == other.request /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(connect, read, write, request) /* spotless:on */
+
+ override fun toString() =
+ "Timeout{connect=$connect, read=$read, write=$write, request=$request}"
+}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/Values.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/Values.kt
index 8f2344cb9..79149391d 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/core/Values.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/core/Values.kt
@@ -27,10 +27,8 @@ import com.fasterxml.jackson.databind.node.JsonNodeType.POJO
import com.fasterxml.jackson.databind.node.JsonNodeType.STRING
import com.fasterxml.jackson.databind.ser.std.NullSerializer
import com.withorb.api.errors.OrbInvalidDataException
-import java.nio.charset.Charset
import java.util.Objects
import java.util.Optional
-import org.apache.hc.core5.http.ContentType
@JsonDeserialize(using = JsonField.Deserializer::class)
sealed class JsonField {
@@ -287,12 +285,12 @@ private constructor(
return true
}
- return other is KnownValue<*> && value == other.value
+ return other is KnownValue<*> && value contentEquals other.value
}
- override fun hashCode() = value.hashCode()
+ override fun hashCode() = contentHash(value)
- override fun toString() = value.toString()
+ override fun toString() = value.contentToString()
companion object {
@JsonCreator @JvmStatic fun of(value: T) = KnownValue(value)
@@ -462,15 +460,63 @@ annotation class ExcludeMissing
)
annotation class NoAutoDetect
-class MultipartFormValue
-internal constructor(
- val name: String,
- val value: T,
- val contentType: ContentType,
- val filename: String? = null,
+class MultipartField
+private constructor(
+ @get:JvmName("value") val value: JsonField,
+ @get:JvmName("contentType") val contentType: String,
+ private val filename: String?,
) {
- private val hashCode: Int by lazy { contentHash(name, value, contentType, filename) }
+ companion object {
+
+ @JvmStatic fun of(value: T?) = builder().value(value).build()
+
+ @JvmStatic fun of(value: JsonField) = builder().value(value).build()
+
+ @JvmStatic fun builder() = Builder()
+ }
+
+ fun filename(): Optional = Optional.ofNullable(filename)
+
+ @JvmSynthetic
+ internal fun map(transform: (T) -> R): MultipartField =
+ MultipartField.builder()
+ .value(value.map(transform))
+ .contentType(contentType)
+ .filename(filename)
+ .build()
+
+ /** A builder for [MultipartField]. */
+ class Builder internal constructor() {
+
+ private var value: JsonField? = null
+ private var contentType: String? = null
+ private var filename: String? = null
+
+ fun value(value: JsonField) = apply { this.value = value }
+
+ fun value(value: T?) = value(JsonField.ofNullable(value))
+
+ fun contentType(contentType: String) = apply { this.contentType = contentType }
+
+ fun filename(filename: String?) = apply { this.filename = filename }
+
+ fun filename(filename: Optional) = filename(filename.orElse(null))
+
+ fun build(): MultipartField {
+ val value = checkRequired("value", value)
+ return MultipartField(
+ value,
+ contentType
+ ?: if (value is KnownValue && value.value is ByteArray)
+ "application/octet-stream"
+ else "text/plain; charset=utf-8",
+ filename,
+ )
+ }
+ }
+
+ private val hashCode: Int by lazy { contentHash(value, contentType, filename) }
override fun hashCode(): Int = hashCode
@@ -479,63 +525,12 @@ internal constructor(
return true
}
- return other is MultipartFormValue<*> &&
- name == other.name &&
- value contentEquals other.value &&
+ return other is MultipartField<*> &&
+ value == other.value &&
contentType == other.contentType &&
filename == other.filename
}
override fun toString(): String =
- "MultipartFormValue{name=$name, contentType=$contentType, filename=$filename, value=${valueToString()}}"
-
- private fun valueToString(): String =
- when (value) {
- is ByteArray -> "ByteArray of size ${value.size}"
- else -> value.toString()
- }
-
- companion object {
- internal fun fromString(
- name: String,
- value: String,
- contentType: ContentType,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType)
-
- internal fun fromBoolean(
- name: String,
- value: Boolean,
- contentType: ContentType,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType)
-
- internal fun fromLong(
- name: String,
- value: Long,
- contentType: ContentType,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType)
-
- internal fun fromDouble(
- name: String,
- value: Double,
- contentType: ContentType,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType)
-
- internal fun fromEnum(
- name: String,
- value: T,
- contentType: ContentType,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType)
-
- internal fun fromByteArray(
- name: String,
- value: ByteArray,
- contentType: ContentType,
- filename: String? = null,
- ): MultipartFormValue = MultipartFormValue(name, value, contentType, filename)
- }
-}
-
-internal object ContentTypes {
- val DefaultText = ContentType.create(ContentType.TEXT_PLAIN.mimeType, Charset.forName("UTF-8"))
- val DefaultBinary = ContentType.DEFAULT_BINARY
+ "MultipartField{value=$value, contentType=$contentType, filename=$filename}"
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/http/HttpRequestBodies.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/http/HttpRequestBodies.kt
new file mode 100644
index 000000000..e49836bd4
--- /dev/null
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/core/http/HttpRequestBodies.kt
@@ -0,0 +1,89 @@
+// File generated from our OpenAPI spec by Stainless.
+
+@file:JvmName("HttpRequestBodies")
+
+package com.withorb.api.core.http
+
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.json.JsonMapper
+import com.fasterxml.jackson.databind.node.JsonNodeType
+import com.withorb.api.core.MultipartField
+import com.withorb.api.errors.OrbInvalidDataException
+import java.io.OutputStream
+import kotlin.jvm.optionals.getOrNull
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder
+import org.apache.hc.core5.http.ContentType
+import org.apache.hc.core5.http.HttpEntity
+
+@JvmSynthetic
+internal inline fun json(jsonMapper: JsonMapper, value: T): HttpRequestBody =
+ object : HttpRequestBody {
+ private val bytes: ByteArray by lazy { jsonMapper.writeValueAsBytes(value) }
+
+ override fun writeTo(outputStream: OutputStream) = outputStream.write(bytes)
+
+ override fun contentType(): String = "application/json"
+
+ override fun contentLength(): Long = bytes.size.toLong()
+
+ override fun repeatable(): Boolean = true
+
+ override fun close() {}
+ }
+
+@JvmSynthetic
+internal fun multipartFormData(
+ jsonMapper: JsonMapper,
+ fields: Map>,
+): HttpRequestBody =
+ object : HttpRequestBody {
+ private val entity: HttpEntity by lazy {
+ MultipartEntityBuilder.create()
+ .apply {
+ fields.forEach { (name, field) ->
+ val node = jsonMapper.valueToTree(field.value)
+ serializePart(name, node).forEach { (name, bytes) ->
+ addBinaryBody(
+ name,
+ bytes,
+ ContentType.parseLenient(field.contentType),
+ field.filename().getOrNull(),
+ )
+ }
+ }
+ }
+ .build()
+ }
+
+ private fun serializePart(name: String, node: JsonNode): Sequence> =
+ when (node.nodeType) {
+ JsonNodeType.MISSING,
+ JsonNodeType.NULL -> emptySequence()
+ JsonNodeType.BINARY -> sequenceOf(name to node.binaryValue())
+ JsonNodeType.STRING -> sequenceOf(name to node.textValue().toByteArray())
+ JsonNodeType.BOOLEAN ->
+ sequenceOf(name to node.booleanValue().toString().toByteArray())
+ JsonNodeType.NUMBER ->
+ sequenceOf(name to node.numberValue().toString().toByteArray())
+ JsonNodeType.ARRAY ->
+ node.elements().asSequence().flatMap { element ->
+ serializePart("$name[]", element)
+ }
+ JsonNodeType.OBJECT ->
+ node.fields().asSequence().flatMap { (key, value) ->
+ serializePart("$name[$key]", value)
+ }
+ JsonNodeType.POJO,
+ null -> throw OrbInvalidDataException("Unexpected JsonNode type: ${node.nodeType}")
+ }
+
+ override fun writeTo(outputStream: OutputStream) = entity.writeTo(outputStream)
+
+ override fun contentType(): String = entity.contentType
+
+ override fun contentLength(): Long = entity.contentLength
+
+ override fun repeatable(): Boolean = entity.isRepeatable
+
+ override fun close() = entity.close()
+ }
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/http/HttpResponseFor.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/http/HttpResponseFor.kt
new file mode 100644
index 000000000..0f8e55198
--- /dev/null
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/core/http/HttpResponseFor.kt
@@ -0,0 +1,23 @@
+package com.withorb.api.core.http
+
+import java.io.InputStream
+
+interface HttpResponseFor : HttpResponse {
+
+ fun parse(): T
+}
+
+@JvmSynthetic
+internal fun HttpResponse.parseable(parse: () -> T): HttpResponseFor =
+ object : HttpResponseFor {
+
+ override fun parse(): T = parse()
+
+ override fun statusCode(): Int = this@parseable.statusCode()
+
+ override fun headers(): Headers = this@parseable.headers()
+
+ override fun body(): InputStream = this@parseable.body()
+
+ override fun close() = this@parseable.close()
+ }
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/errors/OrbError.kt b/orb-java-core/src/main/kotlin/com/withorb/api/errors/OrbError.kt
index 2479f3e03..7860890be 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/errors/OrbError.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/errors/OrbError.kt
@@ -27,6 +27,7 @@ private constructor(
companion object {
+ /** Returns a mutable builder for constructing an instance of [OrbError]. */
@JvmStatic fun builder() = Builder()
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AddCreditLedgerEntryRequest.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AddCreditLedgerEntryRequest.kt
new file mode 100644
index 000000000..a534f8e0c
--- /dev/null
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AddCreditLedgerEntryRequest.kt
@@ -0,0 +1,3344 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.withorb.api.models
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter
+import com.fasterxml.jackson.annotation.JsonAnySetter
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.fasterxml.jackson.annotation.JsonProperty
+import com.fasterxml.jackson.core.JsonGenerator
+import com.fasterxml.jackson.core.ObjectCodec
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.SerializerProvider
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize
+import com.fasterxml.jackson.databind.annotation.JsonSerialize
+import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
+import com.withorb.api.core.BaseDeserializer
+import com.withorb.api.core.BaseSerializer
+import com.withorb.api.core.Enum
+import com.withorb.api.core.ExcludeMissing
+import com.withorb.api.core.JsonField
+import com.withorb.api.core.JsonMissing
+import com.withorb.api.core.JsonValue
+import com.withorb.api.core.NoAutoDetect
+import com.withorb.api.core.checkRequired
+import com.withorb.api.core.getOrThrow
+import com.withorb.api.core.immutableEmptyMap
+import com.withorb.api.core.toImmutable
+import com.withorb.api.errors.OrbInvalidDataException
+import java.time.LocalDate
+import java.time.OffsetDateTime
+import java.util.Objects
+import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
+
+@JsonDeserialize(using = AddCreditLedgerEntryRequest.Deserializer::class)
+@JsonSerialize(using = AddCreditLedgerEntryRequest.Serializer::class)
+class AddCreditLedgerEntryRequest
+private constructor(
+ private val incrementCreditLedgerEntryRequestParams:
+ AddIncrementCreditLedgerEntryRequestParams? =
+ null,
+ private val decrementCreditLedgerEntryRequestParams:
+ AddDecrementCreditLedgerEntryRequestParams? =
+ null,
+ private val expirationChangeCreditLedgerEntryRequestParams:
+ AddExpirationChangeCreditLedgerEntryRequestParams? =
+ null,
+ private val voidCreditLedgerEntryRequestParams: AddVoidCreditLedgerEntryRequestParams? = null,
+ private val amendmentCreditLedgerEntryRequestParams:
+ AddAmendmentCreditLedgerEntryRequestParams? =
+ null,
+ private val _json: JsonValue? = null,
+) {
+
+ fun incrementCreditLedgerEntryRequestParams():
+ Optional =
+ Optional.ofNullable(incrementCreditLedgerEntryRequestParams)
+
+ fun decrementCreditLedgerEntryRequestParams():
+ Optional =
+ Optional.ofNullable(decrementCreditLedgerEntryRequestParams)
+
+ fun expirationChangeCreditLedgerEntryRequestParams():
+ Optional =
+ Optional.ofNullable(expirationChangeCreditLedgerEntryRequestParams)
+
+ fun voidCreditLedgerEntryRequestParams(): Optional =
+ Optional.ofNullable(voidCreditLedgerEntryRequestParams)
+
+ fun amendmentCreditLedgerEntryRequestParams():
+ Optional =
+ Optional.ofNullable(amendmentCreditLedgerEntryRequestParams)
+
+ fun isIncrementCreditLedgerEntryRequestParams(): Boolean =
+ incrementCreditLedgerEntryRequestParams != null
+
+ fun isDecrementCreditLedgerEntryRequestParams(): Boolean =
+ decrementCreditLedgerEntryRequestParams != null
+
+ fun isExpirationChangeCreditLedgerEntryRequestParams(): Boolean =
+ expirationChangeCreditLedgerEntryRequestParams != null
+
+ fun isVoidCreditLedgerEntryRequestParams(): Boolean = voidCreditLedgerEntryRequestParams != null
+
+ fun isAmendmentCreditLedgerEntryRequestParams(): Boolean =
+ amendmentCreditLedgerEntryRequestParams != null
+
+ fun asIncrementCreditLedgerEntryRequestParams(): AddIncrementCreditLedgerEntryRequestParams =
+ incrementCreditLedgerEntryRequestParams.getOrThrow(
+ "incrementCreditLedgerEntryRequestParams"
+ )
+
+ fun asDecrementCreditLedgerEntryRequestParams(): AddDecrementCreditLedgerEntryRequestParams =
+ decrementCreditLedgerEntryRequestParams.getOrThrow(
+ "decrementCreditLedgerEntryRequestParams"
+ )
+
+ fun asExpirationChangeCreditLedgerEntryRequestParams():
+ AddExpirationChangeCreditLedgerEntryRequestParams =
+ expirationChangeCreditLedgerEntryRequestParams.getOrThrow(
+ "expirationChangeCreditLedgerEntryRequestParams"
+ )
+
+ fun asVoidCreditLedgerEntryRequestParams(): AddVoidCreditLedgerEntryRequestParams =
+ voidCreditLedgerEntryRequestParams.getOrThrow("voidCreditLedgerEntryRequestParams")
+
+ fun asAmendmentCreditLedgerEntryRequestParams(): AddAmendmentCreditLedgerEntryRequestParams =
+ amendmentCreditLedgerEntryRequestParams.getOrThrow(
+ "amendmentCreditLedgerEntryRequestParams"
+ )
+
+ fun _json(): Optional = Optional.ofNullable(_json)
+
+ fun accept(visitor: Visitor): T {
+ return when {
+ incrementCreditLedgerEntryRequestParams != null ->
+ visitor.visitIncrementCreditLedgerEntryRequestParams(
+ incrementCreditLedgerEntryRequestParams
+ )
+ decrementCreditLedgerEntryRequestParams != null ->
+ visitor.visitDecrementCreditLedgerEntryRequestParams(
+ decrementCreditLedgerEntryRequestParams
+ )
+ expirationChangeCreditLedgerEntryRequestParams != null ->
+ visitor.visitExpirationChangeCreditLedgerEntryRequestParams(
+ expirationChangeCreditLedgerEntryRequestParams
+ )
+ voidCreditLedgerEntryRequestParams != null ->
+ visitor.visitVoidCreditLedgerEntryRequestParams(voidCreditLedgerEntryRequestParams)
+ amendmentCreditLedgerEntryRequestParams != null ->
+ visitor.visitAmendmentCreditLedgerEntryRequestParams(
+ amendmentCreditLedgerEntryRequestParams
+ )
+ else -> visitor.unknown(_json)
+ }
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): AddCreditLedgerEntryRequest = apply {
+ if (validated) {
+ return@apply
+ }
+
+ accept(
+ object : Visitor {
+ override fun visitIncrementCreditLedgerEntryRequestParams(
+ incrementCreditLedgerEntryRequestParams:
+ AddIncrementCreditLedgerEntryRequestParams
+ ) {
+ incrementCreditLedgerEntryRequestParams.validate()
+ }
+
+ override fun visitDecrementCreditLedgerEntryRequestParams(
+ decrementCreditLedgerEntryRequestParams:
+ AddDecrementCreditLedgerEntryRequestParams
+ ) {
+ decrementCreditLedgerEntryRequestParams.validate()
+ }
+
+ override fun visitExpirationChangeCreditLedgerEntryRequestParams(
+ expirationChangeCreditLedgerEntryRequestParams:
+ AddExpirationChangeCreditLedgerEntryRequestParams
+ ) {
+ expirationChangeCreditLedgerEntryRequestParams.validate()
+ }
+
+ override fun visitVoidCreditLedgerEntryRequestParams(
+ voidCreditLedgerEntryRequestParams: AddVoidCreditLedgerEntryRequestParams
+ ) {
+ voidCreditLedgerEntryRequestParams.validate()
+ }
+
+ override fun visitAmendmentCreditLedgerEntryRequestParams(
+ amendmentCreditLedgerEntryRequestParams:
+ AddAmendmentCreditLedgerEntryRequestParams
+ ) {
+ amendmentCreditLedgerEntryRequestParams.validate()
+ }
+ }
+ )
+ validated = true
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AddCreditLedgerEntryRequest && incrementCreditLedgerEntryRequestParams == other.incrementCreditLedgerEntryRequestParams && decrementCreditLedgerEntryRequestParams == other.decrementCreditLedgerEntryRequestParams && expirationChangeCreditLedgerEntryRequestParams == other.expirationChangeCreditLedgerEntryRequestParams && voidCreditLedgerEntryRequestParams == other.voidCreditLedgerEntryRequestParams && amendmentCreditLedgerEntryRequestParams == other.amendmentCreditLedgerEntryRequestParams /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(incrementCreditLedgerEntryRequestParams, decrementCreditLedgerEntryRequestParams, expirationChangeCreditLedgerEntryRequestParams, voidCreditLedgerEntryRequestParams, amendmentCreditLedgerEntryRequestParams) /* spotless:on */
+
+ override fun toString(): String =
+ when {
+ incrementCreditLedgerEntryRequestParams != null ->
+ "AddCreditLedgerEntryRequest{incrementCreditLedgerEntryRequestParams=$incrementCreditLedgerEntryRequestParams}"
+ decrementCreditLedgerEntryRequestParams != null ->
+ "AddCreditLedgerEntryRequest{decrementCreditLedgerEntryRequestParams=$decrementCreditLedgerEntryRequestParams}"
+ expirationChangeCreditLedgerEntryRequestParams != null ->
+ "AddCreditLedgerEntryRequest{expirationChangeCreditLedgerEntryRequestParams=$expirationChangeCreditLedgerEntryRequestParams}"
+ voidCreditLedgerEntryRequestParams != null ->
+ "AddCreditLedgerEntryRequest{voidCreditLedgerEntryRequestParams=$voidCreditLedgerEntryRequestParams}"
+ amendmentCreditLedgerEntryRequestParams != null ->
+ "AddCreditLedgerEntryRequest{amendmentCreditLedgerEntryRequestParams=$amendmentCreditLedgerEntryRequestParams}"
+ _json != null -> "AddCreditLedgerEntryRequest{_unknown=$_json}"
+ else -> throw IllegalStateException("Invalid AddCreditLedgerEntryRequest")
+ }
+
+ companion object {
+
+ @JvmStatic
+ fun ofIncrementCreditLedgerEntryRequestParams(
+ incrementCreditLedgerEntryRequestParams: AddIncrementCreditLedgerEntryRequestParams
+ ) =
+ AddCreditLedgerEntryRequest(
+ incrementCreditLedgerEntryRequestParams = incrementCreditLedgerEntryRequestParams
+ )
+
+ @JvmStatic
+ fun ofDecrementCreditLedgerEntryRequestParams(
+ decrementCreditLedgerEntryRequestParams: AddDecrementCreditLedgerEntryRequestParams
+ ) =
+ AddCreditLedgerEntryRequest(
+ decrementCreditLedgerEntryRequestParams = decrementCreditLedgerEntryRequestParams
+ )
+
+ @JvmStatic
+ fun ofExpirationChangeCreditLedgerEntryRequestParams(
+ expirationChangeCreditLedgerEntryRequestParams:
+ AddExpirationChangeCreditLedgerEntryRequestParams
+ ) =
+ AddCreditLedgerEntryRequest(
+ expirationChangeCreditLedgerEntryRequestParams =
+ expirationChangeCreditLedgerEntryRequestParams
+ )
+
+ @JvmStatic
+ fun ofVoidCreditLedgerEntryRequestParams(
+ voidCreditLedgerEntryRequestParams: AddVoidCreditLedgerEntryRequestParams
+ ) =
+ AddCreditLedgerEntryRequest(
+ voidCreditLedgerEntryRequestParams = voidCreditLedgerEntryRequestParams
+ )
+
+ @JvmStatic
+ fun ofAmendmentCreditLedgerEntryRequestParams(
+ amendmentCreditLedgerEntryRequestParams: AddAmendmentCreditLedgerEntryRequestParams
+ ) =
+ AddCreditLedgerEntryRequest(
+ amendmentCreditLedgerEntryRequestParams = amendmentCreditLedgerEntryRequestParams
+ )
+ }
+
+ /**
+ * An interface that defines how to map each variant of [AddCreditLedgerEntryRequest] to a value
+ * of type [T].
+ */
+ interface Visitor {
+
+ fun visitIncrementCreditLedgerEntryRequestParams(
+ incrementCreditLedgerEntryRequestParams: AddIncrementCreditLedgerEntryRequestParams
+ ): T
+
+ fun visitDecrementCreditLedgerEntryRequestParams(
+ decrementCreditLedgerEntryRequestParams: AddDecrementCreditLedgerEntryRequestParams
+ ): T
+
+ fun visitExpirationChangeCreditLedgerEntryRequestParams(
+ expirationChangeCreditLedgerEntryRequestParams:
+ AddExpirationChangeCreditLedgerEntryRequestParams
+ ): T
+
+ fun visitVoidCreditLedgerEntryRequestParams(
+ voidCreditLedgerEntryRequestParams: AddVoidCreditLedgerEntryRequestParams
+ ): T
+
+ fun visitAmendmentCreditLedgerEntryRequestParams(
+ amendmentCreditLedgerEntryRequestParams: AddAmendmentCreditLedgerEntryRequestParams
+ ): T
+
+ /**
+ * Maps an unknown variant of [AddCreditLedgerEntryRequest] to a value of type [T].
+ *
+ * An instance of [AddCreditLedgerEntryRequest] can contain an unknown variant if it was
+ * deserialized from data that doesn't match any known variant. For example, if the SDK is
+ * on an older version than the API, then the API may respond with new variants that the SDK
+ * is unaware of.
+ *
+ * @throws OrbInvalidDataException in the default implementation.
+ */
+ fun unknown(json: JsonValue?): T {
+ throw OrbInvalidDataException("Unknown AddCreditLedgerEntryRequest: $json")
+ }
+ }
+
+ internal class Deserializer :
+ BaseDeserializer(AddCreditLedgerEntryRequest::class) {
+
+ override fun ObjectCodec.deserialize(node: JsonNode): AddCreditLedgerEntryRequest {
+ val json = JsonValue.fromJsonNode(node)
+ val entryType = json.asObject().getOrNull()?.get("entry_type")?.asString()?.getOrNull()
+
+ when (entryType) {
+ "increment" -> {
+ tryDeserialize(
+ node,
+ jacksonTypeRef(),
+ ) {
+ it.validate()
+ }
+ ?.let {
+ return AddCreditLedgerEntryRequest(
+ incrementCreditLedgerEntryRequestParams = it,
+ _json = json,
+ )
+ }
+ }
+ "decrement" -> {
+ tryDeserialize(
+ node,
+ jacksonTypeRef(),
+ ) {
+ it.validate()
+ }
+ ?.let {
+ return AddCreditLedgerEntryRequest(
+ decrementCreditLedgerEntryRequestParams = it,
+ _json = json,
+ )
+ }
+ }
+ "expiration_change" -> {
+ tryDeserialize(
+ node,
+ jacksonTypeRef(),
+ ) {
+ it.validate()
+ }
+ ?.let {
+ return AddCreditLedgerEntryRequest(
+ expirationChangeCreditLedgerEntryRequestParams = it,
+ _json = json,
+ )
+ }
+ }
+ "void" -> {
+ tryDeserialize(node, jacksonTypeRef()) {
+ it.validate()
+ }
+ ?.let {
+ return AddCreditLedgerEntryRequest(
+ voidCreditLedgerEntryRequestParams = it,
+ _json = json,
+ )
+ }
+ }
+ "amendment" -> {
+ tryDeserialize(
+ node,
+ jacksonTypeRef(),
+ ) {
+ it.validate()
+ }
+ ?.let {
+ return AddCreditLedgerEntryRequest(
+ amendmentCreditLedgerEntryRequestParams = it,
+ _json = json,
+ )
+ }
+ }
+ }
+
+ return AddCreditLedgerEntryRequest(_json = json)
+ }
+ }
+
+ internal class Serializer :
+ BaseSerializer(AddCreditLedgerEntryRequest::class) {
+
+ override fun serialize(
+ value: AddCreditLedgerEntryRequest,
+ generator: JsonGenerator,
+ provider: SerializerProvider,
+ ) {
+ when {
+ value.incrementCreditLedgerEntryRequestParams != null ->
+ generator.writeObject(value.incrementCreditLedgerEntryRequestParams)
+ value.decrementCreditLedgerEntryRequestParams != null ->
+ generator.writeObject(value.decrementCreditLedgerEntryRequestParams)
+ value.expirationChangeCreditLedgerEntryRequestParams != null ->
+ generator.writeObject(value.expirationChangeCreditLedgerEntryRequestParams)
+ value.voidCreditLedgerEntryRequestParams != null ->
+ generator.writeObject(value.voidCreditLedgerEntryRequestParams)
+ value.amendmentCreditLedgerEntryRequestParams != null ->
+ generator.writeObject(value.amendmentCreditLedgerEntryRequestParams)
+ value._json != null -> generator.writeObject(value._json)
+ else -> throw IllegalStateException("Invalid AddCreditLedgerEntryRequest")
+ }
+ }
+ }
+
+ @NoAutoDetect
+ class AddIncrementCreditLedgerEntryRequestParams
+ @JsonCreator
+ private constructor(
+ @JsonProperty("amount")
+ @ExcludeMissing
+ private val amount: JsonField = JsonMissing.of(),
+ @JsonProperty("entry_type")
+ @ExcludeMissing
+ private val entryType: JsonField = JsonMissing.of(),
+ @JsonProperty("currency")
+ @ExcludeMissing
+ private val currency: JsonField = JsonMissing.of(),
+ @JsonProperty("description")
+ @ExcludeMissing
+ private val description: JsonField = JsonMissing.of(),
+ @JsonProperty("effective_date")
+ @ExcludeMissing
+ private val effectiveDate: JsonField = JsonMissing.of(),
+ @JsonProperty("expiry_date")
+ @ExcludeMissing
+ private val expiryDate: JsonField = JsonMissing.of(),
+ @JsonProperty("invoice_settings")
+ @ExcludeMissing
+ private val invoiceSettings: JsonField = JsonMissing.of(),
+ @JsonProperty("metadata")
+ @ExcludeMissing
+ private val metadata: JsonField = JsonMissing.of(),
+ @JsonProperty("per_unit_cost_basis")
+ @ExcludeMissing
+ private val perUnitCostBasis: JsonField = JsonMissing.of(),
+ @JsonAnySetter
+ private val additionalProperties: Map = immutableEmptyMap(),
+ ) {
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ fun amount(): Double = amount.getRequired("amount")
+
+ fun entryType(): EntryType = entryType.getRequired("entry_type")
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a real-world
+ * currency, it must match the customer's invoicing currency.
+ */
+ fun currency(): Optional = Optional.ofNullable(currency.getNullable("currency"))
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(): Optional =
+ Optional.ofNullable(description.getNullable("description"))
+
+ /**
+ * An ISO 8601 format date that denotes when this credit balance should become available for
+ * use.
+ */
+ fun effectiveDate(): Optional =
+ Optional.ofNullable(effectiveDate.getNullable("effective_date"))
+
+ /** An ISO 8601 format date that denotes when this credit balance should expire. */
+ fun expiryDate(): Optional =
+ Optional.ofNullable(expiryDate.getNullable("expiry_date"))
+
+ /**
+ * Passing `invoice_settings` automatically generates an invoice for the newly added
+ * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, as the
+ * calculation of the invoice total is done on that basis.
+ */
+ fun invoiceSettings(): Optional =
+ Optional.ofNullable(invoiceSettings.getNullable("invoice_settings"))
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by setting
+ * `metadata` to `null`.
+ */
+ fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata"))
+
+ /**
+ * Can only be specified when entry_type=increment. How much, in the customer's currency, a
+ * customer paid for a single credit in this block
+ */
+ fun perUnitCostBasis(): Optional =
+ Optional.ofNullable(perUnitCostBasis.getNullable("per_unit_cost_basis"))
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount
+
+ @JsonProperty("entry_type")
+ @ExcludeMissing
+ fun _entryType(): JsonField = entryType
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a real-world
+ * currency, it must match the customer's invoicing currency.
+ */
+ @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ @JsonProperty("description")
+ @ExcludeMissing
+ fun _description(): JsonField = description
+
+ /**
+ * An ISO 8601 format date that denotes when this credit balance should become available for
+ * use.
+ */
+ @JsonProperty("effective_date")
+ @ExcludeMissing
+ fun _effectiveDate(): JsonField = effectiveDate
+
+ /** An ISO 8601 format date that denotes when this credit balance should expire. */
+ @JsonProperty("expiry_date")
+ @ExcludeMissing
+ fun _expiryDate(): JsonField = expiryDate
+
+ /**
+ * Passing `invoice_settings` automatically generates an invoice for the newly added
+ * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, as the
+ * calculation of the invoice total is done on that basis.
+ */
+ @JsonProperty("invoice_settings")
+ @ExcludeMissing
+ fun _invoiceSettings(): JsonField = invoiceSettings
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by setting
+ * `metadata` to `null`.
+ */
+ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata
+
+ /**
+ * Can only be specified when entry_type=increment. How much, in the customer's currency, a
+ * customer paid for a single credit in this block
+ */
+ @JsonProperty("per_unit_cost_basis")
+ @ExcludeMissing
+ fun _perUnitCostBasis(): JsonField = perUnitCostBasis
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map = additionalProperties
+
+ private var validated: Boolean = false
+
+ fun validate(): AddIncrementCreditLedgerEntryRequestParams = apply {
+ if (validated) {
+ return@apply
+ }
+
+ amount()
+ entryType()
+ currency()
+ description()
+ effectiveDate()
+ expiryDate()
+ invoiceSettings().ifPresent { it.validate() }
+ metadata().ifPresent { it.validate() }
+ perUnitCostBasis()
+ validated = true
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of
+ * [AddIncrementCreditLedgerEntryRequestParams].
+ *
+ * The following fields are required:
+ * ```java
+ * .amount()
+ * .entryType()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [AddIncrementCreditLedgerEntryRequestParams]. */
+ class Builder internal constructor() {
+
+ private var amount: JsonField? = null
+ private var entryType: JsonField? = null
+ private var currency: JsonField = JsonMissing.of()
+ private var description: JsonField = JsonMissing.of()
+ private var effectiveDate: JsonField = JsonMissing.of()
+ private var expiryDate: JsonField = JsonMissing.of()
+ private var invoiceSettings: JsonField = JsonMissing.of()
+ private var metadata: JsonField = JsonMissing.of()
+ private var perUnitCostBasis: JsonField = JsonMissing.of()
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(
+ addIncrementCreditLedgerEntryRequestParams:
+ AddIncrementCreditLedgerEntryRequestParams
+ ) = apply {
+ amount = addIncrementCreditLedgerEntryRequestParams.amount
+ entryType = addIncrementCreditLedgerEntryRequestParams.entryType
+ currency = addIncrementCreditLedgerEntryRequestParams.currency
+ description = addIncrementCreditLedgerEntryRequestParams.description
+ effectiveDate = addIncrementCreditLedgerEntryRequestParams.effectiveDate
+ expiryDate = addIncrementCreditLedgerEntryRequestParams.expiryDate
+ invoiceSettings = addIncrementCreditLedgerEntryRequestParams.invoiceSettings
+ metadata = addIncrementCreditLedgerEntryRequestParams.metadata
+ perUnitCostBasis = addIncrementCreditLedgerEntryRequestParams.perUnitCostBasis
+ additionalProperties =
+ addIncrementCreditLedgerEntryRequestParams.additionalProperties.toMutableMap()
+ }
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ fun amount(amount: Double) = amount(JsonField.of(amount))
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ fun amount(amount: JsonField) = apply { this.amount = amount }
+
+ fun entryType(entryType: EntryType) = entryType(JsonField.of(entryType))
+
+ fun entryType(entryType: JsonField) = apply { this.entryType = entryType }
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a
+ * real-world currency, it must match the customer's invoicing currency.
+ */
+ fun currency(currency: String?) = currency(JsonField.ofNullable(currency))
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a
+ * real-world currency, it must match the customer's invoicing currency.
+ */
+ fun currency(currency: Optional) = currency(currency.orElse(null))
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a
+ * real-world currency, it must match the customer's invoicing currency.
+ */
+ fun currency(currency: JsonField) = apply { this.currency = currency }
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(description: String?) = description(JsonField.ofNullable(description))
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(description: Optional) = description(description.orElse(null))
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(description: JsonField) = apply {
+ this.description = description
+ }
+
+ /**
+ * An ISO 8601 format date that denotes when this credit balance should become available
+ * for use.
+ */
+ fun effectiveDate(effectiveDate: OffsetDateTime?) =
+ effectiveDate(JsonField.ofNullable(effectiveDate))
+
+ /**
+ * An ISO 8601 format date that denotes when this credit balance should become available
+ * for use.
+ */
+ fun effectiveDate(effectiveDate: Optional) =
+ effectiveDate(effectiveDate.orElse(null))
+
+ /**
+ * An ISO 8601 format date that denotes when this credit balance should become available
+ * for use.
+ */
+ fun effectiveDate(effectiveDate: JsonField) = apply {
+ this.effectiveDate = effectiveDate
+ }
+
+ /** An ISO 8601 format date that denotes when this credit balance should expire. */
+ fun expiryDate(expiryDate: OffsetDateTime?) =
+ expiryDate(JsonField.ofNullable(expiryDate))
+
+ /** An ISO 8601 format date that denotes when this credit balance should expire. */
+ fun expiryDate(expiryDate: Optional) =
+ expiryDate(expiryDate.orElse(null))
+
+ /** An ISO 8601 format date that denotes when this credit balance should expire. */
+ fun expiryDate(expiryDate: JsonField) = apply {
+ this.expiryDate = expiryDate
+ }
+
+ /**
+ * Passing `invoice_settings` automatically generates an invoice for the newly added
+ * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, as
+ * the calculation of the invoice total is done on that basis.
+ */
+ fun invoiceSettings(invoiceSettings: InvoiceSettings?) =
+ invoiceSettings(JsonField.ofNullable(invoiceSettings))
+
+ /**
+ * Passing `invoice_settings` automatically generates an invoice for the newly added
+ * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, as
+ * the calculation of the invoice total is done on that basis.
+ */
+ fun invoiceSettings(invoiceSettings: Optional) =
+ invoiceSettings(invoiceSettings.orElse(null))
+
+ /**
+ * Passing `invoice_settings` automatically generates an invoice for the newly added
+ * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, as
+ * the calculation of the invoice total is done on that basis.
+ */
+ fun invoiceSettings(invoiceSettings: JsonField) = apply {
+ this.invoiceSettings = invoiceSettings
+ }
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by
+ * setting `metadata` to `null`.
+ */
+ fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata))
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by
+ * setting `metadata` to `null`.
+ */
+ fun metadata(metadata: Optional) = metadata(metadata.orElse(null))
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by
+ * setting `metadata` to `null`.
+ */
+ fun metadata(metadata: JsonField) = apply { this.metadata = metadata }
+
+ /**
+ * Can only be specified when entry_type=increment. How much, in the customer's
+ * currency, a customer paid for a single credit in this block
+ */
+ fun perUnitCostBasis(perUnitCostBasis: String?) =
+ perUnitCostBasis(JsonField.ofNullable(perUnitCostBasis))
+
+ /**
+ * Can only be specified when entry_type=increment. How much, in the customer's
+ * currency, a customer paid for a single credit in this block
+ */
+ fun perUnitCostBasis(perUnitCostBasis: Optional) =
+ perUnitCostBasis(perUnitCostBasis.orElse(null))
+
+ /**
+ * Can only be specified when entry_type=increment. How much, in the customer's
+ * currency, a customer paid for a single credit in this block
+ */
+ fun perUnitCostBasis(perUnitCostBasis: JsonField) = apply {
+ this.perUnitCostBasis = perUnitCostBasis
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ fun build(): AddIncrementCreditLedgerEntryRequestParams =
+ AddIncrementCreditLedgerEntryRequestParams(
+ checkRequired("amount", amount),
+ checkRequired("entryType", entryType),
+ currency,
+ description,
+ effectiveDate,
+ expiryDate,
+ invoiceSettings,
+ metadata,
+ perUnitCostBasis,
+ additionalProperties.toImmutable(),
+ )
+ }
+
+ class EntryType @JsonCreator private constructor(private val value: JsonField) :
+ Enum {
+
+ /**
+ * Returns this class instance's raw value.
+ *
+ * This is usually only useful if this instance was deserialized from data that doesn't
+ * match any known member, and you want to know that value. For example, if the SDK is
+ * on an older version than the API, then the API may respond with new members that the
+ * SDK is unaware of.
+ */
+ @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value
+
+ companion object {
+
+ @JvmField val INCREMENT = of("increment")
+
+ @JvmStatic fun of(value: String) = EntryType(JsonField.of(value))
+ }
+
+ /** An enum containing [EntryType]'s known values. */
+ enum class Known {
+ INCREMENT
+ }
+
+ /**
+ * An enum containing [EntryType]'s known values, as well as an [_UNKNOWN] member.
+ *
+ * An instance of [EntryType] can contain an unknown value in a couple of cases:
+ * - It was deserialized from data that doesn't match any known member. For example, if
+ * the SDK is on an older version than the API, then the API may respond with new
+ * members that the SDK is unaware of.
+ * - It was constructed with an arbitrary value using the [of] method.
+ */
+ enum class Value {
+ INCREMENT,
+ /**
+ * An enum member indicating that [EntryType] was instantiated with an unknown
+ * value.
+ */
+ _UNKNOWN,
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value, or
+ * [Value._UNKNOWN] if the class was instantiated with an unknown value.
+ *
+ * Use the [known] method instead if you're certain the value is always known or if you
+ * want to throw for the unknown case.
+ */
+ fun value(): Value =
+ when (this) {
+ INCREMENT -> Value.INCREMENT
+ else -> Value._UNKNOWN
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value.
+ *
+ * Use the [value] method instead if you're uncertain the value is always known and
+ * don't want to throw for the unknown case.
+ *
+ * @throws OrbInvalidDataException if this class instance's value is a not a known
+ * member.
+ */
+ fun known(): Known =
+ when (this) {
+ INCREMENT -> Known.INCREMENT
+ else -> throw OrbInvalidDataException("Unknown EntryType: $value")
+ }
+
+ /**
+ * Returns this class instance's primitive wire representation.
+ *
+ * This differs from the [toString] method because that method is primarily for
+ * debugging and generally doesn't throw.
+ *
+ * @throws OrbInvalidDataException if this class instance's value does not have the
+ * expected primitive type.
+ */
+ fun asString(): String =
+ _value().asString().orElseThrow { OrbInvalidDataException("Value is not a String") }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */
+ }
+
+ override fun hashCode() = value.hashCode()
+
+ override fun toString() = value.toString()
+ }
+
+ /**
+ * Passing `invoice_settings` automatically generates an invoice for the newly added
+ * credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis, as the
+ * calculation of the invoice total is done on that basis.
+ */
+ @NoAutoDetect
+ class InvoiceSettings
+ @JsonCreator
+ private constructor(
+ @JsonProperty("auto_collection")
+ @ExcludeMissing
+ private val autoCollection: JsonField = JsonMissing.of(),
+ @JsonProperty("net_terms")
+ @ExcludeMissing
+ private val netTerms: JsonField = JsonMissing.of(),
+ @JsonProperty("memo")
+ @ExcludeMissing
+ private val memo: JsonField = JsonMissing.of(),
+ @JsonProperty("require_successful_payment")
+ @ExcludeMissing
+ private val requireSuccessfulPayment: JsonField = JsonMissing.of(),
+ @JsonAnySetter
+ private val additionalProperties: Map = immutableEmptyMap(),
+ ) {
+
+ /**
+ * Whether the credits purchase invoice should auto collect with the customer's saved
+ * payment method.
+ */
+ fun autoCollection(): Boolean = autoCollection.getRequired("auto_collection")
+
+ /**
+ * The net terms determines the difference between the invoice date and the issue date
+ * for the invoice. If you intend the invoice to be due on issue, set this to 0.
+ */
+ fun netTerms(): Long = netTerms.getRequired("net_terms")
+
+ /** An optional memo to display on the invoice. */
+ fun memo(): Optional = Optional.ofNullable(memo.getNullable("memo"))
+
+ /**
+ * If true, the new credit block will require that the corresponding invoice is paid
+ * before it can be drawn down from.
+ */
+ fun requireSuccessfulPayment(): Optional =
+ Optional.ofNullable(
+ requireSuccessfulPayment.getNullable("require_successful_payment")
+ )
+
+ /**
+ * Whether the credits purchase invoice should auto collect with the customer's saved
+ * payment method.
+ */
+ @JsonProperty("auto_collection")
+ @ExcludeMissing
+ fun _autoCollection(): JsonField = autoCollection
+
+ /**
+ * The net terms determines the difference between the invoice date and the issue date
+ * for the invoice. If you intend the invoice to be due on issue, set this to 0.
+ */
+ @JsonProperty("net_terms") @ExcludeMissing fun _netTerms(): JsonField = netTerms
+
+ /** An optional memo to display on the invoice. */
+ @JsonProperty("memo") @ExcludeMissing fun _memo(): JsonField = memo
+
+ /**
+ * If true, the new credit block will require that the corresponding invoice is paid
+ * before it can be drawn down from.
+ */
+ @JsonProperty("require_successful_payment")
+ @ExcludeMissing
+ fun _requireSuccessfulPayment(): JsonField = requireSuccessfulPayment
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map = additionalProperties
+
+ private var validated: Boolean = false
+
+ fun validate(): InvoiceSettings = apply {
+ if (validated) {
+ return@apply
+ }
+
+ autoCollection()
+ netTerms()
+ memo()
+ requireSuccessfulPayment()
+ validated = true
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of [InvoiceSettings].
+ *
+ * The following fields are required:
+ * ```java
+ * .autoCollection()
+ * .netTerms()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [InvoiceSettings]. */
+ class Builder internal constructor() {
+
+ private var autoCollection: JsonField? = null
+ private var netTerms: JsonField? = null
+ private var memo: JsonField = JsonMissing.of()
+ private var requireSuccessfulPayment: JsonField = JsonMissing.of()
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(invoiceSettings: InvoiceSettings) = apply {
+ autoCollection = invoiceSettings.autoCollection
+ netTerms = invoiceSettings.netTerms
+ memo = invoiceSettings.memo
+ requireSuccessfulPayment = invoiceSettings.requireSuccessfulPayment
+ additionalProperties = invoiceSettings.additionalProperties.toMutableMap()
+ }
+
+ /**
+ * Whether the credits purchase invoice should auto collect with the customer's
+ * saved payment method.
+ */
+ fun autoCollection(autoCollection: Boolean) =
+ autoCollection(JsonField.of(autoCollection))
+
+ /**
+ * Whether the credits purchase invoice should auto collect with the customer's
+ * saved payment method.
+ */
+ fun autoCollection(autoCollection: JsonField) = apply {
+ this.autoCollection = autoCollection
+ }
+
+ /**
+ * The net terms determines the difference between the invoice date and the issue
+ * date for the invoice. If you intend the invoice to be due on issue, set this
+ * to 0.
+ */
+ fun netTerms(netTerms: Long) = netTerms(JsonField.of(netTerms))
+
+ /**
+ * The net terms determines the difference between the invoice date and the issue
+ * date for the invoice. If you intend the invoice to be due on issue, set this
+ * to 0.
+ */
+ fun netTerms(netTerms: JsonField) = apply { this.netTerms = netTerms }
+
+ /** An optional memo to display on the invoice. */
+ fun memo(memo: String?) = memo(JsonField.ofNullable(memo))
+
+ /** An optional memo to display on the invoice. */
+ fun memo(memo: Optional) = memo(memo.orElse(null))
+
+ /** An optional memo to display on the invoice. */
+ fun memo(memo: JsonField) = apply { this.memo = memo }
+
+ /**
+ * If true, the new credit block will require that the corresponding invoice is paid
+ * before it can be drawn down from.
+ */
+ fun requireSuccessfulPayment(requireSuccessfulPayment: Boolean) =
+ requireSuccessfulPayment(JsonField.of(requireSuccessfulPayment))
+
+ /**
+ * If true, the new credit block will require that the corresponding invoice is paid
+ * before it can be drawn down from.
+ */
+ fun requireSuccessfulPayment(requireSuccessfulPayment: JsonField) = apply {
+ this.requireSuccessfulPayment = requireSuccessfulPayment
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) =
+ apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply {
+ additionalProperties.remove(key)
+ }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ fun build(): InvoiceSettings =
+ InvoiceSettings(
+ checkRequired("autoCollection", autoCollection),
+ checkRequired("netTerms", netTerms),
+ memo,
+ requireSuccessfulPayment,
+ additionalProperties.toImmutable(),
+ )
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is InvoiceSettings && autoCollection == other.autoCollection && netTerms == other.netTerms && memo == other.memo && requireSuccessfulPayment == other.requireSuccessfulPayment && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(autoCollection, netTerms, memo, requireSuccessfulPayment, additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "InvoiceSettings{autoCollection=$autoCollection, netTerms=$netTerms, memo=$memo, requireSuccessfulPayment=$requireSuccessfulPayment, additionalProperties=$additionalProperties}"
+ }
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by setting
+ * `metadata` to `null`.
+ */
+ @NoAutoDetect
+ class Metadata
+ @JsonCreator
+ private constructor(
+ @JsonAnySetter
+ private val additionalProperties: Map = immutableEmptyMap()
+ ) {
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map = additionalProperties
+
+ private var validated: Boolean = false
+
+ fun validate(): Metadata = apply {
+ if (validated) {
+ return@apply
+ }
+
+ validated = true
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /** Returns a mutable builder for constructing an instance of [Metadata]. */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Metadata]. */
+ class Builder internal constructor() {
+
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(metadata: Metadata) = apply {
+ additionalProperties = metadata.additionalProperties.toMutableMap()
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) =
+ apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply {
+ additionalProperties.remove(key)
+ }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ fun build(): Metadata = Metadata(additionalProperties.toImmutable())
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() = "Metadata{additionalProperties=$additionalProperties}"
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AddIncrementCreditLedgerEntryRequestParams && amount == other.amount && entryType == other.entryType && currency == other.currency && description == other.description && effectiveDate == other.effectiveDate && expiryDate == other.expiryDate && invoiceSettings == other.invoiceSettings && metadata == other.metadata && perUnitCostBasis == other.perUnitCostBasis && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(amount, entryType, currency, description, effectiveDate, expiryDate, invoiceSettings, metadata, perUnitCostBasis, additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "AddIncrementCreditLedgerEntryRequestParams{amount=$amount, entryType=$entryType, currency=$currency, description=$description, effectiveDate=$effectiveDate, expiryDate=$expiryDate, invoiceSettings=$invoiceSettings, metadata=$metadata, perUnitCostBasis=$perUnitCostBasis, additionalProperties=$additionalProperties}"
+ }
+
+ @NoAutoDetect
+ class AddDecrementCreditLedgerEntryRequestParams
+ @JsonCreator
+ private constructor(
+ @JsonProperty("amount")
+ @ExcludeMissing
+ private val amount: JsonField = JsonMissing.of(),
+ @JsonProperty("entry_type")
+ @ExcludeMissing
+ private val entryType: JsonField = JsonMissing.of(),
+ @JsonProperty("currency")
+ @ExcludeMissing
+ private val currency: JsonField = JsonMissing.of(),
+ @JsonProperty("description")
+ @ExcludeMissing
+ private val description: JsonField = JsonMissing.of(),
+ @JsonProperty("metadata")
+ @ExcludeMissing
+ private val metadata: JsonField = JsonMissing.of(),
+ @JsonAnySetter
+ private val additionalProperties: Map = immutableEmptyMap(),
+ ) {
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ fun amount(): Double = amount.getRequired("amount")
+
+ fun entryType(): EntryType = entryType.getRequired("entry_type")
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a real-world
+ * currency, it must match the customer's invoicing currency.
+ */
+ fun currency(): Optional = Optional.ofNullable(currency.getNullable("currency"))
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(): Optional =
+ Optional.ofNullable(description.getNullable("description"))
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by setting
+ * `metadata` to `null`.
+ */
+ fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata"))
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount
+
+ @JsonProperty("entry_type")
+ @ExcludeMissing
+ fun _entryType(): JsonField = entryType
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a real-world
+ * currency, it must match the customer's invoicing currency.
+ */
+ @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ @JsonProperty("description")
+ @ExcludeMissing
+ fun _description(): JsonField = description
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by setting
+ * `metadata` to `null`.
+ */
+ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map = additionalProperties
+
+ private var validated: Boolean = false
+
+ fun validate(): AddDecrementCreditLedgerEntryRequestParams = apply {
+ if (validated) {
+ return@apply
+ }
+
+ amount()
+ entryType()
+ currency()
+ description()
+ metadata().ifPresent { it.validate() }
+ validated = true
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of
+ * [AddDecrementCreditLedgerEntryRequestParams].
+ *
+ * The following fields are required:
+ * ```java
+ * .amount()
+ * .entryType()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [AddDecrementCreditLedgerEntryRequestParams]. */
+ class Builder internal constructor() {
+
+ private var amount: JsonField? = null
+ private var entryType: JsonField? = null
+ private var currency: JsonField = JsonMissing.of()
+ private var description: JsonField = JsonMissing.of()
+ private var metadata: JsonField = JsonMissing.of()
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(
+ addDecrementCreditLedgerEntryRequestParams:
+ AddDecrementCreditLedgerEntryRequestParams
+ ) = apply {
+ amount = addDecrementCreditLedgerEntryRequestParams.amount
+ entryType = addDecrementCreditLedgerEntryRequestParams.entryType
+ currency = addDecrementCreditLedgerEntryRequestParams.currency
+ description = addDecrementCreditLedgerEntryRequestParams.description
+ metadata = addDecrementCreditLedgerEntryRequestParams.metadata
+ additionalProperties =
+ addDecrementCreditLedgerEntryRequestParams.additionalProperties.toMutableMap()
+ }
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ fun amount(amount: Double) = amount(JsonField.of(amount))
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ fun amount(amount: JsonField) = apply { this.amount = amount }
+
+ fun entryType(entryType: EntryType) = entryType(JsonField.of(entryType))
+
+ fun entryType(entryType: JsonField) = apply { this.entryType = entryType }
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a
+ * real-world currency, it must match the customer's invoicing currency.
+ */
+ fun currency(currency: String?) = currency(JsonField.ofNullable(currency))
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a
+ * real-world currency, it must match the customer's invoicing currency.
+ */
+ fun currency(currency: Optional) = currency(currency.orElse(null))
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a
+ * real-world currency, it must match the customer's invoicing currency.
+ */
+ fun currency(currency: JsonField) = apply { this.currency = currency }
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(description: String?) = description(JsonField.ofNullable(description))
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(description: Optional) = description(description.orElse(null))
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(description: JsonField) = apply {
+ this.description = description
+ }
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by
+ * setting `metadata` to `null`.
+ */
+ fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata))
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by
+ * setting `metadata` to `null`.
+ */
+ fun metadata(metadata: Optional) = metadata(metadata.orElse(null))
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by
+ * setting `metadata` to `null`.
+ */
+ fun metadata(metadata: JsonField) = apply { this.metadata = metadata }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ fun build(): AddDecrementCreditLedgerEntryRequestParams =
+ AddDecrementCreditLedgerEntryRequestParams(
+ checkRequired("amount", amount),
+ checkRequired("entryType", entryType),
+ currency,
+ description,
+ metadata,
+ additionalProperties.toImmutable(),
+ )
+ }
+
+ class EntryType @JsonCreator private constructor(private val value: JsonField) :
+ Enum {
+
+ /**
+ * Returns this class instance's raw value.
+ *
+ * This is usually only useful if this instance was deserialized from data that doesn't
+ * match any known member, and you want to know that value. For example, if the SDK is
+ * on an older version than the API, then the API may respond with new members that the
+ * SDK is unaware of.
+ */
+ @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value
+
+ companion object {
+
+ @JvmField val DECREMENT = of("decrement")
+
+ @JvmStatic fun of(value: String) = EntryType(JsonField.of(value))
+ }
+
+ /** An enum containing [EntryType]'s known values. */
+ enum class Known {
+ DECREMENT
+ }
+
+ /**
+ * An enum containing [EntryType]'s known values, as well as an [_UNKNOWN] member.
+ *
+ * An instance of [EntryType] can contain an unknown value in a couple of cases:
+ * - It was deserialized from data that doesn't match any known member. For example, if
+ * the SDK is on an older version than the API, then the API may respond with new
+ * members that the SDK is unaware of.
+ * - It was constructed with an arbitrary value using the [of] method.
+ */
+ enum class Value {
+ DECREMENT,
+ /**
+ * An enum member indicating that [EntryType] was instantiated with an unknown
+ * value.
+ */
+ _UNKNOWN,
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value, or
+ * [Value._UNKNOWN] if the class was instantiated with an unknown value.
+ *
+ * Use the [known] method instead if you're certain the value is always known or if you
+ * want to throw for the unknown case.
+ */
+ fun value(): Value =
+ when (this) {
+ DECREMENT -> Value.DECREMENT
+ else -> Value._UNKNOWN
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value.
+ *
+ * Use the [value] method instead if you're uncertain the value is always known and
+ * don't want to throw for the unknown case.
+ *
+ * @throws OrbInvalidDataException if this class instance's value is a not a known
+ * member.
+ */
+ fun known(): Known =
+ when (this) {
+ DECREMENT -> Known.DECREMENT
+ else -> throw OrbInvalidDataException("Unknown EntryType: $value")
+ }
+
+ /**
+ * Returns this class instance's primitive wire representation.
+ *
+ * This differs from the [toString] method because that method is primarily for
+ * debugging and generally doesn't throw.
+ *
+ * @throws OrbInvalidDataException if this class instance's value does not have the
+ * expected primitive type.
+ */
+ fun asString(): String =
+ _value().asString().orElseThrow { OrbInvalidDataException("Value is not a String") }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */
+ }
+
+ override fun hashCode() = value.hashCode()
+
+ override fun toString() = value.toString()
+ }
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by setting
+ * `metadata` to `null`.
+ */
+ @NoAutoDetect
+ class Metadata
+ @JsonCreator
+ private constructor(
+ @JsonAnySetter
+ private val additionalProperties: Map = immutableEmptyMap()
+ ) {
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map = additionalProperties
+
+ private var validated: Boolean = false
+
+ fun validate(): Metadata = apply {
+ if (validated) {
+ return@apply
+ }
+
+ validated = true
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /** Returns a mutable builder for constructing an instance of [Metadata]. */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Metadata]. */
+ class Builder internal constructor() {
+
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(metadata: Metadata) = apply {
+ additionalProperties = metadata.additionalProperties.toMutableMap()
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) =
+ apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply {
+ additionalProperties.remove(key)
+ }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ fun build(): Metadata = Metadata(additionalProperties.toImmutable())
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() = "Metadata{additionalProperties=$additionalProperties}"
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AddDecrementCreditLedgerEntryRequestParams && amount == other.amount && entryType == other.entryType && currency == other.currency && description == other.description && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(amount, entryType, currency, description, metadata, additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "AddDecrementCreditLedgerEntryRequestParams{amount=$amount, entryType=$entryType, currency=$currency, description=$description, metadata=$metadata, additionalProperties=$additionalProperties}"
+ }
+
+ @NoAutoDetect
+ class AddExpirationChangeCreditLedgerEntryRequestParams
+ @JsonCreator
+ private constructor(
+ @JsonProperty("entry_type")
+ @ExcludeMissing
+ private val entryType: JsonField = JsonMissing.of(),
+ @JsonProperty("expiry_date")
+ @ExcludeMissing
+ private val expiryDate: JsonField = JsonMissing.of(),
+ @JsonProperty("target_expiry_date")
+ @ExcludeMissing
+ private val targetExpiryDate: JsonField = JsonMissing.of(),
+ @JsonProperty("amount")
+ @ExcludeMissing
+ private val amount: JsonField = JsonMissing.of(),
+ @JsonProperty("block_id")
+ @ExcludeMissing
+ private val blockId: JsonField = JsonMissing.of(),
+ @JsonProperty("currency")
+ @ExcludeMissing
+ private val currency: JsonField = JsonMissing.of(),
+ @JsonProperty("description")
+ @ExcludeMissing
+ private val description: JsonField = JsonMissing.of(),
+ @JsonProperty("metadata")
+ @ExcludeMissing
+ private val metadata: JsonField = JsonMissing.of(),
+ @JsonAnySetter
+ private val additionalProperties: Map = immutableEmptyMap(),
+ ) {
+
+ fun entryType(): EntryType = entryType.getRequired("entry_type")
+
+ /** An ISO 8601 format date that identifies the origination credit block to expire */
+ fun expiryDate(): Optional =
+ Optional.ofNullable(expiryDate.getNullable("expiry_date"))
+
+ /**
+ * A future date (specified in YYYY-MM-DD format) used for expiration change, denoting when
+ * credits transferred (as part of a partial block expiration) should expire.
+ */
+ fun targetExpiryDate(): LocalDate = targetExpiryDate.getRequired("target_expiry_date")
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ fun amount(): Optional = Optional.ofNullable(amount.getNullable("amount"))
+
+ /**
+ * The ID of the block affected by an expiration_change, used to differentiate between
+ * multiple blocks with the same `expiry_date`.
+ */
+ fun blockId(): Optional = Optional.ofNullable(blockId.getNullable("block_id"))
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a real-world
+ * currency, it must match the customer's invoicing currency.
+ */
+ fun currency(): Optional = Optional.ofNullable(currency.getNullable("currency"))
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(): Optional =
+ Optional.ofNullable(description.getNullable("description"))
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by setting
+ * `metadata` to `null`.
+ */
+ fun metadata(): Optional = Optional.ofNullable(metadata.getNullable("metadata"))
+
+ @JsonProperty("entry_type")
+ @ExcludeMissing
+ fun _entryType(): JsonField = entryType
+
+ /** An ISO 8601 format date that identifies the origination credit block to expire */
+ @JsonProperty("expiry_date")
+ @ExcludeMissing
+ fun _expiryDate(): JsonField = expiryDate
+
+ /**
+ * A future date (specified in YYYY-MM-DD format) used for expiration change, denoting when
+ * credits transferred (as part of a partial block expiration) should expire.
+ */
+ @JsonProperty("target_expiry_date")
+ @ExcludeMissing
+ fun _targetExpiryDate(): JsonField = targetExpiryDate
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount
+
+ /**
+ * The ID of the block affected by an expiration_change, used to differentiate between
+ * multiple blocks with the same `expiry_date`.
+ */
+ @JsonProperty("block_id") @ExcludeMissing fun _blockId(): JsonField = blockId
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a real-world
+ * currency, it must match the customer's invoicing currency.
+ */
+ @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ @JsonProperty("description")
+ @ExcludeMissing
+ fun _description(): JsonField = description
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by setting
+ * `metadata` to `null`.
+ */
+ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map = additionalProperties
+
+ private var validated: Boolean = false
+
+ fun validate(): AddExpirationChangeCreditLedgerEntryRequestParams = apply {
+ if (validated) {
+ return@apply
+ }
+
+ entryType()
+ expiryDate()
+ targetExpiryDate()
+ amount()
+ blockId()
+ currency()
+ description()
+ metadata().ifPresent { it.validate() }
+ validated = true
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of
+ * [AddExpirationChangeCreditLedgerEntryRequestParams].
+ *
+ * The following fields are required:
+ * ```java
+ * .entryType()
+ * .expiryDate()
+ * .targetExpiryDate()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [AddExpirationChangeCreditLedgerEntryRequestParams]. */
+ class Builder internal constructor() {
+
+ private var entryType: JsonField? = null
+ private var expiryDate: JsonField? = null
+ private var targetExpiryDate: JsonField? = null
+ private var amount: JsonField = JsonMissing.of()
+ private var blockId: JsonField = JsonMissing.of()
+ private var currency: JsonField = JsonMissing.of()
+ private var description: JsonField = JsonMissing.of()
+ private var metadata: JsonField = JsonMissing.of()
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(
+ addExpirationChangeCreditLedgerEntryRequestParams:
+ AddExpirationChangeCreditLedgerEntryRequestParams
+ ) = apply {
+ entryType = addExpirationChangeCreditLedgerEntryRequestParams.entryType
+ expiryDate = addExpirationChangeCreditLedgerEntryRequestParams.expiryDate
+ targetExpiryDate =
+ addExpirationChangeCreditLedgerEntryRequestParams.targetExpiryDate
+ amount = addExpirationChangeCreditLedgerEntryRequestParams.amount
+ blockId = addExpirationChangeCreditLedgerEntryRequestParams.blockId
+ currency = addExpirationChangeCreditLedgerEntryRequestParams.currency
+ description = addExpirationChangeCreditLedgerEntryRequestParams.description
+ metadata = addExpirationChangeCreditLedgerEntryRequestParams.metadata
+ additionalProperties =
+ addExpirationChangeCreditLedgerEntryRequestParams.additionalProperties
+ .toMutableMap()
+ }
+
+ fun entryType(entryType: EntryType) = entryType(JsonField.of(entryType))
+
+ fun entryType(entryType: JsonField) = apply { this.entryType = entryType }
+
+ /** An ISO 8601 format date that identifies the origination credit block to expire */
+ fun expiryDate(expiryDate: OffsetDateTime?) =
+ expiryDate(JsonField.ofNullable(expiryDate))
+
+ /** An ISO 8601 format date that identifies the origination credit block to expire */
+ fun expiryDate(expiryDate: Optional) =
+ expiryDate(expiryDate.orElse(null))
+
+ /** An ISO 8601 format date that identifies the origination credit block to expire */
+ fun expiryDate(expiryDate: JsonField) = apply {
+ this.expiryDate = expiryDate
+ }
+
+ /**
+ * A future date (specified in YYYY-MM-DD format) used for expiration change, denoting
+ * when credits transferred (as part of a partial block expiration) should expire.
+ */
+ fun targetExpiryDate(targetExpiryDate: LocalDate) =
+ targetExpiryDate(JsonField.of(targetExpiryDate))
+
+ /**
+ * A future date (specified in YYYY-MM-DD format) used for expiration change, denoting
+ * when credits transferred (as part of a partial block expiration) should expire.
+ */
+ fun targetExpiryDate(targetExpiryDate: JsonField) = apply {
+ this.targetExpiryDate = targetExpiryDate
+ }
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ fun amount(amount: Double?) = amount(JsonField.ofNullable(amount))
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ fun amount(amount: Double) = amount(amount as Double?)
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228
+ fun amount(amount: Optional) = amount(amount.orElse(null) as Double?)
+
+ /**
+ * The number of credits to effect. Note that this is required for increment, decrement,
+ * void, or undo operations.
+ */
+ fun amount(amount: JsonField) = apply { this.amount = amount }
+
+ /**
+ * The ID of the block affected by an expiration_change, used to differentiate between
+ * multiple blocks with the same `expiry_date`.
+ */
+ fun blockId(blockId: String?) = blockId(JsonField.ofNullable(blockId))
+
+ /**
+ * The ID of the block affected by an expiration_change, used to differentiate between
+ * multiple blocks with the same `expiry_date`.
+ */
+ fun blockId(blockId: Optional) = blockId(blockId.orElse(null))
+
+ /**
+ * The ID of the block affected by an expiration_change, used to differentiate between
+ * multiple blocks with the same `expiry_date`.
+ */
+ fun blockId(blockId: JsonField) = apply { this.blockId = blockId }
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a
+ * real-world currency, it must match the customer's invoicing currency.
+ */
+ fun currency(currency: String?) = currency(JsonField.ofNullable(currency))
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a
+ * real-world currency, it must match the customer's invoicing currency.
+ */
+ fun currency(currency: Optional) = currency(currency.orElse(null))
+
+ /**
+ * The currency or custom pricing unit to use for this ledger entry. If this is a
+ * real-world currency, it must match the customer's invoicing currency.
+ */
+ fun currency(currency: JsonField) = apply { this.currency = currency }
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(description: String?) = description(JsonField.ofNullable(description))
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(description: Optional) = description(description.orElse(null))
+
+ /**
+ * Optional metadata that can be specified when adding ledger results via the API. For
+ * example, this can be used to note an increment refers to trial credits, or for noting
+ * corrections as a result of an incident, etc.
+ */
+ fun description(description: JsonField) = apply {
+ this.description = description
+ }
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by
+ * setting `metadata` to `null`.
+ */
+ fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata))
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by
+ * setting `metadata` to `null`.
+ */
+ fun metadata(metadata: Optional) = metadata(metadata.orElse(null))
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by
+ * setting `metadata` to `null`.
+ */
+ fun metadata(metadata: JsonField) = apply { this.metadata = metadata }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ fun build(): AddExpirationChangeCreditLedgerEntryRequestParams =
+ AddExpirationChangeCreditLedgerEntryRequestParams(
+ checkRequired("entryType", entryType),
+ checkRequired("expiryDate", expiryDate),
+ checkRequired("targetExpiryDate", targetExpiryDate),
+ amount,
+ blockId,
+ currency,
+ description,
+ metadata,
+ additionalProperties.toImmutable(),
+ )
+ }
+
+ class EntryType @JsonCreator private constructor(private val value: JsonField) :
+ Enum {
+
+ /**
+ * Returns this class instance's raw value.
+ *
+ * This is usually only useful if this instance was deserialized from data that doesn't
+ * match any known member, and you want to know that value. For example, if the SDK is
+ * on an older version than the API, then the API may respond with new members that the
+ * SDK is unaware of.
+ */
+ @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value
+
+ companion object {
+
+ @JvmField val EXPIRATION_CHANGE = of("expiration_change")
+
+ @JvmStatic fun of(value: String) = EntryType(JsonField.of(value))
+ }
+
+ /** An enum containing [EntryType]'s known values. */
+ enum class Known {
+ EXPIRATION_CHANGE
+ }
+
+ /**
+ * An enum containing [EntryType]'s known values, as well as an [_UNKNOWN] member.
+ *
+ * An instance of [EntryType] can contain an unknown value in a couple of cases:
+ * - It was deserialized from data that doesn't match any known member. For example, if
+ * the SDK is on an older version than the API, then the API may respond with new
+ * members that the SDK is unaware of.
+ * - It was constructed with an arbitrary value using the [of] method.
+ */
+ enum class Value {
+ EXPIRATION_CHANGE,
+ /**
+ * An enum member indicating that [EntryType] was instantiated with an unknown
+ * value.
+ */
+ _UNKNOWN,
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value, or
+ * [Value._UNKNOWN] if the class was instantiated with an unknown value.
+ *
+ * Use the [known] method instead if you're certain the value is always known or if you
+ * want to throw for the unknown case.
+ */
+ fun value(): Value =
+ when (this) {
+ EXPIRATION_CHANGE -> Value.EXPIRATION_CHANGE
+ else -> Value._UNKNOWN
+ }
+
+ /**
+ * Returns an enum member corresponding to this class instance's value.
+ *
+ * Use the [value] method instead if you're uncertain the value is always known and
+ * don't want to throw for the unknown case.
+ *
+ * @throws OrbInvalidDataException if this class instance's value is a not a known
+ * member.
+ */
+ fun known(): Known =
+ when (this) {
+ EXPIRATION_CHANGE -> Known.EXPIRATION_CHANGE
+ else -> throw OrbInvalidDataException("Unknown EntryType: $value")
+ }
+
+ /**
+ * Returns this class instance's primitive wire representation.
+ *
+ * This differs from the [toString] method because that method is primarily for
+ * debugging and generally doesn't throw.
+ *
+ * @throws OrbInvalidDataException if this class instance's value does not have the
+ * expected primitive type.
+ */
+ fun asString(): String =
+ _value().asString().orElseThrow { OrbInvalidDataException("Value is not a String") }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is EntryType && value == other.value /* spotless:on */
+ }
+
+ override fun hashCode() = value.hashCode()
+
+ override fun toString() = value.toString()
+ }
+
+ /**
+ * User-specified key/value pairs for the resource. Individual keys can be removed by
+ * setting the value to `null`, and the entire metadata mapping can be cleared by setting
+ * `metadata` to `null`.
+ */
+ @NoAutoDetect
+ class Metadata
+ @JsonCreator
+ private constructor(
+ @JsonAnySetter
+ private val additionalProperties: Map = immutableEmptyMap()
+ ) {
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map = additionalProperties
+
+ private var validated: Boolean = false
+
+ fun validate(): Metadata = apply {
+ if (validated) {
+ return@apply
+ }
+
+ validated = true
+ }
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /** Returns a mutable builder for constructing an instance of [Metadata]. */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Metadata]. */
+ class Builder internal constructor() {
+
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(metadata: Metadata) = apply {
+ additionalProperties = metadata.additionalProperties.toMutableMap()
+ }
+
+ fun additionalProperties(additionalProperties: Map