diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94046873..ebbaa260 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,8 +12,6 @@ jobs: lint: name: lint runs-on: ubuntu-latest - - steps: - uses: actions/checkout@v4 @@ -34,7 +32,6 @@ jobs: test: name: test runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 diff --git a/.release-please-manifest.json b/.release-please-manifest.json index d940b600..87d3d84c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.55.0" + ".": "0.56.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 51e113d8..7d6c32c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,36 @@ # Changelog +## 0.56.0 (2025-04-09) + +Full Changelog: [v0.55.0...v0.56.0](https://github.com/orbcorp/orb-java/compare/v0.55.0...v0.56.0) + +### Features + +* **client:** make pagination robust to missing data ([bf8c89e](https://github.com/orbcorp/orb-java/commit/bf8c89e3e5148a99afd9b9e5f211dd3002c2d88e)) +* **client:** support setting base URL via env var ([#397](https://github.com/orbcorp/orb-java/issues/397)) ([4ac10b3](https://github.com/orbcorp/orb-java/commit/4ac10b3cf164a76c7da1e0c5fc12aeec0338d0d3)) + + +### Bug Fixes + +* **client:** bump to better jackson version ([#400](https://github.com/orbcorp/orb-java/issues/400)) ([b9c0a00](https://github.com/orbcorp/orb-java/commit/b9c0a00b0181bfbaf7a9a2f670b98000dfa4b996)) + + +### Chores + +* **internal:** expand CI branch coverage ([#399](https://github.com/orbcorp/orb-java/issues/399)) ([17d8399](https://github.com/orbcorp/orb-java/commit/17d8399351f5affa7a89fbc79df9e88c732c1330)) +* **internal:** reduce CI branch coverage ([06a8495](https://github.com/orbcorp/orb-java/commit/06a84957b55d697cbb0bd3a8c6f9a4a02f95d90c)) + + +### Documentation + +* add comments for page methods ([bf8c89e](https://github.com/orbcorp/orb-java/commit/bf8c89e3e5148a99afd9b9e5f211dd3002c2d88e)) + + +### Refactors + +* **client:** deduplicate page response classes ([#401](https://github.com/orbcorp/orb-java/issues/401)) ([bf8c89e](https://github.com/orbcorp/orb-java/commit/bf8c89e3e5148a99afd9b9e5f211dd3002c2d88e)) +* **client:** migrate pages to builder pattern ([#402](https://github.com/orbcorp/orb-java/issues/402)) ([bbcd954](https://github.com/orbcorp/orb-java/commit/bbcd9545d5fad36f5b241ecc5515b44454533265)) + ## 0.55.0 (2025-04-08) Full Changelog: [v0.54.0...v0.55.0](https://github.com/orbcorp/orb-java/compare/v0.54.0...v0.55.0) diff --git a/README.md b/README.md index 9eb20414..6bb662be 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-java)](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.55.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-java)](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.56.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.55.0") +implementation("com.withorb.api:orb-java:0.56.0") ``` ### Maven @@ -28,7 +28,7 @@ implementation("com.withorb.api:orb-java:0.55.0") com.withorb.api orb-java - 0.55.0 + 0.56.0 ``` @@ -46,7 +46,7 @@ import com.withorb.api.client.okhttp.OrbOkHttpClient; import com.withorb.api.models.Customer; import com.withorb.api.models.CustomerCreateParams; -// Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables +// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables OrbClient client = OrbOkHttpClient.fromEnv(); CustomerCreateParams params = CustomerCreateParams.builder() @@ -64,7 +64,7 @@ Configure the client using environment variables: import com.withorb.api.client.OrbClient; import com.withorb.api.client.okhttp.OrbOkHttpClient; -// Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables +// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables OrbClient client = OrbOkHttpClient.fromEnv(); ``` @@ -86,7 +86,7 @@ import com.withorb.api.client.OrbClient; import com.withorb.api.client.okhttp.OrbOkHttpClient; OrbClient client = OrbOkHttpClient.builder() - // Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables + // Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables .fromEnv() .apiKey("My API Key") .build(); @@ -94,10 +94,11 @@ OrbClient client = OrbOkHttpClient.builder() See this table for the available options: -| Setter | Environment variable | Required | Default value | -| --------------- | -------------------- | -------- | ------------- | -| `apiKey` | `ORB_API_KEY` | true | - | -| `webhookSecret` | `ORB_WEBHOOK_SECRET` | false | - | +| Setter | Environment variable | Required | Default value | +| --------------- | -------------------- | -------- | ------------------------------ | +| `apiKey` | `ORB_API_KEY` | true | - | +| `webhookSecret` | `ORB_WEBHOOK_SECRET` | false | - | +| `baseUrl` | `ORB_BASE_URL` | true | `"https://api.withorb.com/v1"` | > [!TIP] > Don't create more than one client in the same application. Each client has a connection pool and @@ -128,7 +129,7 @@ import com.withorb.api.models.Customer; import com.withorb.api.models.CustomerCreateParams; import java.util.concurrent.CompletableFuture; -// Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables +// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables OrbClient client = OrbOkHttpClient.fromEnv(); CustomerCreateParams params = CustomerCreateParams.builder() @@ -147,7 +148,7 @@ import com.withorb.api.models.Customer; import com.withorb.api.models.CustomerCreateParams; import java.util.concurrent.CompletableFuture; -// Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables +// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables OrbClientAsync client = OrbOkHttpClientAsync.fromEnv(); CustomerCreateParams params = CustomerCreateParams.builder() diff --git a/build.gradle.kts b/build.gradle.kts index f2cb58af..3973ccca 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,4 @@ allprojects { group = "com.withorb.api" - version = "0.55.0" // x-release-please-version + version = "0.56.0" // x-release-please-version } 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 e3b5ce1e..458d3da8 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 @@ -29,14 +29,10 @@ class OrbOkHttpClient private constructor() { class Builder internal constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() - private var baseUrl: String = ClientOptions.PRODUCTION_URL private var timeout: Timeout = Timeout.default() private var proxy: Proxy? = null - fun baseUrl(baseUrl: String) = apply { - clientOptions.baseUrl(baseUrl) - this.baseUrl = baseUrl - } + fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) } /** * Whether to throw an exception if any of the Jackson versions detected at runtime are @@ -177,7 +173,7 @@ class OrbOkHttpClient private constructor() { clientOptions .httpClient( OkHttpClient.builder() - .baseUrl(baseUrl) + .baseUrl(clientOptions.baseUrl()) .timeout(timeout) .proxy(proxy) .build() 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 ef9cbe65..f8d51c09 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 @@ -29,14 +29,10 @@ class OrbOkHttpClientAsync private constructor() { class Builder internal constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() - private var baseUrl: String = ClientOptions.PRODUCTION_URL private var timeout: Timeout = Timeout.default() private var proxy: Proxy? = null - fun baseUrl(baseUrl: String) = apply { - clientOptions.baseUrl(baseUrl) - this.baseUrl = baseUrl - } + fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) } /** * Whether to throw an exception if any of the Jackson versions detected at runtime are @@ -177,7 +173,7 @@ class OrbOkHttpClientAsync private constructor() { clientOptions .httpClient( OkHttpClient.builder() - .baseUrl(baseUrl) + .baseUrl(clientOptions.baseUrl()) .timeout(timeout) .proxy(proxy) .build() diff --git a/orb-java-core/build.gradle.kts b/orb-java-core/build.gradle.kts index 8a8d05d5..6955eac0 100644 --- a/orb-java-core/build.gradle.kts +++ b/orb-java-core/build.gradle.kts @@ -17,14 +17,14 @@ configurations.all { } dependencies { - api("com.fasterxml.jackson.core:jackson-core:2.18.1") - api("com.fasterxml.jackson.core:jackson-databind:2.18.1") + api("com.fasterxml.jackson.core:jackson-core:2.18.2") + api("com.fasterxml.jackson.core:jackson-databind:2.18.2") 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") - implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.1") - implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.1") + implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.2") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.2") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.2") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.2") implementation("org.apache.httpcomponents.core5:httpcore5:5.2.4") implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1") 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 82fe7ba1..df5773f1 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 @@ -47,6 +47,7 @@ internal fun checkMaxLength(name: String, value: String, maxLength: Int): String internal fun checkJacksonVersionCompatibility() { val incompatibleJacksonVersions = RUNTIME_JACKSON_VERSIONS.mapNotNull { + val badVersionReason = BAD_JACKSON_VERSIONS[it.toString()] when { it.majorVersion != MINIMUM_JACKSON_VERSION.majorVersion -> it to "incompatible major version" @@ -55,6 +56,7 @@ internal fun checkJacksonVersionCompatibility() { it.minorVersion == MINIMUM_JACKSON_VERSION.minorVersion && it.patchLevel < MINIMUM_JACKSON_VERSION.patchLevel -> it to "patch version too low" + badVersionReason != null -> it to badVersionReason else -> null } } @@ -77,6 +79,8 @@ Double-check that you are depending on compatible Jackson versions. } private val MINIMUM_JACKSON_VERSION: Version = VersionUtil.parseVersion("2.13.4", null, null) +private val BAD_JACKSON_VERSIONS: Map = + mapOf("2.18.1" to "due to https://github.com/FasterXML/jackson-databind/issues/4639") private val RUNTIME_JACKSON_VERSIONS: List = listOf( com.fasterxml.jackson.core.json.PackageVersion.VERSION, 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 8fc681ad..33a56193 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 @@ -197,7 +197,10 @@ private constructor( fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) } + fun baseUrl(): String = baseUrl + fun fromEnv() = apply { + System.getenv("ORB_BASE_URL")?.let { baseUrl(it) } System.getenv("ORB_API_KEY")?.let { apiKey(it) } System.getenv("ORB_WEBHOOK_SECRET")?.let { webhookSecret(it) } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt index 88911b52..e34c1eaf 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt @@ -2,67 +2,40 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.AlertService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of alerts within Orb. - * - * The request must specify one of `customer_id`, `external_customer_id`, or `subscription_id`. - * - * If querying by subscripion_id, the endpoint will return the subscription level alerts as well as - * the plan level alerts associated with the subscription. - * - * The list of alerts is ordered starting from the most recently created alert. This endpoint - * follows Orb's [standardized pagination format](/api-reference/pagination). - */ +/** @see [AlertService.list] */ class AlertListPage private constructor( - private val alertsService: AlertService, + private val service: AlertService, private val params: AlertListParams, - private val response: Response, + private val response: AlertListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is AlertListPage && alertsService == other.alertsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(alertsService, params, response) /* spotless:on */ - - override fun toString() = - "AlertListPage{alertsService=$alertsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [AlertListPageResponse], but gracefully handles missing data. + * + * @see [AlertListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [AlertListPageResponse], but gracefully handles missing data. + * + * @see [AlertListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -70,138 +43,86 @@ private constructor( } return Optional.of( - AlertListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { alertsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(alertsService: AlertService, params: AlertListParams, response: Response) = - AlertListPage(alertsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The parameters that were used to request this page. */ + fun params(): AlertListParams = params - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + /** The response that this page was parsed from. */ + fun response(): AlertListPageResponse = response - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) + fun toBuilder() = Builder().from(this) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [AlertListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [AlertListPage]. */ + class Builder internal constructor() { - companion object { + private var service: AlertService? = null + private var params: AlertListParams? = null + private var response: AlertListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [AlertListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(alertListPage: AlertListPage) = apply { + service = alertListPage.service + params = alertListPage.params + response = alertListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: AlertService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: AlertListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: AlertListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [AlertListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AlertListPage = + AlertListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: AlertListPage) : Iterable { @@ -222,4 +143,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AlertListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "AlertListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt index b8f17466..8a37ce8d 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.AlertServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,50 +11,32 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of alerts within Orb. - * - * The request must specify one of `customer_id`, `external_customer_id`, or `subscription_id`. - * - * If querying by subscripion_id, the endpoint will return the subscription level alerts as well as - * the plan level alerts associated with the subscription. - * - * The list of alerts is ordered starting from the most recently created alert. This endpoint - * follows Orb's [standardized pagination format](/api-reference/pagination). - */ +/** @see [AlertServiceAsync.list] */ class AlertListPageAsync private constructor( - private val alertsService: AlertServiceAsync, + private val service: AlertServiceAsync, private val params: AlertListParams, - private val response: Response, + private val response: AlertListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is AlertListPageAsync && alertsService == other.alertsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(alertsService, params, response) /* spotless:on */ - - override fun toString() = - "AlertListPageAsync{alertsService=$alertsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [AlertListPageResponse], but gracefully handles missing data. + * + * @see [AlertListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [AlertListPageResponse], but gracefully handles missing data. + * + * @see [AlertListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -71,140 +44,89 @@ private constructor( } return Optional.of( - AlertListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { alertsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(alertsService: AlertServiceAsync, params: AlertListParams, response: Response) = - AlertListPageAsync(alertsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): AlertListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** The response that this page was parsed from. */ + fun response(): AlertListPageResponse = response - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [AlertListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [AlertListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: AlertServiceAsync? = null + private var params: AlertListParams? = null + private var response: AlertListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [AlertListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(alertListPageAsync: AlertListPageAsync) = apply { + service = alertListPageAsync.service + params = alertListPageAsync.params + response = alertListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: AlertServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: AlertListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: AlertListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [AlertListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AlertListPageAsync = + AlertListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: AlertListPageAsync) { @@ -232,4 +154,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AlertListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "AlertListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageResponse.kt new file mode 100644 index 00000000..76540e99 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageResponse.kt @@ -0,0 +1,231 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class AlertListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [AlertListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AlertListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(alertListPageResponse: AlertListPageResponse) = apply { + data = alertListPageResponse.data.map { it.toMutableList() } + paginationMetadata = alertListPageResponse.paginationMetadata + additionalProperties = alertListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Alert] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Alert) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [AlertListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AlertListPageResponse = + AlertListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): AlertListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AlertListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AlertListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt index 60451764..8fd79bed 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt @@ -2,63 +2,40 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.CouponService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all coupons for an account in a list format. - * - * The list of coupons is ordered starting from the most recently created coupon. The response also - * includes `pagination_metadata`, which lets the caller retrieve the next page of results if they - * exist. More information about pagination can be found in the Pagination-metadata schema. - */ +/** @see [CouponService.list] */ class CouponListPage private constructor( - private val couponsService: CouponService, + private val service: CouponService, private val params: CouponListParams, - private val response: Response, + private val response: CouponListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CouponListPage && couponsService == other.couponsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(couponsService, params, response) /* spotless:on */ - - override fun toString() = - "CouponListPage{couponsService=$couponsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CouponListPageResponse], but gracefully handles missing data. + * + * @see [CouponListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CouponListPageResponse], but gracefully handles missing data. + * + * @see [CouponListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -66,138 +43,86 @@ private constructor( } return Optional.of( - CouponListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { couponsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(couponsService: CouponService, params: CouponListParams, response: Response) = - CouponListPage(couponsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The parameters that were used to request this page. */ + fun params(): CouponListParams = params - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + /** The response that this page was parsed from. */ + fun response(): CouponListPageResponse = response - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) + fun toBuilder() = Builder().from(this) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [CouponListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [CouponListPage]. */ + class Builder internal constructor() { - companion object { + private var service: CouponService? = null + private var params: CouponListParams? = null + private var response: CouponListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [CouponListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(couponListPage: CouponListPage) = apply { + service = couponListPage.service + params = couponListPage.params + response = couponListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: CouponService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CouponListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: CouponListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [CouponListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CouponListPage = + CouponListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CouponListPage) : Iterable { @@ -218,4 +143,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CouponListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "CouponListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt index 7f1baec1..6486b6da 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.CouponServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,46 +11,32 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all coupons for an account in a list format. - * - * The list of coupons is ordered starting from the most recently created coupon. The response also - * includes `pagination_metadata`, which lets the caller retrieve the next page of results if they - * exist. More information about pagination can be found in the Pagination-metadata schema. - */ +/** @see [CouponServiceAsync.list] */ class CouponListPageAsync private constructor( - private val couponsService: CouponServiceAsync, + private val service: CouponServiceAsync, private val params: CouponListParams, - private val response: Response, + private val response: CouponListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CouponListPageAsync && couponsService == other.couponsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(couponsService, params, response) /* spotless:on */ - - override fun toString() = - "CouponListPageAsync{couponsService=$couponsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CouponListPageResponse], but gracefully handles missing data. + * + * @see [CouponListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CouponListPageResponse], but gracefully handles missing data. + * + * @see [CouponListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -67,140 +44,89 @@ private constructor( } return Optional.of( - CouponListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { couponsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(couponsService: CouponServiceAsync, params: CouponListParams, response: Response) = - CouponListPageAsync(couponsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): CouponListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** The response that this page was parsed from. */ + fun response(): CouponListPageResponse = response - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [CouponListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [CouponListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: CouponServiceAsync? = null + private var params: CouponListParams? = null + private var response: CouponListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [CouponListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(couponListPageAsync: CouponListPageAsync) = apply { + service = couponListPageAsync.service + params = couponListPageAsync.params + response = couponListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: CouponServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CouponListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: CouponListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [CouponListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CouponListPageAsync = + CouponListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CouponListPageAsync) { @@ -228,4 +154,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CouponListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CouponListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageResponse.kt new file mode 100644 index 00000000..77a5bcc3 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageResponse.kt @@ -0,0 +1,231 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class CouponListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [CouponListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CouponListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(couponListPageResponse: CouponListPageResponse) = apply { + data = couponListPageResponse.data.map { it.toMutableList() } + paginationMetadata = couponListPageResponse.paginationMetadata + additionalProperties = couponListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Coupon] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Coupon) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [CouponListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CouponListPageResponse = + CouponListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CouponListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CouponListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CouponListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt index b2595f7d..77f17471 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt @@ -2,62 +2,40 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.coupons.SubscriptionService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all subscriptions that have redeemed a given coupon as a - * [paginated](/api-reference/pagination) list, ordered starting from the most recently created - * subscription. For a full discussion of the subscription resource, see - * [Subscription](/core-concepts#subscription). - */ +/** @see [SubscriptionService.list] */ class CouponSubscriptionListPage private constructor( - private val subscriptionsService: SubscriptionService, + private val service: SubscriptionService, private val params: CouponSubscriptionListParams, - private val response: Response, + private val response: Subscriptions, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CouponSubscriptionListPage && subscriptionsService == other.subscriptionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionsService, params, response) /* spotless:on */ - - override fun toString() = - "CouponSubscriptionListPage{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -65,144 +43,87 @@ private constructor( } return Optional.of( - CouponSubscriptionListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { subscriptionsService.list(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - subscriptionsService: SubscriptionService, - params: CouponSubscriptionListParams, - response: Response, - ) = CouponSubscriptionListPage(subscriptionsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() + /** The parameters that were used to request this page. */ + fun params(): CouponSubscriptionListParams = params - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The response that this page was parsed from. */ + fun response(): Subscriptions = response - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + fun toBuilder() = Builder().from(this) - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [CouponSubscriptionListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [CouponSubscriptionListPage]. */ + class Builder internal constructor() { - companion object { + private var service: SubscriptionService? = null + private var params: CouponSubscriptionListParams? = null + private var response: Subscriptions? = null - /** - * Returns a mutable builder for constructing an instance of - * [CouponSubscriptionListPage]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(couponSubscriptionListPage: CouponSubscriptionListPage) = apply { + service = couponSubscriptionListPage.service + params = couponSubscriptionListPage.params + response = couponSubscriptionListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: SubscriptionService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CouponSubscriptionListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: Subscriptions) = apply { this.response = response } + + /** + * Returns an immutable instance of [CouponSubscriptionListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CouponSubscriptionListPage = + CouponSubscriptionListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CouponSubscriptionListPage) : Iterable { @@ -223,4 +144,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CouponSubscriptionListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CouponSubscriptionListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt index 86a187d6..47417e21 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.coupons.SubscriptionServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,45 +11,32 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all subscriptions that have redeemed a given coupon as a - * [paginated](/api-reference/pagination) list, ordered starting from the most recently created - * subscription. For a full discussion of the subscription resource, see - * [Subscription](/core-concepts#subscription). - */ +/** @see [SubscriptionServiceAsync.list] */ class CouponSubscriptionListPageAsync private constructor( - private val subscriptionsService: SubscriptionServiceAsync, + private val service: SubscriptionServiceAsync, private val params: CouponSubscriptionListParams, - private val response: Response, + private val response: Subscriptions, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CouponSubscriptionListPageAsync && subscriptionsService == other.subscriptionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionsService, params, response) /* spotless:on */ - - override fun toString() = - "CouponSubscriptionListPageAsync{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -66,146 +44,91 @@ private constructor( } return Optional.of( - CouponSubscriptionListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { subscriptionsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - subscriptionsService: SubscriptionServiceAsync, - params: CouponSubscriptionListParams, - response: Response, - ) = CouponSubscriptionListPageAsync(subscriptionsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** The parameters that were used to request this page. */ + fun params(): CouponSubscriptionListParams = params - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" - - companion object { + /** The response that this page was parsed from. */ + fun response(): Subscriptions = response - /** - * Returns a mutable builder for constructing an instance of - * [CouponSubscriptionListPageAsync]. - */ - @JvmStatic fun builder() = Builder() - } - - class Builder { + fun toBuilder() = Builder().from(this) - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) + companion object { - fun data(data: JsonField>) = apply { this.data = data } + /** + * Returns a mutable builder for constructing an instance of + * [CouponSubscriptionListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) + /** A builder for [CouponSubscriptionListPageAsync]. */ + class Builder internal constructor() { - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } + private var service: SubscriptionServiceAsync? = null + private var params: CouponSubscriptionListParams? = null + private var response: Subscriptions? = null - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + @JvmSynthetic + internal fun from(couponSubscriptionListPageAsync: CouponSubscriptionListPageAsync) = + apply { + service = couponSubscriptionListPageAsync.service + params = couponSubscriptionListPageAsync.params + response = couponSubscriptionListPageAsync.response } - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: SubscriptionServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CouponSubscriptionListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: Subscriptions) = apply { this.response = response } + + /** + * Returns an immutable instance of [CouponSubscriptionListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CouponSubscriptionListPageAsync = + CouponSubscriptionListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CouponSubscriptionListPageAsync) { @@ -233,4 +156,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CouponSubscriptionListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CouponSubscriptionListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt index 7a20c009..cbbd4f40 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt @@ -2,61 +2,40 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.CreditNoteService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * Get a paginated list of CreditNotes. Users can also filter by customer_id, subscription_id, or - * external_customer_id. The credit notes will be returned in reverse chronological order by - * `creation_time`. - */ +/** @see [CreditNoteService.list] */ class CreditNoteListPage private constructor( - private val creditNotesService: CreditNoteService, + private val service: CreditNoteService, private val params: CreditNoteListParams, - private val response: Response, + private val response: CreditNoteListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CreditNoteListPage && creditNotesService == other.creditNotesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(creditNotesService, params, response) /* spotless:on */ - - override fun toString() = - "CreditNoteListPage{creditNotesService=$creditNotesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data. + * + * @see [CreditNoteListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data. + * + * @see [CreditNoteListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -64,141 +43,86 @@ private constructor( } return Optional.of( - CreditNoteListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { creditNotesService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - creditNotesService: CreditNoteService, - params: CreditNoteListParams, - response: Response, - ) = CreditNoteListPage(creditNotesService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() + /** The parameters that were used to request this page. */ + fun params(): CreditNoteListParams = params - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The response that this page was parsed from. */ + fun response(): CreditNoteListPageResponse = response - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + fun toBuilder() = Builder().from(this) - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [CreditNoteListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [CreditNoteListPage]. */ + class Builder internal constructor() { - companion object { + private var service: CreditNoteService? = null + private var params: CreditNoteListParams? = null + private var response: CreditNoteListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [CreditNoteListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(creditNoteListPage: CreditNoteListPage) = apply { + service = creditNoteListPage.service + params = creditNoteListPage.params + response = creditNoteListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: CreditNoteService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CreditNoteListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: CreditNoteListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [CreditNoteListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CreditNoteListPage = + CreditNoteListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CreditNoteListPage) : Iterable { @@ -219,4 +143,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CreditNoteListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CreditNoteListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt index fe23817a..104920cc 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.CreditNoteServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,44 +11,32 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * Get a paginated list of CreditNotes. Users can also filter by customer_id, subscription_id, or - * external_customer_id. The credit notes will be returned in reverse chronological order by - * `creation_time`. - */ +/** @see [CreditNoteServiceAsync.list] */ class CreditNoteListPageAsync private constructor( - private val creditNotesService: CreditNoteServiceAsync, + private val service: CreditNoteServiceAsync, private val params: CreditNoteListParams, - private val response: Response, + private val response: CreditNoteListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CreditNoteListPageAsync && creditNotesService == other.creditNotesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(creditNotesService, params, response) /* spotless:on */ - - override fun toString() = - "CreditNoteListPageAsync{creditNotesService=$creditNotesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data. + * + * @see [CreditNoteListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data. + * + * @see [CreditNoteListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -65,145 +44,89 @@ private constructor( } return Optional.of( - CreditNoteListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { creditNotesService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - creditNotesService: CreditNoteServiceAsync, - params: CreditNoteListParams, - response: Response, - ) = CreditNoteListPageAsync(creditNotesService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): CreditNoteListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** The response that this page was parsed from. */ + fun response(): CreditNoteListPageResponse = response - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [CreditNoteListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [CreditNoteListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: CreditNoteServiceAsync? = null + private var params: CreditNoteListParams? = null + private var response: CreditNoteListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [CreditNoteListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(creditNoteListPageAsync: CreditNoteListPageAsync) = apply { + service = creditNoteListPageAsync.service + params = creditNoteListPageAsync.params + response = creditNoteListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: CreditNoteServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CreditNoteListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: CreditNoteListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [CreditNoteListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CreditNoteListPageAsync = + CreditNoteListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CreditNoteListPageAsync) { @@ -231,4 +154,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CreditNoteListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CreditNoteListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageResponse.kt new file mode 100644 index 00000000..c9e73d4b --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageResponse.kt @@ -0,0 +1,231 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class CreditNoteListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [CreditNoteListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CreditNoteListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(creditNoteListPageResponse: CreditNoteListPageResponse) = apply { + data = creditNoteListPageResponse.data.map { it.toMutableList() } + paginationMetadata = creditNoteListPageResponse.paginationMetadata + additionalProperties = creditNoteListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [CreditNote] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: CreditNote) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [CreditNoteListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CreditNoteListPageResponse = + CreditNoteListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CreditNoteListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CreditNoteListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CreditNoteListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt index 1885e264..a313acd6 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt @@ -2,82 +2,43 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.customers.BalanceTransactionService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * ## The customer balance - * - * The customer balance is an amount in the customer's currency, which Orb automatically applies to - * subsequent invoices. This balance can be adjusted manually via Orb's webapp on the customer - * details page. You can use this balance to provide a fixed mid-period credit to the customer. - * Commonly, this is done due to system downtime/SLA violation, or an adhoc adjustment discussed - * with the customer. - * - * If the balance is a positive value at the time of invoicing, it represents that the customer has - * credit that should be used to offset the amount due on the next issued invoice. In this case, Orb - * will automatically reduce the next invoice by the balance amount, and roll over any remaining - * balance if the invoice is fully discounted. - * - * If the balance is a negative value at the time of invoicing, Orb will increase the invoice's - * amount due with a positive adjustment, and reset the balance to 0. - * - * This endpoint retrieves all customer balance transactions in reverse chronological order for a - * single customer, providing a complete audit trail of all adjustments and invoice applications. - * - * ## Eligibility - * - * The customer balance can only be applied to invoices or adjusted manually if invoices are not - * synced to a separate invoicing provider. If a payment gateway such as Stripe is used, the balance - * will be applied to the invoice before forwarding payment to the gateway. - */ +/** @see [BalanceTransactionService.list] */ class CustomerBalanceTransactionListPage private constructor( - private val balanceTransactionsService: BalanceTransactionService, + private val service: BalanceTransactionService, private val params: CustomerBalanceTransactionListParams, - private val response: Response, + private val response: CustomerBalanceTransactionListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerBalanceTransactionListPage && balanceTransactionsService == other.balanceTransactionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(balanceTransactionsService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerBalanceTransactionListPage{balanceTransactionsService=$balanceTransactionsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerBalanceTransactionListPageResponse], but gracefully handles missing + * data. + * + * @see [CustomerBalanceTransactionListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerBalanceTransactionListPageResponse], but gracefully handles missing + * data. + * + * @see [CustomerBalanceTransactionListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -85,150 +46,91 @@ private constructor( } return Optional.of( - CustomerBalanceTransactionListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { balanceTransactionsService.list(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): CustomerBalanceTransactionListParams = params - @JvmStatic - fun of( - balanceTransactionsService: BalanceTransactionService, - params: CustomerBalanceTransactionListParams, - response: Response, - ) = CustomerBalanceTransactionListPage(balanceTransactionsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): CustomerBalanceTransactionListPageResponse = response - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun toBuilder() = Builder().from(this) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + companion object { - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** + * Returns a mutable builder for constructing an instance of + * [CustomerBalanceTransactionListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** A builder for [CustomerBalanceTransactionListPage]. */ + class Builder internal constructor() { - fun toBuilder() = Builder().from(this) + private var service: BalanceTransactionService? = null + private var params: CustomerBalanceTransactionListParams? = null + private var response: CustomerBalanceTransactionListPageResponse? = null - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + @JvmSynthetic + internal fun from(customerBalanceTransactionListPage: CustomerBalanceTransactionListPage) = + apply { + service = customerBalanceTransactionListPage.service + params = customerBalanceTransactionListPage.params + response = customerBalanceTransactionListPage.response } - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + fun service(service: BalanceTransactionService) = apply { this.service = service } - companion object { + /** The parameters that were used to request this page. */ + fun params(params: CustomerBalanceTransactionListParams) = apply { this.params = params } - /** - * Returns a mutable builder for constructing an instance of - * [CustomerBalanceTransactionListPage]. - */ - @JvmStatic fun builder() = Builder() + /** The response that this page was parsed from. */ + fun response(response: CustomerBalanceTransactionListPageResponse) = apply { + this.response = response } - class Builder { - - private var data: JsonField> = - JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [CustomerBalanceTransactionListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerBalanceTransactionListPage = + CustomerBalanceTransactionListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerBalanceTransactionListPage) : @@ -250,4 +152,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerBalanceTransactionListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerBalanceTransactionListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt index d25ae282..6214987f 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.customers.BalanceTransactionServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,65 +11,35 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * ## The customer balance - * - * The customer balance is an amount in the customer's currency, which Orb automatically applies to - * subsequent invoices. This balance can be adjusted manually via Orb's webapp on the customer - * details page. You can use this balance to provide a fixed mid-period credit to the customer. - * Commonly, this is done due to system downtime/SLA violation, or an adhoc adjustment discussed - * with the customer. - * - * If the balance is a positive value at the time of invoicing, it represents that the customer has - * credit that should be used to offset the amount due on the next issued invoice. In this case, Orb - * will automatically reduce the next invoice by the balance amount, and roll over any remaining - * balance if the invoice is fully discounted. - * - * If the balance is a negative value at the time of invoicing, Orb will increase the invoice's - * amount due with a positive adjustment, and reset the balance to 0. - * - * This endpoint retrieves all customer balance transactions in reverse chronological order for a - * single customer, providing a complete audit trail of all adjustments and invoice applications. - * - * ## Eligibility - * - * The customer balance can only be applied to invoices or adjusted manually if invoices are not - * synced to a separate invoicing provider. If a payment gateway such as Stripe is used, the balance - * will be applied to the invoice before forwarding payment to the gateway. - */ +/** @see [BalanceTransactionServiceAsync.list] */ class CustomerBalanceTransactionListPageAsync private constructor( - private val balanceTransactionsService: BalanceTransactionServiceAsync, + private val service: BalanceTransactionServiceAsync, private val params: CustomerBalanceTransactionListParams, - private val response: Response, + private val response: CustomerBalanceTransactionListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerBalanceTransactionListPageAsync && balanceTransactionsService == other.balanceTransactionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(balanceTransactionsService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerBalanceTransactionListPageAsync{balanceTransactionsService=$balanceTransactionsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerBalanceTransactionListPageResponse], but gracefully handles missing + * data. + * + * @see [CustomerBalanceTransactionListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerBalanceTransactionListPageResponse], but gracefully handles missing + * data. + * + * @see [CustomerBalanceTransactionListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -86,152 +47,94 @@ private constructor( } return Optional.of( - CustomerBalanceTransactionListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { balanceTransactionsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - balanceTransactionsService: BalanceTransactionServiceAsync, - params: CustomerBalanceTransactionListParams, - response: Response, - ) = CustomerBalanceTransactionListPageAsync(balanceTransactionsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) + /** The parameters that were used to request this page. */ + fun params(): CustomerBalanceTransactionListParams = params - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The response that this page was parsed from. */ + fun response(): CustomerBalanceTransactionListPageResponse = response - private var validated: Boolean = false + fun toBuilder() = Builder().from(this) - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of + * [CustomerBalanceTransactionListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun toBuilder() = Builder().from(this) + /** A builder for [CustomerBalanceTransactionListPageAsync]. */ + class Builder internal constructor() { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + private var service: BalanceTransactionServiceAsync? = null + private var params: CustomerBalanceTransactionListParams? = null + private var response: CustomerBalanceTransactionListPageResponse? = null - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + @JvmSynthetic + internal fun from( + customerBalanceTransactionListPageAsync: CustomerBalanceTransactionListPageAsync + ) = apply { + service = customerBalanceTransactionListPageAsync.service + params = customerBalanceTransactionListPageAsync.params + response = customerBalanceTransactionListPageAsync.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + fun service(service: BalanceTransactionServiceAsync) = apply { this.service = service } - companion object { + /** The parameters that were used to request this page. */ + fun params(params: CustomerBalanceTransactionListParams) = apply { this.params = params } - /** - * Returns a mutable builder for constructing an instance of - * [CustomerBalanceTransactionListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + /** The response that this page was parsed from. */ + fun response(response: CustomerBalanceTransactionListPageResponse) = apply { + this.response = response } - class Builder { - - private var data: JsonField> = - JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [CustomerBalanceTransactionListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerBalanceTransactionListPageAsync = + CustomerBalanceTransactionListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerBalanceTransactionListPageAsync) { @@ -264,4 +167,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerBalanceTransactionListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerBalanceTransactionListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageResponse.kt new file mode 100644 index 00000000..3cc541d8 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageResponse.kt @@ -0,0 +1,239 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class CustomerBalanceTransactionListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CustomerBalanceTransactionListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomerBalanceTransactionListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + customerBalanceTransactionListPageResponse: CustomerBalanceTransactionListPageResponse + ) = apply { + data = customerBalanceTransactionListPageResponse.data.map { it.toMutableList() } + paginationMetadata = customerBalanceTransactionListPageResponse.paginationMetadata + additionalProperties = + customerBalanceTransactionListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is primarily + * for setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [CustomerBalanceTransactionListResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: CustomerBalanceTransactionListResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [CustomerBalanceTransactionListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerBalanceTransactionListPageResponse = + CustomerBalanceTransactionListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CustomerBalanceTransactionListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerBalanceTransactionListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomerBalanceTransactionListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPage.kt index 1819ff44..a791b9c6 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPage.kt @@ -2,133 +2,43 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.customers.credits.LedgerService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * The credits ledger provides _auditing_ functionality over Orb's credits system with a list of - * actions that have taken place to modify a customer's credit balance. This - * [paginated endpoint](/api-reference/pagination) lists these entries, starting from the most - * recent ledger entry. - * - * More details on using Orb's real-time credit feature are [here](/product-catalog/prepurchase). - * - * There are four major types of modifications to credit balance, detailed below. - * - * ## Increment - * - * Credits (which optionally expire on a future date) can be added via the API ([Add Ledger - * Entry](create-ledger-entry)). The ledger entry for such an action will always contain the total - * eligible starting and ending balance for the customer at the time the entry was added to the - * ledger. - * - * ## Decrement - * - * Deductions can occur as a result of an API call to create a ledger entry (see - * [Add Ledger Entry](create-ledger-entry)), or automatically as a result of incurring usage. Both - * ledger entries present the `decrement` entry type. - * - * As usage for a customer is reported into Orb, credits may be deducted according to the customer's - * plan configuration. An automated deduction of this type will result in a ledger entry, also with - * a starting and ending balance. In order to provide better tracing capabilities for automatic - * deductions, Orb always associates each automatic deduction with the `event_id` at the time of - * ingestion, used to pinpoint _why_ credit deduction took place and to ensure that credits are - * never deducted without an associated usage event. - * - * By default, Orb uses an algorithm that automatically deducts from the _soonest expiring credit - * block_ first in order to ensure that all credits are utilized appropriately. As an example, if - * trial credits with an expiration date of 2 weeks from now are present for a customer, they will - * be used before any deductions take place from a non-expiring credit block. - * - * If there are multiple blocks with the same expiration date, Orb will deduct from the block with - * the _lower cost basis_ first (e.g. trial credits with a $0 cost basis before paid credits with a - * $5.00 cost basis). - * - * It's also possible for a single usage event's deduction to _span_ credit blocks. In this case, - * Orb will deduct from the next block, ending at the credit block which consists of unexpiring - * credits. Each of these deductions will lead to a _separate_ ledger entry, one per credit block - * that is deducted from. By default, the customer's total credit balance in Orb can be negative as - * a result of a decrement. - * - * ## Expiration change - * - * The expiry of credits can be changed as a result of the API (See - * [Add Ledger Entry](create-ledger-entry)). This will create a ledger entry that specifies the - * balance as well as the initial and target expiry dates. - * - * Note that for this entry type, `starting_balance` will equal `ending_balance`, and the `amount` - * represents the balance transferred. The credit block linked to the ledger entry is the source - * credit block from which there was an expiration change - * - * ## Credits expiry - * - * When a set of credits expire on pre-set expiration date, the customer's balance automatically - * reflects this change and adds an entry to the ledger indicating this event. Note that credit - * expiry should always happen close to a date boundary in the customer's timezone. - * - * ## Void initiated - * - * Credit blocks can be voided via the API. The `amount` on this entry corresponds to the number of - * credits that were remaining in the block at time of void. `void_reason` will be populated if the - * void is created with a reason. - * - * ## Void - * - * When a set of credits is voided, the customer's balance automatically reflects this change and - * adds an entry to the ledger indicating this event. - * - * ## Amendment - * - * When credits are added to a customer's balance as a result of a correction, this entry will be - * added to the ledger to indicate the adjustment of credits. - */ +/** @see [LedgerService.listByExternalId] */ class CustomerCreditLedgerListByExternalIdPage private constructor( - private val ledgerService: LedgerService, + private val service: LedgerService, private val params: CustomerCreditLedgerListByExternalIdParams, - private val response: Response, + private val response: CustomerCreditLedgerListByExternalIdPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditLedgerListByExternalIdPage && ledgerService == other.ledgerService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(ledgerService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditLedgerListByExternalIdPage{ledgerService=$ledgerService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditLedgerListByExternalIdPageResponse], but gracefully handles + * missing data. + * + * @see [CustomerCreditLedgerListByExternalIdPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditLedgerListByExternalIdPageResponse], but gracefully handles + * missing data. + * + * @see [CustomerCreditLedgerListByExternalIdPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -136,151 +46,94 @@ private constructor( } return Optional.of( - CustomerCreditLedgerListByExternalIdParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { ledgerService.listByExternalId(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.listByExternalId(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - ledgerService: LedgerService, - params: CustomerCreditLedgerListByExternalIdParams, - response: Response, - ) = CustomerCreditLedgerListByExternalIdPage(ledgerService, params, response) - } + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditLedgerListByExternalIdParams = params - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { + /** The response that this page was parsed from. */ + fun response(): CustomerCreditLedgerListByExternalIdPageResponse = response - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) + fun toBuilder() = Builder().from(this) - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() + companion object { - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditLedgerListByExternalIdPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) + /** A builder for [CustomerCreditLedgerListByExternalIdPage]. */ + class Builder internal constructor() { - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) + private var service: LedgerService? = null + private var params: CustomerCreditLedgerListByExternalIdParams? = null + private var response: CustomerCreditLedgerListByExternalIdPageResponse? = null - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) + @JvmSynthetic + internal fun from( + customerCreditLedgerListByExternalIdPage: CustomerCreditLedgerListByExternalIdPage + ) = apply { + service = customerCreditLedgerListByExternalIdPage.service + params = customerCreditLedgerListByExternalIdPage.params + response = customerCreditLedgerListByExternalIdPage.response } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun service(service: LedgerService) = apply { this.service = service } - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditLedgerListByExternalIdParams) = apply { + this.params = params } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [CustomerCreditLedgerListByExternalIdPage]. - */ - @JvmStatic fun builder() = Builder() + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditLedgerListByExternalIdPageResponse) = apply { + this.response = response } - class Builder { - - private var data: JsonField> = - JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = - data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [CustomerCreditLedgerListByExternalIdPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditLedgerListByExternalIdPage = + CustomerCreditLedgerListByExternalIdPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditLedgerListByExternalIdPage) : @@ -302,4 +155,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditLedgerListByExternalIdPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditLedgerListByExternalIdPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageAsync.kt index 56ae4ba5..ce9a3b86 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.customers.credits.LedgerServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,116 +11,35 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * The credits ledger provides _auditing_ functionality over Orb's credits system with a list of - * actions that have taken place to modify a customer's credit balance. This - * [paginated endpoint](/api-reference/pagination) lists these entries, starting from the most - * recent ledger entry. - * - * More details on using Orb's real-time credit feature are [here](/product-catalog/prepurchase). - * - * There are four major types of modifications to credit balance, detailed below. - * - * ## Increment - * - * Credits (which optionally expire on a future date) can be added via the API ([Add Ledger - * Entry](create-ledger-entry)). The ledger entry for such an action will always contain the total - * eligible starting and ending balance for the customer at the time the entry was added to the - * ledger. - * - * ## Decrement - * - * Deductions can occur as a result of an API call to create a ledger entry (see - * [Add Ledger Entry](create-ledger-entry)), or automatically as a result of incurring usage. Both - * ledger entries present the `decrement` entry type. - * - * As usage for a customer is reported into Orb, credits may be deducted according to the customer's - * plan configuration. An automated deduction of this type will result in a ledger entry, also with - * a starting and ending balance. In order to provide better tracing capabilities for automatic - * deductions, Orb always associates each automatic deduction with the `event_id` at the time of - * ingestion, used to pinpoint _why_ credit deduction took place and to ensure that credits are - * never deducted without an associated usage event. - * - * By default, Orb uses an algorithm that automatically deducts from the _soonest expiring credit - * block_ first in order to ensure that all credits are utilized appropriately. As an example, if - * trial credits with an expiration date of 2 weeks from now are present for a customer, they will - * be used before any deductions take place from a non-expiring credit block. - * - * If there are multiple blocks with the same expiration date, Orb will deduct from the block with - * the _lower cost basis_ first (e.g. trial credits with a $0 cost basis before paid credits with a - * $5.00 cost basis). - * - * It's also possible for a single usage event's deduction to _span_ credit blocks. In this case, - * Orb will deduct from the next block, ending at the credit block which consists of unexpiring - * credits. Each of these deductions will lead to a _separate_ ledger entry, one per credit block - * that is deducted from. By default, the customer's total credit balance in Orb can be negative as - * a result of a decrement. - * - * ## Expiration change - * - * The expiry of credits can be changed as a result of the API (See - * [Add Ledger Entry](create-ledger-entry)). This will create a ledger entry that specifies the - * balance as well as the initial and target expiry dates. - * - * Note that for this entry type, `starting_balance` will equal `ending_balance`, and the `amount` - * represents the balance transferred. The credit block linked to the ledger entry is the source - * credit block from which there was an expiration change - * - * ## Credits expiry - * - * When a set of credits expire on pre-set expiration date, the customer's balance automatically - * reflects this change and adds an entry to the ledger indicating this event. Note that credit - * expiry should always happen close to a date boundary in the customer's timezone. - * - * ## Void initiated - * - * Credit blocks can be voided via the API. The `amount` on this entry corresponds to the number of - * credits that were remaining in the block at time of void. `void_reason` will be populated if the - * void is created with a reason. - * - * ## Void - * - * When a set of credits is voided, the customer's balance automatically reflects this change and - * adds an entry to the ledger indicating this event. - * - * ## Amendment - * - * When credits are added to a customer's balance as a result of a correction, this entry will be - * added to the ledger to indicate the adjustment of credits. - */ +/** @see [LedgerServiceAsync.listByExternalId] */ class CustomerCreditLedgerListByExternalIdPageAsync private constructor( - private val ledgerService: LedgerServiceAsync, + private val service: LedgerServiceAsync, private val params: CustomerCreditLedgerListByExternalIdParams, - private val response: Response, + private val response: CustomerCreditLedgerListByExternalIdPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditLedgerListByExternalIdPageAsync && ledgerService == other.ledgerService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(ledgerService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditLedgerListByExternalIdPageAsync{ledgerService=$ledgerService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditLedgerListByExternalIdPageResponse], but gracefully handles + * missing data. + * + * @see [CustomerCreditLedgerListByExternalIdPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditLedgerListByExternalIdPageResponse], but gracefully handles + * missing data. + * + * @see [CustomerCreditLedgerListByExternalIdPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -137,153 +47,97 @@ private constructor( } return Optional.of( - CustomerCreditLedgerListByExternalIdParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { ledgerService.listByExternalId(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.listByExternalId(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - ledgerService: LedgerServiceAsync, - params: CustomerCreditLedgerListByExternalIdParams, - response: Response, - ) = CustomerCreditLedgerListByExternalIdPageAsync(ledgerService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditLedgerListByExternalIdParams = params - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** The response that this page was parsed from. */ + fun response(): CustomerCreditLedgerListByExternalIdPageResponse = response - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + fun toBuilder() = Builder().from(this) - private var validated: Boolean = false + companion object { - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditLedgerListByExternalIdPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - data().map { it.validate() } - paginationMetadata().validate() - validated = true + /** A builder for [CustomerCreditLedgerListByExternalIdPageAsync]. */ + class Builder internal constructor() { + + private var service: LedgerServiceAsync? = null + private var params: CustomerCreditLedgerListByExternalIdParams? = null + private var response: CustomerCreditLedgerListByExternalIdPageResponse? = null + + @JvmSynthetic + internal fun from( + customerCreditLedgerListByExternalIdPageAsync: + CustomerCreditLedgerListByExternalIdPageAsync + ) = apply { + service = customerCreditLedgerListByExternalIdPageAsync.service + params = customerCreditLedgerListByExternalIdPageAsync.params + response = customerCreditLedgerListByExternalIdPageAsync.response } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun service(service: LedgerServiceAsync) = apply { this.service = service } - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditLedgerListByExternalIdParams) = apply { + this.params = params } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [CustomerCreditLedgerListByExternalIdPageAsync]. - */ - @JvmStatic fun builder() = Builder() + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditLedgerListByExternalIdPageResponse) = apply { + this.response = response } - class Builder { - - private var data: JsonField> = - JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = - data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [CustomerCreditLedgerListByExternalIdPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditLedgerListByExternalIdPageAsync = + CustomerCreditLedgerListByExternalIdPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditLedgerListByExternalIdPageAsync) { @@ -316,4 +170,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditLedgerListByExternalIdPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditLedgerListByExternalIdPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponse.kt new file mode 100644 index 00000000..22f89788 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponse.kt @@ -0,0 +1,330 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class CustomerCreditLedgerListByExternalIdPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditLedgerListByExternalIdPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomerCreditLedgerListByExternalIdPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = + null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + customerCreditLedgerListByExternalIdPageResponse: + CustomerCreditLedgerListByExternalIdPageResponse + ) = apply { + data = customerCreditLedgerListByExternalIdPageResponse.data.map { it.toMutableList() } + paginationMetadata = customerCreditLedgerListByExternalIdPageResponse.paginationMetadata + additionalProperties = + customerCreditLedgerListByExternalIdPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = + data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [CustomerCreditLedgerListByExternalIdResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: CustomerCreditLedgerListByExternalIdResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListByExternalIdResponse.ofIncrementLedgerEntry(incrementLedgerEntry)`. + */ + fun addData( + incrementLedgerEntry: CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + ) = + addData( + CustomerCreditLedgerListByExternalIdResponse.ofIncrementLedgerEntry( + incrementLedgerEntry + ) + ) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListByExternalIdResponse.ofDecrementLedgerEntry(decrementLedgerEntry)`. + */ + fun addData( + decrementLedgerEntry: CustomerCreditLedgerListByExternalIdResponse.DecrementLedgerEntry + ) = + addData( + CustomerCreditLedgerListByExternalIdResponse.ofDecrementLedgerEntry( + decrementLedgerEntry + ) + ) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListByExternalIdResponse.ofExpirationChangeLedgerEntry(expirationChangeLedgerEntry)`. + */ + fun addData( + expirationChangeLedgerEntry: + CustomerCreditLedgerListByExternalIdResponse.ExpirationChangeLedgerEntry + ) = + addData( + CustomerCreditLedgerListByExternalIdResponse.ofExpirationChangeLedgerEntry( + expirationChangeLedgerEntry + ) + ) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListByExternalIdResponse.ofCreditBlockExpiryLedgerEntry(creditBlockExpiryLedgerEntry)`. + */ + fun addData( + creditBlockExpiryLedgerEntry: + CustomerCreditLedgerListByExternalIdResponse.CreditBlockExpiryLedgerEntry + ) = + addData( + CustomerCreditLedgerListByExternalIdResponse.ofCreditBlockExpiryLedgerEntry( + creditBlockExpiryLedgerEntry + ) + ) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListByExternalIdResponse.ofVoidLedgerEntry(voidLedgerEntry)`. + */ + fun addData(voidLedgerEntry: CustomerCreditLedgerListByExternalIdResponse.VoidLedgerEntry) = + addData(CustomerCreditLedgerListByExternalIdResponse.ofVoidLedgerEntry(voidLedgerEntry)) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListByExternalIdResponse.ofVoidInitiatedLedgerEntry(voidInitiatedLedgerEntry)`. + */ + fun addData( + voidInitiatedLedgerEntry: + CustomerCreditLedgerListByExternalIdResponse.VoidInitiatedLedgerEntry + ) = + addData( + CustomerCreditLedgerListByExternalIdResponse.ofVoidInitiatedLedgerEntry( + voidInitiatedLedgerEntry + ) + ) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListByExternalIdResponse.ofAmendmentLedgerEntry(amendmentLedgerEntry)`. + */ + fun addData( + amendmentLedgerEntry: CustomerCreditLedgerListByExternalIdResponse.AmendmentLedgerEntry + ) = + addData( + CustomerCreditLedgerListByExternalIdResponse.ofAmendmentLedgerEntry( + amendmentLedgerEntry + ) + ) + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [CustomerCreditLedgerListByExternalIdPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditLedgerListByExternalIdPageResponse = + CustomerCreditLedgerListByExternalIdPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CustomerCreditLedgerListByExternalIdPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditLedgerListByExternalIdPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomerCreditLedgerListByExternalIdPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPage.kt index 7239aca4..b5b1fbb4 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPage.kt @@ -2,133 +2,41 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.customers.credits.LedgerService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * The credits ledger provides _auditing_ functionality over Orb's credits system with a list of - * actions that have taken place to modify a customer's credit balance. This - * [paginated endpoint](/api-reference/pagination) lists these entries, starting from the most - * recent ledger entry. - * - * More details on using Orb's real-time credit feature are [here](/product-catalog/prepurchase). - * - * There are four major types of modifications to credit balance, detailed below. - * - * ## Increment - * - * Credits (which optionally expire on a future date) can be added via the API ([Add Ledger - * Entry](create-ledger-entry)). The ledger entry for such an action will always contain the total - * eligible starting and ending balance for the customer at the time the entry was added to the - * ledger. - * - * ## Decrement - * - * Deductions can occur as a result of an API call to create a ledger entry (see - * [Add Ledger Entry](create-ledger-entry)), or automatically as a result of incurring usage. Both - * ledger entries present the `decrement` entry type. - * - * As usage for a customer is reported into Orb, credits may be deducted according to the customer's - * plan configuration. An automated deduction of this type will result in a ledger entry, also with - * a starting and ending balance. In order to provide better tracing capabilities for automatic - * deductions, Orb always associates each automatic deduction with the `event_id` at the time of - * ingestion, used to pinpoint _why_ credit deduction took place and to ensure that credits are - * never deducted without an associated usage event. - * - * By default, Orb uses an algorithm that automatically deducts from the _soonest expiring credit - * block_ first in order to ensure that all credits are utilized appropriately. As an example, if - * trial credits with an expiration date of 2 weeks from now are present for a customer, they will - * be used before any deductions take place from a non-expiring credit block. - * - * If there are multiple blocks with the same expiration date, Orb will deduct from the block with - * the _lower cost basis_ first (e.g. trial credits with a $0 cost basis before paid credits with a - * $5.00 cost basis). - * - * It's also possible for a single usage event's deduction to _span_ credit blocks. In this case, - * Orb will deduct from the next block, ending at the credit block which consists of unexpiring - * credits. Each of these deductions will lead to a _separate_ ledger entry, one per credit block - * that is deducted from. By default, the customer's total credit balance in Orb can be negative as - * a result of a decrement. - * - * ## Expiration change - * - * The expiry of credits can be changed as a result of the API (See - * [Add Ledger Entry](create-ledger-entry)). This will create a ledger entry that specifies the - * balance as well as the initial and target expiry dates. - * - * Note that for this entry type, `starting_balance` will equal `ending_balance`, and the `amount` - * represents the balance transferred. The credit block linked to the ledger entry is the source - * credit block from which there was an expiration change - * - * ## Credits expiry - * - * When a set of credits expire on pre-set expiration date, the customer's balance automatically - * reflects this change and adds an entry to the ledger indicating this event. Note that credit - * expiry should always happen close to a date boundary in the customer's timezone. - * - * ## Void initiated - * - * Credit blocks can be voided via the API. The `amount` on this entry corresponds to the number of - * credits that were remaining in the block at time of void. `void_reason` will be populated if the - * void is created with a reason. - * - * ## Void - * - * When a set of credits is voided, the customer's balance automatically reflects this change and - * adds an entry to the ledger indicating this event. - * - * ## Amendment - * - * When credits are added to a customer's balance as a result of a correction, this entry will be - * added to the ledger to indicate the adjustment of credits. - */ +/** @see [LedgerService.list] */ class CustomerCreditLedgerListPage private constructor( - private val ledgerService: LedgerService, + private val service: LedgerService, private val params: CustomerCreditLedgerListParams, - private val response: Response, + private val response: CustomerCreditLedgerListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditLedgerListPage && ledgerService == other.ledgerService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(ledgerService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditLedgerListPage{ledgerService=$ledgerService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditLedgerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditLedgerListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditLedgerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditLedgerListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -136,149 +44,89 @@ private constructor( } return Optional.of( - CustomerCreditLedgerListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { ledgerService.list(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - ledgerService: LedgerService, - params: CustomerCreditLedgerListParams, - response: Response, - ) = CustomerCreditLedgerListPage(ledgerService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditLedgerListParams = params - private var validated: Boolean = false + /** The response that this page was parsed from. */ + fun response(): CustomerCreditLedgerListPageResponse = response - fun validate(): Response = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of [CustomerCreditLedgerListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun toBuilder() = Builder().from(this) + /** A builder for [CustomerCreditLedgerListPage]. */ + class Builder internal constructor() { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + private var service: LedgerService? = null + private var params: CustomerCreditLedgerListParams? = null + private var response: CustomerCreditLedgerListPageResponse? = null - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + @JvmSynthetic + internal fun from(customerCreditLedgerListPage: CustomerCreditLedgerListPage) = apply { + service = customerCreditLedgerListPage.service + params = customerCreditLedgerListPage.params + response = customerCreditLedgerListPage.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + fun service(service: LedgerService) = apply { this.service = service } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditLedgerListParams) = apply { this.params = params } - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [CustomerCreditLedgerListPage]. - */ - @JvmStatic fun builder() = Builder() + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditLedgerListPageResponse) = apply { + this.response = response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [CustomerCreditLedgerListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditLedgerListPage = + CustomerCreditLedgerListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditLedgerListPage) : @@ -300,4 +148,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditLedgerListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditLedgerListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageAsync.kt index ea0be730..31bb8765 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.customers.credits.LedgerServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,116 +11,33 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * The credits ledger provides _auditing_ functionality over Orb's credits system with a list of - * actions that have taken place to modify a customer's credit balance. This - * [paginated endpoint](/api-reference/pagination) lists these entries, starting from the most - * recent ledger entry. - * - * More details on using Orb's real-time credit feature are [here](/product-catalog/prepurchase). - * - * There are four major types of modifications to credit balance, detailed below. - * - * ## Increment - * - * Credits (which optionally expire on a future date) can be added via the API ([Add Ledger - * Entry](create-ledger-entry)). The ledger entry for such an action will always contain the total - * eligible starting and ending balance for the customer at the time the entry was added to the - * ledger. - * - * ## Decrement - * - * Deductions can occur as a result of an API call to create a ledger entry (see - * [Add Ledger Entry](create-ledger-entry)), or automatically as a result of incurring usage. Both - * ledger entries present the `decrement` entry type. - * - * As usage for a customer is reported into Orb, credits may be deducted according to the customer's - * plan configuration. An automated deduction of this type will result in a ledger entry, also with - * a starting and ending balance. In order to provide better tracing capabilities for automatic - * deductions, Orb always associates each automatic deduction with the `event_id` at the time of - * ingestion, used to pinpoint _why_ credit deduction took place and to ensure that credits are - * never deducted without an associated usage event. - * - * By default, Orb uses an algorithm that automatically deducts from the _soonest expiring credit - * block_ first in order to ensure that all credits are utilized appropriately. As an example, if - * trial credits with an expiration date of 2 weeks from now are present for a customer, they will - * be used before any deductions take place from a non-expiring credit block. - * - * If there are multiple blocks with the same expiration date, Orb will deduct from the block with - * the _lower cost basis_ first (e.g. trial credits with a $0 cost basis before paid credits with a - * $5.00 cost basis). - * - * It's also possible for a single usage event's deduction to _span_ credit blocks. In this case, - * Orb will deduct from the next block, ending at the credit block which consists of unexpiring - * credits. Each of these deductions will lead to a _separate_ ledger entry, one per credit block - * that is deducted from. By default, the customer's total credit balance in Orb can be negative as - * a result of a decrement. - * - * ## Expiration change - * - * The expiry of credits can be changed as a result of the API (See - * [Add Ledger Entry](create-ledger-entry)). This will create a ledger entry that specifies the - * balance as well as the initial and target expiry dates. - * - * Note that for this entry type, `starting_balance` will equal `ending_balance`, and the `amount` - * represents the balance transferred. The credit block linked to the ledger entry is the source - * credit block from which there was an expiration change - * - * ## Credits expiry - * - * When a set of credits expire on pre-set expiration date, the customer's balance automatically - * reflects this change and adds an entry to the ledger indicating this event. Note that credit - * expiry should always happen close to a date boundary in the customer's timezone. - * - * ## Void initiated - * - * Credit blocks can be voided via the API. The `amount` on this entry corresponds to the number of - * credits that were remaining in the block at time of void. `void_reason` will be populated if the - * void is created with a reason. - * - * ## Void - * - * When a set of credits is voided, the customer's balance automatically reflects this change and - * adds an entry to the ledger indicating this event. - * - * ## Amendment - * - * When credits are added to a customer's balance as a result of a correction, this entry will be - * added to the ledger to indicate the adjustment of credits. - */ +/** @see [LedgerServiceAsync.list] */ class CustomerCreditLedgerListPageAsync private constructor( - private val ledgerService: LedgerServiceAsync, + private val service: LedgerServiceAsync, private val params: CustomerCreditLedgerListParams, - private val response: Response, + private val response: CustomerCreditLedgerListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditLedgerListPageAsync && ledgerService == other.ledgerService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(ledgerService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditLedgerListPageAsync{ledgerService=$ledgerService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditLedgerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditLedgerListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditLedgerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditLedgerListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -137,151 +45,93 @@ private constructor( } return Optional.of( - CustomerCreditLedgerListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { ledgerService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - ledgerService: LedgerServiceAsync, - params: CustomerCreditLedgerListParams, - response: Response, - ) = CustomerCreditLedgerListPageAsync(ledgerService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditLedgerListParams = params - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The response that this page was parsed from. */ + fun response(): CustomerCreditLedgerListPageResponse = response - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) + fun toBuilder() = Builder().from(this) - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + companion object { - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditLedgerListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** A builder for [CustomerCreditLedgerListPageAsync]. */ + class Builder internal constructor() { - fun toBuilder() = Builder().from(this) + private var service: LedgerServiceAsync? = null + private var params: CustomerCreditLedgerListParams? = null + private var response: CustomerCreditLedgerListPageResponse? = null - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + @JvmSynthetic + internal fun from(customerCreditLedgerListPageAsync: CustomerCreditLedgerListPageAsync) = + apply { + service = customerCreditLedgerListPageAsync.service + params = customerCreditLedgerListPageAsync.params + response = customerCreditLedgerListPageAsync.response } - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + fun service(service: LedgerServiceAsync) = apply { this.service = service } - companion object { + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditLedgerListParams) = apply { this.params = params } - /** - * Returns a mutable builder for constructing an instance of - * [CustomerCreditLedgerListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditLedgerListPageResponse) = apply { + this.response = response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [CustomerCreditLedgerListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditLedgerListPageAsync = + CustomerCreditLedgerListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditLedgerListPageAsync) { @@ -312,4 +162,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditLedgerListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditLedgerListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponse.kt new file mode 100644 index 00000000..645d99e3 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponse.kt @@ -0,0 +1,308 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class CustomerCreditLedgerListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditLedgerListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomerCreditLedgerListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + customerCreditLedgerListPageResponse: CustomerCreditLedgerListPageResponse + ) = apply { + data = customerCreditLedgerListPageResponse.data.map { it.toMutableList() } + paginationMetadata = customerCreditLedgerListPageResponse.paginationMetadata + additionalProperties = + customerCreditLedgerListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [CustomerCreditLedgerListResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: CustomerCreditLedgerListResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListResponse.ofIncrementLedgerEntry(incrementLedgerEntry)`. + */ + fun addData(incrementLedgerEntry: CustomerCreditLedgerListResponse.IncrementLedgerEntry) = + addData(CustomerCreditLedgerListResponse.ofIncrementLedgerEntry(incrementLedgerEntry)) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListResponse.ofDecrementLedgerEntry(decrementLedgerEntry)`. + */ + fun addData(decrementLedgerEntry: CustomerCreditLedgerListResponse.DecrementLedgerEntry) = + addData(CustomerCreditLedgerListResponse.ofDecrementLedgerEntry(decrementLedgerEntry)) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListResponse.ofExpirationChangeLedgerEntry(expirationChangeLedgerEntry)`. + */ + fun addData( + expirationChangeLedgerEntry: + CustomerCreditLedgerListResponse.ExpirationChangeLedgerEntry + ) = + addData( + CustomerCreditLedgerListResponse.ofExpirationChangeLedgerEntry( + expirationChangeLedgerEntry + ) + ) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListResponse.ofCreditBlockExpiryLedgerEntry(creditBlockExpiryLedgerEntry)`. + */ + fun addData( + creditBlockExpiryLedgerEntry: + CustomerCreditLedgerListResponse.CreditBlockExpiryLedgerEntry + ) = + addData( + CustomerCreditLedgerListResponse.ofCreditBlockExpiryLedgerEntry( + creditBlockExpiryLedgerEntry + ) + ) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListResponse.ofVoidLedgerEntry(voidLedgerEntry)`. + */ + fun addData(voidLedgerEntry: CustomerCreditLedgerListResponse.VoidLedgerEntry) = + addData(CustomerCreditLedgerListResponse.ofVoidLedgerEntry(voidLedgerEntry)) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListResponse.ofVoidInitiatedLedgerEntry(voidInitiatedLedgerEntry)`. + */ + fun addData( + voidInitiatedLedgerEntry: CustomerCreditLedgerListResponse.VoidInitiatedLedgerEntry + ) = + addData( + CustomerCreditLedgerListResponse.ofVoidInitiatedLedgerEntry( + voidInitiatedLedgerEntry + ) + ) + + /** + * Alias for calling [addData] with + * `CustomerCreditLedgerListResponse.ofAmendmentLedgerEntry(amendmentLedgerEntry)`. + */ + fun addData(amendmentLedgerEntry: CustomerCreditLedgerListResponse.AmendmentLedgerEntry) = + addData(CustomerCreditLedgerListResponse.ofAmendmentLedgerEntry(amendmentLedgerEntry)) + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [CustomerCreditLedgerListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditLedgerListPageResponse = + CustomerCreditLedgerListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CustomerCreditLedgerListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditLedgerListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomerCreditLedgerListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPage.kt index 6cd7ac10..c63f6aa6 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPage.kt @@ -2,65 +2,43 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.customers.CreditService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * Returns a paginated list of unexpired, non-zero credit blocks for a customer. - * - * If `include_all_blocks` is set to `true`, all credit blocks (including expired and depleted - * blocks) will be included in the response. - * - * Note that `currency` defaults to credits if not specified. To use a real world currency, set - * `currency` to an ISO 4217 string. - */ +/** @see [CreditService.listByExternalId] */ class CustomerCreditListByExternalIdPage private constructor( - private val creditsService: CreditService, + private val service: CreditService, private val params: CustomerCreditListByExternalIdParams, - private val response: Response, + private val response: CustomerCreditListByExternalIdPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditListByExternalIdPage && creditsService == other.creditsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(creditsService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditListByExternalIdPage{creditsService=$creditsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditListByExternalIdPageResponse], but gracefully handles missing + * data. + * + * @see [CustomerCreditListByExternalIdPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditListByExternalIdPageResponse], but gracefully handles missing + * data. + * + * @see [CustomerCreditListByExternalIdPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -68,150 +46,91 @@ private constructor( } return Optional.of( - CustomerCreditListByExternalIdParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { creditsService.listByExternalId(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.listByExternalId(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditListByExternalIdParams = params - @JvmStatic - fun of( - creditsService: CreditService, - params: CustomerCreditListByExternalIdParams, - response: Response, - ) = CustomerCreditListByExternalIdPage(creditsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): CustomerCreditListByExternalIdPageResponse = response - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun toBuilder() = Builder().from(this) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + companion object { - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditListByExternalIdPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** A builder for [CustomerCreditListByExternalIdPage]. */ + class Builder internal constructor() { - fun toBuilder() = Builder().from(this) + private var service: CreditService? = null + private var params: CustomerCreditListByExternalIdParams? = null + private var response: CustomerCreditListByExternalIdPageResponse? = null - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + @JvmSynthetic + internal fun from(customerCreditListByExternalIdPage: CustomerCreditListByExternalIdPage) = + apply { + service = customerCreditListByExternalIdPage.service + params = customerCreditListByExternalIdPage.params + response = customerCreditListByExternalIdPage.response } - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + fun service(service: CreditService) = apply { this.service = service } - companion object { + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditListByExternalIdParams) = apply { this.params = params } - /** - * Returns a mutable builder for constructing an instance of - * [CustomerCreditListByExternalIdPage]. - */ - @JvmStatic fun builder() = Builder() + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditListByExternalIdPageResponse) = apply { + this.response = response } - class Builder { - - private var data: JsonField> = - JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [CustomerCreditListByExternalIdPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditListByExternalIdPage = + CustomerCreditListByExternalIdPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditListByExternalIdPage) : @@ -233,4 +152,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditListByExternalIdPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditListByExternalIdPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageAsync.kt index 5e44b1fb..a15138b2 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.customers.CreditServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,48 +11,35 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * Returns a paginated list of unexpired, non-zero credit blocks for a customer. - * - * If `include_all_blocks` is set to `true`, all credit blocks (including expired and depleted - * blocks) will be included in the response. - * - * Note that `currency` defaults to credits if not specified. To use a real world currency, set - * `currency` to an ISO 4217 string. - */ +/** @see [CreditServiceAsync.listByExternalId] */ class CustomerCreditListByExternalIdPageAsync private constructor( - private val creditsService: CreditServiceAsync, + private val service: CreditServiceAsync, private val params: CustomerCreditListByExternalIdParams, - private val response: Response, + private val response: CustomerCreditListByExternalIdPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditListByExternalIdPageAsync && creditsService == other.creditsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(creditsService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditListByExternalIdPageAsync{creditsService=$creditsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditListByExternalIdPageResponse], but gracefully handles missing + * data. + * + * @see [CustomerCreditListByExternalIdPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditListByExternalIdPageResponse], but gracefully handles missing + * data. + * + * @see [CustomerCreditListByExternalIdPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -69,152 +47,94 @@ private constructor( } return Optional.of( - CustomerCreditListByExternalIdParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { creditsService.listByExternalId(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.listByExternalId(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - creditsService: CreditServiceAsync, - params: CustomerCreditListByExternalIdParams, - response: Response, - ) = CustomerCreditListByExternalIdPageAsync(creditsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditListByExternalIdParams = params - private var validated: Boolean = false + /** The response that this page was parsed from. */ + fun response(): CustomerCreditListByExternalIdPageResponse = response - fun validate(): Response = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditListByExternalIdPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun toBuilder() = Builder().from(this) + /** A builder for [CustomerCreditListByExternalIdPageAsync]. */ + class Builder internal constructor() { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + private var service: CreditServiceAsync? = null + private var params: CustomerCreditListByExternalIdParams? = null + private var response: CustomerCreditListByExternalIdPageResponse? = null - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + @JvmSynthetic + internal fun from( + customerCreditListByExternalIdPageAsync: CustomerCreditListByExternalIdPageAsync + ) = apply { + service = customerCreditListByExternalIdPageAsync.service + params = customerCreditListByExternalIdPageAsync.params + response = customerCreditListByExternalIdPageAsync.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + fun service(service: CreditServiceAsync) = apply { this.service = service } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditListByExternalIdParams) = apply { this.params = params } - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [CustomerCreditListByExternalIdPageAsync]. - */ - @JvmStatic fun builder() = Builder() + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditListByExternalIdPageResponse) = apply { + this.response = response } - class Builder { - - private var data: JsonField> = - JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [CustomerCreditListByExternalIdPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditListByExternalIdPageAsync = + CustomerCreditListByExternalIdPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditListByExternalIdPageAsync) { @@ -247,4 +167,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditListByExternalIdPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditListByExternalIdPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponse.kt new file mode 100644 index 00000000..660e69c6 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponse.kt @@ -0,0 +1,239 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class CustomerCreditListByExternalIdPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditListByExternalIdPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomerCreditListByExternalIdPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + customerCreditListByExternalIdPageResponse: CustomerCreditListByExternalIdPageResponse + ) = apply { + data = customerCreditListByExternalIdPageResponse.data.map { it.toMutableList() } + paginationMetadata = customerCreditListByExternalIdPageResponse.paginationMetadata + additionalProperties = + customerCreditListByExternalIdPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is primarily + * for setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [CustomerCreditListByExternalIdResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: CustomerCreditListByExternalIdResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [CustomerCreditListByExternalIdPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditListByExternalIdPageResponse = + CustomerCreditListByExternalIdPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CustomerCreditListByExternalIdPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditListByExternalIdPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomerCreditListByExternalIdPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPage.kt index 9fb8e38c..df86a0a8 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPage.kt @@ -2,65 +2,41 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.customers.CreditService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * Returns a paginated list of unexpired, non-zero credit blocks for a customer. - * - * If `include_all_blocks` is set to `true`, all credit blocks (including expired and depleted - * blocks) will be included in the response. - * - * Note that `currency` defaults to credits if not specified. To use a real world currency, set - * `currency` to an ISO 4217 string. - */ +/** @see [CreditService.list] */ class CustomerCreditListPage private constructor( - private val creditsService: CreditService, + private val service: CreditService, private val params: CustomerCreditListParams, - private val response: Response, + private val response: CustomerCreditListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditListPage && creditsService == other.creditsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(creditsService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditListPage{creditsService=$creditsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -68,146 +44,87 @@ private constructor( } return Optional.of( - CustomerCreditListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { creditsService.list(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - creditsService: CreditService, - params: CustomerCreditListParams, - response: Response, - ) = CustomerCreditListPage(creditsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditListParams = params - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): CustomerCreditListPageResponse = response - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [CustomerCreditListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [CustomerCreditListPage]. */ + class Builder internal constructor() { - companion object { + private var service: CreditService? = null + private var params: CustomerCreditListParams? = null + private var response: CustomerCreditListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [CustomerCreditListPage]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(customerCreditListPage: CustomerCreditListPage) = apply { + service = customerCreditListPage.service + params = customerCreditListPage.params + response = customerCreditListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: CreditService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [CustomerCreditListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditListPage = + CustomerCreditListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditListPage) : @@ -229,4 +146,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageAsync.kt index eaf69a04..03272689 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.customers.CreditServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,48 +11,33 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * Returns a paginated list of unexpired, non-zero credit blocks for a customer. - * - * If `include_all_blocks` is set to `true`, all credit blocks (including expired and depleted - * blocks) will be included in the response. - * - * Note that `currency` defaults to credits if not specified. To use a real world currency, set - * `currency` to an ISO 4217 string. - */ +/** @see [CreditServiceAsync.list] */ class CustomerCreditListPageAsync private constructor( - private val creditsService: CreditServiceAsync, + private val service: CreditServiceAsync, private val params: CustomerCreditListParams, - private val response: Response, + private val response: CustomerCreditListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditListPageAsync && creditsService == other.creditsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(creditsService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditListPageAsync{creditsService=$creditsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -69,149 +45,89 @@ private constructor( } return Optional.of( - CustomerCreditListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { creditsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - creditsService: CreditServiceAsync, - params: CustomerCreditListParams, - response: Response, - ) = CustomerCreditListPageAsync(creditsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditListParams = params - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** The response that this page was parsed from. */ + fun response(): CustomerCreditListPageResponse = response - fun toBuilder() = Builder().from(this) + fun toBuilder() = Builder().from(this) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [CustomerCreditListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [CustomerCreditListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: CreditServiceAsync? = null + private var params: CustomerCreditListParams? = null + private var response: CustomerCreditListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of - * [CustomerCreditListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(customerCreditListPageAsync: CustomerCreditListPageAsync) = apply { + service = customerCreditListPageAsync.service + params = customerCreditListPageAsync.params + response = customerCreditListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: CreditServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [CustomerCreditListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditListPageAsync = + CustomerCreditListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditListPageAsync) { @@ -242,4 +158,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageResponse.kt new file mode 100644 index 00000000..ff42399a --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditListPageResponse.kt @@ -0,0 +1,237 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class CustomerCreditListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomerCreditListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(customerCreditListPageResponse: CustomerCreditListPageResponse) = apply { + data = customerCreditListPageResponse.data.map { it.toMutableList() } + paginationMetadata = customerCreditListPageResponse.paginationMetadata + additionalProperties = + customerCreditListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [CustomerCreditListResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: CustomerCreditListResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [CustomerCreditListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditListPageResponse = + CustomerCreditListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CustomerCreditListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomerCreditListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPage.kt index 9feb4d5e..7e1662ea 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPage.kt @@ -2,57 +2,43 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.customers.credits.TopUpService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** List top-ups by external ID */ +/** @see [TopUpService.listByExternalId] */ class CustomerCreditTopUpListByExternalIdPage private constructor( - private val topUpsService: TopUpService, + private val service: TopUpService, private val params: CustomerCreditTopUpListByExternalIdParams, - private val response: Response, + private val response: CustomerCreditTopUpListByExternalIdPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditTopUpListByExternalIdPage && topUpsService == other.topUpsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(topUpsService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditTopUpListByExternalIdPage{topUpsService=$topUpsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditTopUpListByExternalIdPageResponse], but gracefully handles + * missing data. + * + * @see [CustomerCreditTopUpListByExternalIdPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditTopUpListByExternalIdPageResponse], but gracefully handles + * missing data. + * + * @see [CustomerCreditTopUpListByExternalIdPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -60,151 +46,94 @@ private constructor( } return Optional.of( - CustomerCreditTopUpListByExternalIdParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { topUpsService.listByExternalId(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.listByExternalId(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - topUpsService: TopUpService, - params: CustomerCreditTopUpListByExternalIdParams, - response: Response, - ) = CustomerCreditTopUpListByExternalIdPage(topUpsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditTopUpListByExternalIdParams = params - private var validated: Boolean = false + /** The response that this page was parsed from. */ + fun response(): CustomerCreditTopUpListByExternalIdPageResponse = response - fun validate(): Response = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditTopUpListByExternalIdPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun toBuilder() = Builder().from(this) + /** A builder for [CustomerCreditTopUpListByExternalIdPage]. */ + class Builder internal constructor() { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + private var service: TopUpService? = null + private var params: CustomerCreditTopUpListByExternalIdParams? = null + private var response: CustomerCreditTopUpListByExternalIdPageResponse? = null - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + @JvmSynthetic + internal fun from( + customerCreditTopUpListByExternalIdPage: CustomerCreditTopUpListByExternalIdPage + ) = apply { + service = customerCreditTopUpListByExternalIdPage.service + params = customerCreditTopUpListByExternalIdPage.params + response = customerCreditTopUpListByExternalIdPage.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" - - companion object { + fun service(service: TopUpService) = apply { this.service = service } - /** - * Returns a mutable builder for constructing an instance of - * [CustomerCreditTopUpListByExternalIdPage]. - */ - @JvmStatic fun builder() = Builder() + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditTopUpListByExternalIdParams) = apply { + this.params = params } - class Builder { - - private var data: JsonField> = - JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = - data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditTopUpListByExternalIdPageResponse) = apply { + this.response = response } + + /** + * Returns an immutable instance of [CustomerCreditTopUpListByExternalIdPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditTopUpListByExternalIdPage = + CustomerCreditTopUpListByExternalIdPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditTopUpListByExternalIdPage) : @@ -226,4 +155,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditTopUpListByExternalIdPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditTopUpListByExternalIdPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageAsync.kt index bd343ab2..7ea10578 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.customers.credits.TopUpServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,40 +11,35 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** List top-ups by external ID */ +/** @see [TopUpServiceAsync.listByExternalId] */ class CustomerCreditTopUpListByExternalIdPageAsync private constructor( - private val topUpsService: TopUpServiceAsync, + private val service: TopUpServiceAsync, private val params: CustomerCreditTopUpListByExternalIdParams, - private val response: Response, + private val response: CustomerCreditTopUpListByExternalIdPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditTopUpListByExternalIdPageAsync && topUpsService == other.topUpsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(topUpsService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditTopUpListByExternalIdPageAsync{topUpsService=$topUpsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditTopUpListByExternalIdPageResponse], but gracefully handles + * missing data. + * + * @see [CustomerCreditTopUpListByExternalIdPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditTopUpListByExternalIdPageResponse], but gracefully handles + * missing data. + * + * @see [CustomerCreditTopUpListByExternalIdPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -61,153 +47,97 @@ private constructor( } return Optional.of( - CustomerCreditTopUpListByExternalIdParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { topUpsService.listByExternalId(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.listByExternalId(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditTopUpListByExternalIdParams = params - @JvmStatic - fun of( - topUpsService: TopUpServiceAsync, - params: CustomerCreditTopUpListByExternalIdParams, - response: Response, - ) = CustomerCreditTopUpListByExternalIdPageAsync(topUpsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): CustomerCreditTopUpListByExternalIdPageResponse = response - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun toBuilder() = Builder().from(this) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + companion object { - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditTopUpListByExternalIdPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - data().map { it.validate() } - paginationMetadata().validate() - validated = true + /** A builder for [CustomerCreditTopUpListByExternalIdPageAsync]. */ + class Builder internal constructor() { + + private var service: TopUpServiceAsync? = null + private var params: CustomerCreditTopUpListByExternalIdParams? = null + private var response: CustomerCreditTopUpListByExternalIdPageResponse? = null + + @JvmSynthetic + internal fun from( + customerCreditTopUpListByExternalIdPageAsync: + CustomerCreditTopUpListByExternalIdPageAsync + ) = apply { + service = customerCreditTopUpListByExternalIdPageAsync.service + params = customerCreditTopUpListByExternalIdPageAsync.params + response = customerCreditTopUpListByExternalIdPageAsync.response } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun service(service: TopUpServiceAsync) = apply { this.service = service } - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditTopUpListByExternalIdParams) = apply { + this.params = params } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [CustomerCreditTopUpListByExternalIdPageAsync]. - */ - @JvmStatic fun builder() = Builder() + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditTopUpListByExternalIdPageResponse) = apply { + this.response = response } - class Builder { - - private var data: JsonField> = - JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = - data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [CustomerCreditTopUpListByExternalIdPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditTopUpListByExternalIdPageAsync = + CustomerCreditTopUpListByExternalIdPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditTopUpListByExternalIdPageAsync) { @@ -240,4 +170,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditTopUpListByExternalIdPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditTopUpListByExternalIdPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageResponse.kt new file mode 100644 index 00000000..e35ef34f --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageResponse.kt @@ -0,0 +1,241 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class CustomerCreditTopUpListByExternalIdPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditTopUpListByExternalIdPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomerCreditTopUpListByExternalIdPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = + null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + customerCreditTopUpListByExternalIdPageResponse: + CustomerCreditTopUpListByExternalIdPageResponse + ) = apply { + data = customerCreditTopUpListByExternalIdPageResponse.data.map { it.toMutableList() } + paginationMetadata = customerCreditTopUpListByExternalIdPageResponse.paginationMetadata + additionalProperties = + customerCreditTopUpListByExternalIdPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is + * primarily for setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [CustomerCreditTopUpListByExternalIdResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: CustomerCreditTopUpListByExternalIdResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [CustomerCreditTopUpListByExternalIdPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditTopUpListByExternalIdPageResponse = + CustomerCreditTopUpListByExternalIdPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CustomerCreditTopUpListByExternalIdPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditTopUpListByExternalIdPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomerCreditTopUpListByExternalIdPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPage.kt index 99a5a9ee..8b893147 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPage.kt @@ -2,57 +2,41 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.customers.credits.TopUpService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** List top-ups */ +/** @see [TopUpService.list] */ class CustomerCreditTopUpListPage private constructor( - private val topUpsService: TopUpService, + private val service: TopUpService, private val params: CustomerCreditTopUpListParams, - private val response: Response, + private val response: CustomerCreditTopUpListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditTopUpListPage && topUpsService == other.topUpsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(topUpsService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditTopUpListPage{topUpsService=$topUpsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditTopUpListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditTopUpListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditTopUpListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditTopUpListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -60,149 +44,89 @@ private constructor( } return Optional.of( - CustomerCreditTopUpListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { topUpsService.list(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditTopUpListParams = params - @JvmStatic - fun of( - topUpsService: TopUpService, - params: CustomerCreditTopUpListParams, - response: Response, - ) = CustomerCreditTopUpListPage(topUpsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): CustomerCreditTopUpListPageResponse = response - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun toBuilder() = Builder().from(this) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of [CustomerCreditTopUpListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun toBuilder() = Builder().from(this) + /** A builder for [CustomerCreditTopUpListPage]. */ + class Builder internal constructor() { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + private var service: TopUpService? = null + private var params: CustomerCreditTopUpListParams? = null + private var response: CustomerCreditTopUpListPageResponse? = null - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + @JvmSynthetic + internal fun from(customerCreditTopUpListPage: CustomerCreditTopUpListPage) = apply { + service = customerCreditTopUpListPage.service + params = customerCreditTopUpListPage.params + response = customerCreditTopUpListPage.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + fun service(service: TopUpService) = apply { this.service = service } - companion object { + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditTopUpListParams) = apply { this.params = params } - /** - * Returns a mutable builder for constructing an instance of - * [CustomerCreditTopUpListPage]. - */ - @JvmStatic fun builder() = Builder() + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditTopUpListPageResponse) = apply { + this.response = response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [CustomerCreditTopUpListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditTopUpListPage = + CustomerCreditTopUpListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditTopUpListPage) : @@ -224,4 +148,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditTopUpListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditTopUpListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageAsync.kt index 5b97da3c..311e993a 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.customers.credits.TopUpServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,40 +11,33 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** List top-ups */ +/** @see [TopUpServiceAsync.list] */ class CustomerCreditTopUpListPageAsync private constructor( - private val topUpsService: TopUpServiceAsync, + private val service: TopUpServiceAsync, private val params: CustomerCreditTopUpListParams, - private val response: Response, + private val response: CustomerCreditTopUpListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerCreditTopUpListPageAsync && topUpsService == other.topUpsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(topUpsService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerCreditTopUpListPageAsync{topUpsService=$topUpsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerCreditTopUpListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditTopUpListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerCreditTopUpListPageResponse], but gracefully handles missing data. + * + * @see [CustomerCreditTopUpListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -61,151 +45,93 @@ private constructor( } return Optional.of( - CustomerCreditTopUpListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { topUpsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): CustomerCreditTopUpListParams = params - @JvmStatic - fun of( - topUpsService: TopUpServiceAsync, - params: CustomerCreditTopUpListParams, - response: Response, - ) = CustomerCreditTopUpListPageAsync(topUpsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): CustomerCreditTopUpListPageResponse = response - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun toBuilder() = Builder().from(this) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + companion object { - private var validated: Boolean = false + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditTopUpListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** A builder for [CustomerCreditTopUpListPageAsync]. */ + class Builder internal constructor() { - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + private var service: TopUpServiceAsync? = null + private var params: CustomerCreditTopUpListParams? = null + private var response: CustomerCreditTopUpListPageResponse? = null - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + @JvmSynthetic + internal fun from(customerCreditTopUpListPageAsync: CustomerCreditTopUpListPageAsync) = + apply { + service = customerCreditTopUpListPageAsync.service + params = customerCreditTopUpListPageAsync.params + response = customerCreditTopUpListPageAsync.response } - fun toBuilder() = Builder().from(this) + fun service(service: TopUpServiceAsync) = apply { this.service = service } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** The parameters that were used to request this page. */ + fun params(params: CustomerCreditTopUpListParams) = apply { this.params = params } - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + /** The response that this page was parsed from. */ + fun response(response: CustomerCreditTopUpListPageResponse) = apply { + this.response = response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [CustomerCreditTopUpListPageAsync]. - */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [CustomerCreditTopUpListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditTopUpListPageAsync = + CustomerCreditTopUpListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerCreditTopUpListPageAsync) { @@ -236,4 +162,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditTopUpListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerCreditTopUpListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageResponse.kt new file mode 100644 index 00000000..ef5bf608 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageResponse.kt @@ -0,0 +1,239 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class CustomerCreditTopUpListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [CustomerCreditTopUpListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomerCreditTopUpListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + customerCreditTopUpListPageResponse: CustomerCreditTopUpListPageResponse + ) = apply { + data = customerCreditTopUpListPageResponse.data.map { it.toMutableList() } + paginationMetadata = customerCreditTopUpListPageResponse.paginationMetadata + additionalProperties = + customerCreditTopUpListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [CustomerCreditTopUpListResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: CustomerCreditTopUpListResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [CustomerCreditTopUpListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerCreditTopUpListPageResponse = + CustomerCreditTopUpListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CustomerCreditTopUpListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerCreditTopUpListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomerCreditTopUpListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerListPage.kt index f84d3de6..4f51a3ba 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerListPage.kt @@ -2,63 +2,40 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.CustomerService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all customers for an account. The list of customers is ordered - * starting from the most recently created customer. This endpoint follows Orb's - * [standardized pagination format](/api-reference/pagination). - * - * See [Customer](/core-concepts##customer) for an overview of the customer model. - */ +/** @see [CustomerService.list] */ class CustomerListPage private constructor( - private val customersService: CustomerService, + private val service: CustomerService, private val params: CustomerListParams, - private val response: Response, + private val response: CustomerListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerListPage && customersService == other.customersService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customersService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerListPage{customersService=$customersService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -66,138 +43,86 @@ private constructor( } return Optional.of( - CustomerListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { customersService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(customersService: CustomerService, params: CustomerListParams, response: Response) = - CustomerListPage(customersService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() + /** The parameters that were used to request this page. */ + fun params(): CustomerListParams = params - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The response that this page was parsed from. */ + fun response(): CustomerListPageResponse = response - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + fun toBuilder() = Builder().from(this) - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [CustomerListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [CustomerListPage]. */ + class Builder internal constructor() { - companion object { + private var service: CustomerService? = null + private var params: CustomerListParams? = null + private var response: CustomerListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [CustomerListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(customerListPage: CustomerListPage) = apply { + service = customerListPage.service + params = customerListPage.params + response = customerListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: CustomerService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CustomerListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: CustomerListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [CustomerListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerListPage = + CustomerListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerListPage) : Iterable { @@ -218,4 +143,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerListPageAsync.kt index d465edeb..84928046 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.CustomerServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,46 +11,32 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all customers for an account. The list of customers is ordered - * starting from the most recently created customer. This endpoint follows Orb's - * [standardized pagination format](/api-reference/pagination). - * - * See [Customer](/core-concepts##customer) for an overview of the customer model. - */ +/** @see [CustomerServiceAsync.list] */ class CustomerListPageAsync private constructor( - private val customersService: CustomerServiceAsync, + private val service: CustomerServiceAsync, private val params: CustomerListParams, - private val response: Response, + private val response: CustomerListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CustomerListPageAsync && customersService == other.customersService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(customersService, params, response) /* spotless:on */ - - override fun toString() = - "CustomerListPageAsync{customersService=$customersService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [CustomerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [CustomerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -67,145 +44,89 @@ private constructor( } return Optional.of( - CustomerListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { customersService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - customersService: CustomerServiceAsync, - params: CustomerListParams, - response: Response, - ) = CustomerListPageAsync(customersService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): CustomerListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** The response that this page was parsed from. */ + fun response(): CustomerListPageResponse = response - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [CustomerListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [CustomerListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: CustomerServiceAsync? = null + private var params: CustomerListParams? = null + private var response: CustomerListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [CustomerListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(customerListPageAsync: CustomerListPageAsync) = apply { + service = customerListPageAsync.service + params = customerListPageAsync.params + response = customerListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: CustomerServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CustomerListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: CustomerListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [CustomerListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerListPageAsync = + CustomerListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CustomerListPageAsync) { @@ -233,4 +154,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CustomerListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerListPageResponse.kt new file mode 100644 index 00000000..2c04b338 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerListPageResponse.kt @@ -0,0 +1,231 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class CustomerListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [CustomerListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CustomerListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(customerListPageResponse: CustomerListPageResponse) = apply { + data = customerListPageResponse.data.map { it.toMutableList() } + paginationMetadata = customerListPageResponse.paginationMetadata + additionalProperties = customerListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Customer] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Customer) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [CustomerListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CustomerListPageResponse = + CustomerListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CustomerListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomerListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomerListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPage.kt index 8745345f..7d685ba5 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPage.kt @@ -2,57 +2,41 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.DimensionalPriceGroupService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** List dimensional price groups */ +/** @see [DimensionalPriceGroupService.list] */ class DimensionalPriceGroupListPage private constructor( - private val dimensionalPriceGroupsService: DimensionalPriceGroupService, + private val service: DimensionalPriceGroupService, private val params: DimensionalPriceGroupListParams, - private val response: Response, + private val response: DimensionalPriceGroups, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is DimensionalPriceGroupListPage && dimensionalPriceGroupsService == other.dimensionalPriceGroupsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dimensionalPriceGroupsService, params, response) /* spotless:on */ - - override fun toString() = - "DimensionalPriceGroupListPage{dimensionalPriceGroupsService=$dimensionalPriceGroupsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [DimensionalPriceGroups], but gracefully handles missing data. + * + * @see [DimensionalPriceGroups.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [DimensionalPriceGroups], but gracefully handles missing data. + * + * @see [DimensionalPriceGroups.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -60,144 +44,88 @@ private constructor( } return Optional.of( - DimensionalPriceGroupListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { dimensionalPriceGroupsService.list(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - dimensionalPriceGroupsService: DimensionalPriceGroupService, - params: DimensionalPriceGroupListParams, - response: Response, - ) = DimensionalPriceGroupListPage(dimensionalPriceGroupsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() + /** The parameters that were used to request this page. */ + fun params(): DimensionalPriceGroupListParams = params - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The response that this page was parsed from. */ + fun response(): DimensionalPriceGroups = response - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + fun toBuilder() = Builder().from(this) - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of + * [DimensionalPriceGroupListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [DimensionalPriceGroupListPage]. */ + class Builder internal constructor() { - companion object { + private var service: DimensionalPriceGroupService? = null + private var params: DimensionalPriceGroupListParams? = null + private var response: DimensionalPriceGroups? = null - /** - * Returns a mutable builder for constructing an instance of - * [DimensionalPriceGroupListPage]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(dimensionalPriceGroupListPage: DimensionalPriceGroupListPage) = apply { + service = dimensionalPriceGroupListPage.service + params = dimensionalPriceGroupListPage.params + response = dimensionalPriceGroupListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: DimensionalPriceGroupService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: DimensionalPriceGroupListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: DimensionalPriceGroups) = apply { this.response = response } + + /** + * Returns an immutable instance of [DimensionalPriceGroupListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DimensionalPriceGroupListPage = + DimensionalPriceGroupListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: DimensionalPriceGroupListPage) : @@ -219,4 +147,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is DimensionalPriceGroupListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "DimensionalPriceGroupListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPageAsync.kt index 26c3c322..a823786c 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/DimensionalPriceGroupListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.DimensionalPriceGroupServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,40 +11,33 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** List dimensional price groups */ +/** @see [DimensionalPriceGroupServiceAsync.list] */ class DimensionalPriceGroupListPageAsync private constructor( - private val dimensionalPriceGroupsService: DimensionalPriceGroupServiceAsync, + private val service: DimensionalPriceGroupServiceAsync, private val params: DimensionalPriceGroupListParams, - private val response: Response, + private val response: DimensionalPriceGroups, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is DimensionalPriceGroupListPageAsync && dimensionalPriceGroupsService == other.dimensionalPriceGroupsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(dimensionalPriceGroupsService, params, response) /* spotless:on */ - - override fun toString() = - "DimensionalPriceGroupListPageAsync{dimensionalPriceGroupsService=$dimensionalPriceGroupsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [DimensionalPriceGroups], but gracefully handles missing data. + * + * @see [DimensionalPriceGroups.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [DimensionalPriceGroups], but gracefully handles missing data. + * + * @see [DimensionalPriceGroups.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -61,146 +45,91 @@ private constructor( } return Optional.of( - DimensionalPriceGroupListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { dimensionalPriceGroupsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - dimensionalPriceGroupsService: DimensionalPriceGroupServiceAsync, - params: DimensionalPriceGroupListParams, - response: Response, - ) = DimensionalPriceGroupListPageAsync(dimensionalPriceGroupsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** The parameters that were used to request this page. */ + fun params(): DimensionalPriceGroupListParams = params - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" - - companion object { + /** The response that this page was parsed from. */ + fun response(): DimensionalPriceGroups = response - /** - * Returns a mutable builder for constructing an instance of - * [DimensionalPriceGroupListPageAsync]. - */ - @JvmStatic fun builder() = Builder() - } - - class Builder { + fun toBuilder() = Builder().from(this) - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) + companion object { - fun data(data: JsonField>) = apply { this.data = data } + /** + * Returns a mutable builder for constructing an instance of + * [DimensionalPriceGroupListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) + /** A builder for [DimensionalPriceGroupListPageAsync]. */ + class Builder internal constructor() { - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } + private var service: DimensionalPriceGroupServiceAsync? = null + private var params: DimensionalPriceGroupListParams? = null + private var response: DimensionalPriceGroups? = null - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + @JvmSynthetic + internal fun from(dimensionalPriceGroupListPageAsync: DimensionalPriceGroupListPageAsync) = + apply { + service = dimensionalPriceGroupListPageAsync.service + params = dimensionalPriceGroupListPageAsync.params + response = dimensionalPriceGroupListPageAsync.response } - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: DimensionalPriceGroupServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: DimensionalPriceGroupListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: DimensionalPriceGroups) = apply { this.response = response } + + /** + * Returns an immutable instance of [DimensionalPriceGroupListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DimensionalPriceGroupListPageAsync = + DimensionalPriceGroupListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: DimensionalPriceGroupListPageAsync) { @@ -231,4 +160,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is DimensionalPriceGroupListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "DimensionalPriceGroupListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPage.kt index 8138a843..bfcc8636 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPage.kt @@ -2,64 +2,41 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.events.BackfillService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all backfills in a list format. - * - * The list of backfills is ordered starting from the most recently created backfill. The response - * also includes [`pagination_metadata`](/api-reference/pagination), which lets the caller retrieve - * the next page of results if they exist. More information about pagination can be found in the - * [Pagination-metadata schema](pagination). - */ +/** @see [BackfillService.list] */ class EventBackfillListPage private constructor( - private val backfillsService: BackfillService, + private val service: BackfillService, private val params: EventBackfillListParams, - private val response: Response, + private val response: EventBackfillListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is EventBackfillListPage && backfillsService == other.backfillsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(backfillsService, params, response) /* spotless:on */ - - override fun toString() = - "EventBackfillListPage{backfillsService=$backfillsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [EventBackfillListPageResponse], but gracefully handles missing data. + * + * @see [EventBackfillListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [EventBackfillListPageResponse], but gracefully handles missing data. + * + * @see [EventBackfillListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -67,146 +44,87 @@ private constructor( } return Optional.of( - EventBackfillListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { backfillsService.list(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - backfillsService: BackfillService, - params: EventBackfillListParams, - response: Response, - ) = EventBackfillListPage(backfillsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The parameters that were used to request this page. */ + fun params(): EventBackfillListParams = params - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): EventBackfillListPageResponse = response - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [EventBackfillListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [EventBackfillListPage]. */ + class Builder internal constructor() { - companion object { + private var service: BackfillService? = null + private var params: EventBackfillListParams? = null + private var response: EventBackfillListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [EventBackfillListPage]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(eventBackfillListPage: EventBackfillListPage) = apply { + service = eventBackfillListPage.service + params = eventBackfillListPage.params + response = eventBackfillListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: BackfillService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: EventBackfillListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: EventBackfillListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [EventBackfillListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventBackfillListPage = + EventBackfillListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: EventBackfillListPage) : @@ -228,4 +146,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EventBackfillListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "EventBackfillListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageAsync.kt index da69d042..21a3d253 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.events.BackfillServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,47 +11,33 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all backfills in a list format. - * - * The list of backfills is ordered starting from the most recently created backfill. The response - * also includes [`pagination_metadata`](/api-reference/pagination), which lets the caller retrieve - * the next page of results if they exist. More information about pagination can be found in the - * [Pagination-metadata schema](pagination). - */ +/** @see [BackfillServiceAsync.list] */ class EventBackfillListPageAsync private constructor( - private val backfillsService: BackfillServiceAsync, + private val service: BackfillServiceAsync, private val params: EventBackfillListParams, - private val response: Response, + private val response: EventBackfillListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is EventBackfillListPageAsync && backfillsService == other.backfillsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(backfillsService, params, response) /* spotless:on */ - - override fun toString() = - "EventBackfillListPageAsync{backfillsService=$backfillsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [EventBackfillListPageResponse], but gracefully handles missing data. + * + * @see [EventBackfillListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [EventBackfillListPageResponse], but gracefully handles missing data. + * + * @see [EventBackfillListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -68,149 +45,89 @@ private constructor( } return Optional.of( - EventBackfillListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { backfillsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - backfillsService: BackfillServiceAsync, - params: EventBackfillListParams, - response: Response, - ) = EventBackfillListPageAsync(backfillsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The parameters that were used to request this page. */ + fun params(): EventBackfillListParams = params - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** The response that this page was parsed from. */ + fun response(): EventBackfillListPageResponse = response - fun toBuilder() = Builder().from(this) + fun toBuilder() = Builder().from(this) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [EventBackfillListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [EventBackfillListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: BackfillServiceAsync? = null + private var params: EventBackfillListParams? = null + private var response: EventBackfillListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of - * [EventBackfillListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(eventBackfillListPageAsync: EventBackfillListPageAsync) = apply { + service = eventBackfillListPageAsync.service + params = eventBackfillListPageAsync.params + response = eventBackfillListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: BackfillServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: EventBackfillListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: EventBackfillListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [EventBackfillListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventBackfillListPageAsync = + EventBackfillListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: EventBackfillListPageAsync) { @@ -241,4 +158,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EventBackfillListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "EventBackfillListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageResponse.kt new file mode 100644 index 00000000..8c195679 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/EventBackfillListPageResponse.kt @@ -0,0 +1,236 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class EventBackfillListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [EventBackfillListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EventBackfillListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(eventBackfillListPageResponse: EventBackfillListPageResponse) = apply { + data = eventBackfillListPageResponse.data.map { it.toMutableList() } + paginationMetadata = eventBackfillListPageResponse.paginationMetadata + additionalProperties = eventBackfillListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [EventBackfillListResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: EventBackfillListResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [EventBackfillListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EventBackfillListPageResponse = + EventBackfillListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EventBackfillListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EventBackfillListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EventBackfillListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/InvoiceListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/InvoiceListPage.kt index 57b5cb39..6584cb93 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/InvoiceListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/InvoiceListPage.kt @@ -2,70 +2,40 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.InvoiceService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all [`Invoice`](/core-concepts#invoice)s for an account in a list - * format. - * - * The list of invoices is ordered starting from the most recently issued invoice date. The response - * also includes [`pagination_metadata`](/api-reference/pagination), which lets the caller retrieve - * the next page of results if they exist. - * - * By default, this only returns invoices that are `issued`, `paid`, or `synced`. - * - * When fetching any `draft` invoices, this returns the last-computed invoice values for each draft - * invoice, which may not always be up-to-date since Orb regularly refreshes invoices - * asynchronously. - */ +/** @see [InvoiceService.list] */ class InvoiceListPage private constructor( - private val invoicesService: InvoiceService, + private val service: InvoiceService, private val params: InvoiceListParams, - private val response: Response, + private val response: InvoiceListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is InvoiceListPage && invoicesService == other.invoicesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(invoicesService, params, response) /* spotless:on */ - - override fun toString() = - "InvoiceListPage{invoicesService=$invoicesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [InvoiceListPageResponse], but gracefully handles missing data. + * + * @see [InvoiceListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [InvoiceListPageResponse], but gracefully handles missing data. + * + * @see [InvoiceListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -73,138 +43,86 @@ private constructor( } return Optional.of( - InvoiceListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { invoicesService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(invoicesService: InvoiceService, params: InvoiceListParams, response: Response) = - InvoiceListPage(invoicesService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() + /** The parameters that were used to request this page. */ + fun params(): InvoiceListParams = params - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The response that this page was parsed from. */ + fun response(): InvoiceListPageResponse = response - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + fun toBuilder() = Builder().from(this) - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [InvoiceListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [InvoiceListPage]. */ + class Builder internal constructor() { - companion object { + private var service: InvoiceService? = null + private var params: InvoiceListParams? = null + private var response: InvoiceListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [InvoiceListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(invoiceListPage: InvoiceListPage) = apply { + service = invoiceListPage.service + params = invoiceListPage.params + response = invoiceListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: InvoiceService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: InvoiceListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: InvoiceListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [InvoiceListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InvoiceListPage = + InvoiceListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: InvoiceListPage) : Iterable { @@ -225,4 +143,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is InvoiceListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "InvoiceListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageAsync.kt index 37082cf8..4ae13b3a 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.InvoiceServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,53 +11,32 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all [`Invoice`](/core-concepts#invoice)s for an account in a list - * format. - * - * The list of invoices is ordered starting from the most recently issued invoice date. The response - * also includes [`pagination_metadata`](/api-reference/pagination), which lets the caller retrieve - * the next page of results if they exist. - * - * By default, this only returns invoices that are `issued`, `paid`, or `synced`. - * - * When fetching any `draft` invoices, this returns the last-computed invoice values for each draft - * invoice, which may not always be up-to-date since Orb regularly refreshes invoices - * asynchronously. - */ +/** @see [InvoiceServiceAsync.list] */ class InvoiceListPageAsync private constructor( - private val invoicesService: InvoiceServiceAsync, + private val service: InvoiceServiceAsync, private val params: InvoiceListParams, - private val response: Response, + private val response: InvoiceListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is InvoiceListPageAsync && invoicesService == other.invoicesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(invoicesService, params, response) /* spotless:on */ - - override fun toString() = - "InvoiceListPageAsync{invoicesService=$invoicesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [InvoiceListPageResponse], but gracefully handles missing data. + * + * @see [InvoiceListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [InvoiceListPageResponse], but gracefully handles missing data. + * + * @see [InvoiceListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -74,143 +44,89 @@ private constructor( } return Optional.of( - InvoiceListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { invoicesService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - invoicesService: InvoiceServiceAsync, - params: InvoiceListParams, - response: Response, - ) = InvoiceListPageAsync(invoicesService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): InvoiceListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** The response that this page was parsed from. */ + fun response(): InvoiceListPageResponse = response - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [InvoiceListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [InvoiceListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: InvoiceServiceAsync? = null + private var params: InvoiceListParams? = null + private var response: InvoiceListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [InvoiceListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(invoiceListPageAsync: InvoiceListPageAsync) = apply { + service = invoiceListPageAsync.service + params = invoiceListPageAsync.params + response = invoiceListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: InvoiceServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: InvoiceListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: InvoiceListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [InvoiceListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InvoiceListPageAsync = + InvoiceListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: InvoiceListPageAsync) { @@ -238,4 +154,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is InvoiceListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "InvoiceListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageResponse.kt new file mode 100644 index 00000000..1709b9e2 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/InvoiceListPageResponse.kt @@ -0,0 +1,231 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class InvoiceListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [InvoiceListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InvoiceListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(invoiceListPageResponse: InvoiceListPageResponse) = apply { + data = invoiceListPageResponse.data.map { it.toMutableList() } + paginationMetadata = invoiceListPageResponse.paginationMetadata + additionalProperties = invoiceListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Invoice] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Invoice) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [InvoiceListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InvoiceListPageResponse = + InvoiceListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): InvoiceListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is InvoiceListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InvoiceListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/ItemListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/ItemListPage.kt index 51636676..49f8acf1 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/ItemListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/ItemListPage.kt @@ -2,57 +2,40 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.ItemService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** This endpoint returns a list of all Items, ordered in descending order by creation time. */ +/** @see [ItemService.list] */ class ItemListPage private constructor( - private val itemsService: ItemService, + private val service: ItemService, private val params: ItemListParams, - private val response: Response, + private val response: ItemListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ItemListPage && itemsService == other.itemsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(itemsService, params, response) /* spotless:on */ - - override fun toString() = - "ItemListPage{itemsService=$itemsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [ItemListPageResponse], but gracefully handles missing data. + * + * @see [ItemListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [ItemListPageResponse], but gracefully handles missing data. + * + * @see [ItemListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -60,138 +43,86 @@ private constructor( } return Optional.of( - ItemListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { itemsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(itemsService: ItemService, params: ItemListParams, response: Response) = - ItemListPage(itemsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The parameters that were used to request this page. */ + fun params(): ItemListParams = params - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + /** The response that this page was parsed from. */ + fun response(): ItemListPageResponse = response - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) + fun toBuilder() = Builder().from(this) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [ItemListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [ItemListPage]. */ + class Builder internal constructor() { - companion object { + private var service: ItemService? = null + private var params: ItemListParams? = null + private var response: ItemListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [ItemListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(itemListPage: ItemListPage) = apply { + service = itemListPage.service + params = itemListPage.params + response = itemListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: ItemService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ItemListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ItemListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ItemListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ItemListPage = + ItemListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ItemListPage) : Iterable { @@ -212,4 +143,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ItemListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "ItemListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/ItemListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/ItemListPageAsync.kt index f2f38f00..fb75f340 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/ItemListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/ItemListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.ItemServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,40 +11,32 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** This endpoint returns a list of all Items, ordered in descending order by creation time. */ +/** @see [ItemServiceAsync.list] */ class ItemListPageAsync private constructor( - private val itemsService: ItemServiceAsync, + private val service: ItemServiceAsync, private val params: ItemListParams, - private val response: Response, + private val response: ItemListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ItemListPageAsync && itemsService == other.itemsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(itemsService, params, response) /* spotless:on */ - - override fun toString() = - "ItemListPageAsync{itemsService=$itemsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [ItemListPageResponse], but gracefully handles missing data. + * + * @see [ItemListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [ItemListPageResponse], but gracefully handles missing data. + * + * @see [ItemListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -61,140 +44,89 @@ private constructor( } return Optional.of( - ItemListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { itemsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(itemsService: ItemServiceAsync, params: ItemListParams, response: Response) = - ItemListPageAsync(itemsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): ItemListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** The response that this page was parsed from. */ + fun response(): ItemListPageResponse = response - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [ItemListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [ItemListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: ItemServiceAsync? = null + private var params: ItemListParams? = null + private var response: ItemListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [ItemListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(itemListPageAsync: ItemListPageAsync) = apply { + service = itemListPageAsync.service + params = itemListPageAsync.params + response = itemListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: ItemServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ItemListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ItemListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ItemListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ItemListPageAsync = + ItemListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ItemListPageAsync) { @@ -222,4 +154,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ItemListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ItemListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/ItemListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/ItemListPageResponse.kt new file mode 100644 index 00000000..bc10c10b --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/ItemListPageResponse.kt @@ -0,0 +1,230 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class ItemListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ItemListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ItemListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(itemListPageResponse: ItemListPageResponse) = apply { + data = itemListPageResponse.data.map { it.toMutableList() } + paginationMetadata = itemListPageResponse.paginationMetadata + additionalProperties = itemListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Item] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Item) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [ItemListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ItemListPageResponse = + ItemListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ItemListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ItemListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ItemListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/MetricListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/MetricListPage.kt index cc031efc..bd8cb504 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/MetricListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/MetricListPage.kt @@ -2,60 +2,41 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.MetricService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * This endpoint is used to fetch [metric](/core-concepts##metric) details given a metric - * identifier. It returns information about the metrics including its name, description, and item. - */ +/** @see [MetricService.list] */ class MetricListPage private constructor( - private val metricsService: MetricService, + private val service: MetricService, private val params: MetricListParams, - private val response: Response, + private val response: MetricListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MetricListPage && metricsService == other.metricsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(metricsService, params, response) /* spotless:on */ - - override fun toString() = - "MetricListPage{metricsService=$metricsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [MetricListPageResponse], but gracefully handles missing data. + * + * @see [MetricListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [MetricListPageResponse], but gracefully handles missing data. + * + * @see [MetricListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -63,138 +44,86 @@ private constructor( } return Optional.of( - MetricListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { metricsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(metricsService: MetricService, params: MetricListParams, response: Response) = - MetricListPage(metricsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The parameters that were used to request this page. */ + fun params(): MetricListParams = params - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + /** The response that this page was parsed from. */ + fun response(): MetricListPageResponse = response - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) + fun toBuilder() = Builder().from(this) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [MetricListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [MetricListPage]. */ + class Builder internal constructor() { - companion object { + private var service: MetricService? = null + private var params: MetricListParams? = null + private var response: MetricListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [MetricListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(metricListPage: MetricListPage) = apply { + service = metricListPage.service + params = metricListPage.params + response = metricListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: MetricService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: MetricListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: MetricListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [MetricListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MetricListPage = + MetricListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: MetricListPage) : Iterable { @@ -215,4 +144,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is MetricListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "MetricListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/MetricListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/MetricListPageAsync.kt index 7f557a44..9f509035 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/MetricListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/MetricListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.MetricServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,43 +11,33 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * This endpoint is used to fetch [metric](/core-concepts##metric) details given a metric - * identifier. It returns information about the metrics including its name, description, and item. - */ +/** @see [MetricServiceAsync.list] */ class MetricListPageAsync private constructor( - private val metricsService: MetricServiceAsync, + private val service: MetricServiceAsync, private val params: MetricListParams, - private val response: Response, + private val response: MetricListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MetricListPageAsync && metricsService == other.metricsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(metricsService, params, response) /* spotless:on */ - - override fun toString() = - "MetricListPageAsync{metricsService=$metricsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [MetricListPageResponse], but gracefully handles missing data. + * + * @see [MetricListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [MetricListPageResponse], but gracefully handles missing data. + * + * @see [MetricListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -64,140 +45,89 @@ private constructor( } return Optional.of( - MetricListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { metricsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(metricsService: MetricServiceAsync, params: MetricListParams, response: Response) = - MetricListPageAsync(metricsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): MetricListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** The response that this page was parsed from. */ + fun response(): MetricListPageResponse = response - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [MetricListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [MetricListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: MetricServiceAsync? = null + private var params: MetricListParams? = null + private var response: MetricListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [MetricListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(metricListPageAsync: MetricListPageAsync) = apply { + service = metricListPageAsync.service + params = metricListPageAsync.params + response = metricListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: MetricServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: MetricListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: MetricListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [MetricListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MetricListPageAsync = + MetricListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: MetricListPageAsync) { @@ -228,4 +158,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is MetricListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "MetricListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/MetricListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/MetricListPageResponse.kt new file mode 100644 index 00000000..819c853f --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/MetricListPageResponse.kt @@ -0,0 +1,233 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class MetricListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [MetricListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MetricListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metricListPageResponse: MetricListPageResponse) = apply { + data = metricListPageResponse.data.map { it.toMutableList() } + paginationMetadata = metricListPageResponse.paginationMetadata + additionalProperties = metricListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [BillableMetric] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: BillableMetric) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [MetricListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MetricListPageResponse = + MetricListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MetricListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is MetricListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MetricListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/PlanListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/PlanListPage.kt index b10e4e60..3442a463 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/PlanListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/PlanListPage.kt @@ -2,62 +2,40 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.PlanService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all [plans](/core-concepts#plan-and-price) for an account in a - * list format. The list of plans is ordered starting from the most recently created plan. The - * response also includes [`pagination_metadata`](/api-reference/pagination), which lets the caller - * retrieve the next page of results if they exist. - */ +/** @see [PlanService.list] */ class PlanListPage private constructor( - private val plansService: PlanService, + private val service: PlanService, private val params: PlanListParams, - private val response: Response, + private val response: PlanListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is PlanListPage && plansService == other.plansService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(plansService, params, response) /* spotless:on */ - - override fun toString() = - "PlanListPage{plansService=$plansService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [PlanListPageResponse], but gracefully handles missing data. + * + * @see [PlanListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [PlanListPageResponse], but gracefully handles missing data. + * + * @see [PlanListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -65,138 +43,86 @@ private constructor( } return Optional.of( - PlanListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { plansService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(plansService: PlanService, params: PlanListParams, response: Response) = - PlanListPage(plansService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The parameters that were used to request this page. */ + fun params(): PlanListParams = params - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + /** The response that this page was parsed from. */ + fun response(): PlanListPageResponse = response - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) + fun toBuilder() = Builder().from(this) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [PlanListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [PlanListPage]. */ + class Builder internal constructor() { - companion object { + private var service: PlanService? = null + private var params: PlanListParams? = null + private var response: PlanListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [PlanListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(planListPage: PlanListPage) = apply { + service = planListPage.service + params = planListPage.params + response = planListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: PlanService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: PlanListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: PlanListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [PlanListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PlanListPage = + PlanListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: PlanListPage) : Iterable { @@ -217,4 +143,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PlanListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "PlanListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/PlanListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/PlanListPageAsync.kt index ac5e4846..f12c610f 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/PlanListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/PlanListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.PlanServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,45 +11,32 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all [plans](/core-concepts#plan-and-price) for an account in a - * list format. The list of plans is ordered starting from the most recently created plan. The - * response also includes [`pagination_metadata`](/api-reference/pagination), which lets the caller - * retrieve the next page of results if they exist. - */ +/** @see [PlanServiceAsync.list] */ class PlanListPageAsync private constructor( - private val plansService: PlanServiceAsync, + private val service: PlanServiceAsync, private val params: PlanListParams, - private val response: Response, + private val response: PlanListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is PlanListPageAsync && plansService == other.plansService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(plansService, params, response) /* spotless:on */ - - override fun toString() = - "PlanListPageAsync{plansService=$plansService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [PlanListPageResponse], but gracefully handles missing data. + * + * @see [PlanListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [PlanListPageResponse], but gracefully handles missing data. + * + * @see [PlanListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -66,140 +44,89 @@ private constructor( } return Optional.of( - PlanListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { plansService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(plansService: PlanServiceAsync, params: PlanListParams, response: Response) = - PlanListPageAsync(plansService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): PlanListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** The response that this page was parsed from. */ + fun response(): PlanListPageResponse = response - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [PlanListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [PlanListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: PlanServiceAsync? = null + private var params: PlanListParams? = null + private var response: PlanListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [PlanListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(planListPageAsync: PlanListPageAsync) = apply { + service = planListPageAsync.service + params = planListPageAsync.params + response = planListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: PlanServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: PlanListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: PlanListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [PlanListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PlanListPageAsync = + PlanListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: PlanListPageAsync) { @@ -227,4 +154,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PlanListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "PlanListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/PlanListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/PlanListPageResponse.kt new file mode 100644 index 00000000..5a8db213 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/PlanListPageResponse.kt @@ -0,0 +1,230 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class PlanListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PlanListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PlanListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(planListPageResponse: PlanListPageResponse) = apply { + data = planListPageResponse.data.map { it.toMutableList() } + paginationMetadata = planListPageResponse.paginationMetadata + additionalProperties = planListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Plan] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Plan) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [PlanListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PlanListPageResponse = + PlanListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PlanListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PlanListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PlanListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/PriceListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/PriceListPage.kt index 18a4228d..90ac2e31 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/PriceListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/PriceListPage.kt @@ -2,60 +2,40 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.PriceService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * This endpoint is used to list all add-on prices created using the - * [price creation endpoint](/api-reference/price/create-price). - */ +/** @see [PriceService.list] */ class PriceListPage private constructor( - private val pricesService: PriceService, + private val service: PriceService, private val params: PriceListParams, - private val response: Response, + private val response: PriceListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is PriceListPage && pricesService == other.pricesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(pricesService, params, response) /* spotless:on */ - - override fun toString() = - "PriceListPage{pricesService=$pricesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [PriceListPageResponse], but gracefully handles missing data. + * + * @see [PriceListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [PriceListPageResponse], but gracefully handles missing data. + * + * @see [PriceListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -63,138 +43,86 @@ private constructor( } return Optional.of( - PriceListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { pricesService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(pricesService: PriceService, params: PriceListParams, response: Response) = - PriceListPage(pricesService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The parameters that were used to request this page. */ + fun params(): PriceListParams = params - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + /** The response that this page was parsed from. */ + fun response(): PriceListPageResponse = response - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) + fun toBuilder() = Builder().from(this) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [PriceListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [PriceListPage]. */ + class Builder internal constructor() { - companion object { + private var service: PriceService? = null + private var params: PriceListParams? = null + private var response: PriceListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [PriceListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(priceListPage: PriceListPage) = apply { + service = priceListPage.service + params = priceListPage.params + response = priceListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: PriceService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: PriceListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: PriceListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [PriceListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PriceListPage = + PriceListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: PriceListPage) : Iterable { @@ -215,4 +143,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PriceListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "PriceListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/PriceListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/PriceListPageAsync.kt index b6de300c..e38c33a4 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/PriceListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/PriceListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.PriceServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,43 +11,32 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * This endpoint is used to list all add-on prices created using the - * [price creation endpoint](/api-reference/price/create-price). - */ +/** @see [PriceServiceAsync.list] */ class PriceListPageAsync private constructor( - private val pricesService: PriceServiceAsync, + private val service: PriceServiceAsync, private val params: PriceListParams, - private val response: Response, + private val response: PriceListPageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is PriceListPageAsync && pricesService == other.pricesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(pricesService, params, response) /* spotless:on */ - - override fun toString() = - "PriceListPageAsync{pricesService=$pricesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [PriceListPageResponse], but gracefully handles missing data. + * + * @see [PriceListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [PriceListPageResponse], but gracefully handles missing data. + * + * @see [PriceListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -64,140 +44,89 @@ private constructor( } return Optional.of( - PriceListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { pricesService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(pricesService: PriceServiceAsync, params: PriceListParams, response: Response) = - PriceListPageAsync(pricesService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): PriceListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** The response that this page was parsed from. */ + fun response(): PriceListPageResponse = response - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [PriceListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [PriceListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: PriceServiceAsync? = null + private var params: PriceListParams? = null + private var response: PriceListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [PriceListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(priceListPageAsync: PriceListPageAsync) = apply { + service = priceListPageAsync.service + params = priceListPageAsync.params + response = priceListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: PriceServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: PriceListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: PriceListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [PriceListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PriceListPageAsync = + PriceListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: PriceListPageAsync) { @@ -225,4 +154,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PriceListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "PriceListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/PriceListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/PriceListPageResponse.kt new file mode 100644 index 00000000..6d09727c --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/PriceListPageResponse.kt @@ -0,0 +1,364 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class PriceListPageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PriceListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PriceListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(priceListPageResponse: PriceListPageResponse) = apply { + data = priceListPageResponse.data.map { it.toMutableList() } + paginationMetadata = priceListPageResponse.paginationMetadata + additionalProperties = priceListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Price] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Price) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** Alias for calling [addData] with `Price.ofUnit(unit)`. */ + fun addData(unit: Price.UnitPrice) = addData(Price.ofUnit(unit)) + + /** Alias for calling [addData] with `Price.ofPackagePrice(packagePrice)`. */ + fun addData(packagePrice: Price.PackagePrice) = addData(Price.ofPackagePrice(packagePrice)) + + /** Alias for calling [addData] with `Price.ofMatrix(matrix)`. */ + fun addData(matrix: Price.MatrixPrice) = addData(Price.ofMatrix(matrix)) + + /** Alias for calling [addData] with `Price.ofTiered(tiered)`. */ + fun addData(tiered: Price.TieredPrice) = addData(Price.ofTiered(tiered)) + + /** Alias for calling [addData] with `Price.ofTieredBps(tieredBps)`. */ + fun addData(tieredBps: Price.TieredBpsPrice) = addData(Price.ofTieredBps(tieredBps)) + + /** Alias for calling [addData] with `Price.ofBps(bps)`. */ + fun addData(bps: Price.BpsPrice) = addData(Price.ofBps(bps)) + + /** Alias for calling [addData] with `Price.ofBulkBps(bulkBps)`. */ + fun addData(bulkBps: Price.BulkBpsPrice) = addData(Price.ofBulkBps(bulkBps)) + + /** Alias for calling [addData] with `Price.ofBulk(bulk)`. */ + fun addData(bulk: Price.BulkPrice) = addData(Price.ofBulk(bulk)) + + /** + * Alias for calling [addData] with `Price.ofThresholdTotalAmount(thresholdTotalAmount)`. + */ + fun addData(thresholdTotalAmount: Price.ThresholdTotalAmountPrice) = + addData(Price.ofThresholdTotalAmount(thresholdTotalAmount)) + + /** Alias for calling [addData] with `Price.ofTieredPackage(tieredPackage)`. */ + fun addData(tieredPackage: Price.TieredPackagePrice) = + addData(Price.ofTieredPackage(tieredPackage)) + + /** Alias for calling [addData] with `Price.ofGroupedTiered(groupedTiered)`. */ + fun addData(groupedTiered: Price.GroupedTieredPrice) = + addData(Price.ofGroupedTiered(groupedTiered)) + + /** Alias for calling [addData] with `Price.ofTieredWithMinimum(tieredWithMinimum)`. */ + fun addData(tieredWithMinimum: Price.TieredWithMinimumPrice) = + addData(Price.ofTieredWithMinimum(tieredWithMinimum)) + + /** + * Alias for calling [addData] with + * `Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)`. + */ + fun addData(tieredPackageWithMinimum: Price.TieredPackageWithMinimumPrice) = + addData(Price.ofTieredPackageWithMinimum(tieredPackageWithMinimum)) + + /** + * Alias for calling [addData] with `Price.ofPackageWithAllocation(packageWithAllocation)`. + */ + fun addData(packageWithAllocation: Price.PackageWithAllocationPrice) = + addData(Price.ofPackageWithAllocation(packageWithAllocation)) + + /** Alias for calling [addData] with `Price.ofUnitWithPercent(unitWithPercent)`. */ + fun addData(unitWithPercent: Price.UnitWithPercentPrice) = + addData(Price.ofUnitWithPercent(unitWithPercent)) + + /** + * Alias for calling [addData] with `Price.ofMatrixWithAllocation(matrixWithAllocation)`. + */ + fun addData(matrixWithAllocation: Price.MatrixWithAllocationPrice) = + addData(Price.ofMatrixWithAllocation(matrixWithAllocation)) + + /** Alias for calling [addData] with `Price.ofTieredWithProration(tieredWithProration)`. */ + fun addData(tieredWithProration: Price.TieredWithProrationPrice) = + addData(Price.ofTieredWithProration(tieredWithProration)) + + /** Alias for calling [addData] with `Price.ofUnitWithProration(unitWithProration)`. */ + fun addData(unitWithProration: Price.UnitWithProrationPrice) = + addData(Price.ofUnitWithProration(unitWithProration)) + + /** Alias for calling [addData] with `Price.ofGroupedAllocation(groupedAllocation)`. */ + fun addData(groupedAllocation: Price.GroupedAllocationPrice) = + addData(Price.ofGroupedAllocation(groupedAllocation)) + + /** + * Alias for calling [addData] with + * `Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)`. + */ + fun addData(groupedWithProratedMinimum: Price.GroupedWithProratedMinimumPrice) = + addData(Price.ofGroupedWithProratedMinimum(groupedWithProratedMinimum)) + + /** + * Alias for calling [addData] with + * `Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)`. + */ + fun addData(groupedWithMeteredMinimum: Price.GroupedWithMeteredMinimumPrice) = + addData(Price.ofGroupedWithMeteredMinimum(groupedWithMeteredMinimum)) + + /** + * Alias for calling [addData] with `Price.ofMatrixWithDisplayName(matrixWithDisplayName)`. + */ + fun addData(matrixWithDisplayName: Price.MatrixWithDisplayNamePrice) = + addData(Price.ofMatrixWithDisplayName(matrixWithDisplayName)) + + /** Alias for calling [addData] with `Price.ofBulkWithProration(bulkWithProration)`. */ + fun addData(bulkWithProration: Price.BulkWithProrationPrice) = + addData(Price.ofBulkWithProration(bulkWithProration)) + + /** + * Alias for calling [addData] with `Price.ofGroupedTieredPackage(groupedTieredPackage)`. + */ + fun addData(groupedTieredPackage: Price.GroupedTieredPackagePrice) = + addData(Price.ofGroupedTieredPackage(groupedTieredPackage)) + + /** + * Alias for calling [addData] with `Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)`. + */ + fun addData(maxGroupTieredPackage: Price.MaxGroupTieredPackagePrice) = + addData(Price.ofMaxGroupTieredPackage(maxGroupTieredPackage)) + + /** + * Alias for calling [addData] with + * `Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)`. + */ + fun addData(scalableMatrixWithUnitPricing: Price.ScalableMatrixWithUnitPricingPrice) = + addData(Price.ofScalableMatrixWithUnitPricing(scalableMatrixWithUnitPricing)) + + /** + * Alias for calling [addData] with + * `Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)`. + */ + fun addData(scalableMatrixWithTieredPricing: Price.ScalableMatrixWithTieredPricingPrice) = + addData(Price.ofScalableMatrixWithTieredPricing(scalableMatrixWithTieredPricing)) + + /** + * Alias for calling [addData] with `Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)`. + */ + fun addData(cumulativeGroupedBulk: Price.CumulativeGroupedBulkPrice) = + addData(Price.ofCumulativeGroupedBulk(cumulativeGroupedBulk)) + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [PriceListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PriceListPageResponse = + PriceListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PriceListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PriceListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PriceListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePage.kt index 9ee52546..2e815413 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePage.kt @@ -2,61 +2,41 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.SubscriptionService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a [paginated](/api-reference/pagination) list of all plans associated with - * a subscription along with their start and end dates. This list contains the subscription's - * initial plan along with past and future plan changes. - */ +/** @see [SubscriptionService.fetchSchedule] */ class SubscriptionFetchSchedulePage private constructor( - private val subscriptionsService: SubscriptionService, + private val service: SubscriptionService, private val params: SubscriptionFetchScheduleParams, - private val response: Response, + private val response: SubscriptionFetchSchedulePageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is SubscriptionFetchSchedulePage && subscriptionsService == other.subscriptionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionsService, params, response) /* spotless:on */ - - override fun toString() = - "SubscriptionFetchSchedulePage{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [SubscriptionFetchSchedulePageResponse], but gracefully handles missing data. + * + * @see [SubscriptionFetchSchedulePageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [SubscriptionFetchSchedulePageResponse], but gracefully handles missing data. + * + * @see [SubscriptionFetchSchedulePageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -64,149 +44,90 @@ private constructor( } return Optional.of( - SubscriptionFetchScheduleParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { subscriptionsService.fetchSchedule(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.fetchSchedule(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): SubscriptionFetchScheduleParams = params - @JvmStatic - fun of( - subscriptionsService: SubscriptionService, - params: SubscriptionFetchScheduleParams, - response: Response, - ) = SubscriptionFetchSchedulePage(subscriptionsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): SubscriptionFetchSchedulePageResponse = response - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun toBuilder() = Builder().from(this) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + companion object { - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + /** + * Returns a mutable builder for constructing an instance of + * [SubscriptionFetchSchedulePage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun toBuilder() = Builder().from(this) + /** A builder for [SubscriptionFetchSchedulePage]. */ + class Builder internal constructor() { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + private var service: SubscriptionService? = null + private var params: SubscriptionFetchScheduleParams? = null + private var response: SubscriptionFetchSchedulePageResponse? = null - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + @JvmSynthetic + internal fun from(subscriptionFetchSchedulePage: SubscriptionFetchSchedulePage) = apply { + service = subscriptionFetchSchedulePage.service + params = subscriptionFetchSchedulePage.params + response = subscriptionFetchSchedulePage.response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + fun service(service: SubscriptionService) = apply { this.service = service } - companion object { + /** The parameters that were used to request this page. */ + fun params(params: SubscriptionFetchScheduleParams) = apply { this.params = params } - /** - * Returns a mutable builder for constructing an instance of - * [SubscriptionFetchSchedulePage]. - */ - @JvmStatic fun builder() = Builder() + /** The response that this page was parsed from. */ + fun response(response: SubscriptionFetchSchedulePageResponse) = apply { + this.response = response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [SubscriptionFetchSchedulePage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SubscriptionFetchSchedulePage = + SubscriptionFetchSchedulePage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: SubscriptionFetchSchedulePage) : @@ -228,4 +149,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is SubscriptionFetchSchedulePage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "SubscriptionFetchSchedulePage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageAsync.kt index e0339a27..b9895452 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.SubscriptionServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,44 +11,33 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a [paginated](/api-reference/pagination) list of all plans associated with - * a subscription along with their start and end dates. This list contains the subscription's - * initial plan along with past and future plan changes. - */ +/** @see [SubscriptionServiceAsync.fetchSchedule] */ class SubscriptionFetchSchedulePageAsync private constructor( - private val subscriptionsService: SubscriptionServiceAsync, + private val service: SubscriptionServiceAsync, private val params: SubscriptionFetchScheduleParams, - private val response: Response, + private val response: SubscriptionFetchSchedulePageResponse, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is SubscriptionFetchSchedulePageAsync && subscriptionsService == other.subscriptionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionsService, params, response) /* spotless:on */ - - override fun toString() = - "SubscriptionFetchSchedulePageAsync{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [SubscriptionFetchSchedulePageResponse], but gracefully handles missing data. + * + * @see [SubscriptionFetchSchedulePageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [SubscriptionFetchSchedulePageResponse], but gracefully handles missing data. + * + * @see [SubscriptionFetchSchedulePageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -65,151 +45,93 @@ private constructor( } return Optional.of( - SubscriptionFetchScheduleParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { subscriptionsService.fetchSchedule(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.fetchSchedule(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): SubscriptionFetchScheduleParams = params - @JvmStatic - fun of( - subscriptionsService: SubscriptionServiceAsync, - params: SubscriptionFetchScheduleParams, - response: Response, - ) = SubscriptionFetchSchedulePageAsync(subscriptionsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): SubscriptionFetchSchedulePageResponse = response - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + fun toBuilder() = Builder().from(this) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + companion object { - private var validated: Boolean = false + /** + * Returns a mutable builder for constructing an instance of + * [SubscriptionFetchSchedulePageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** A builder for [SubscriptionFetchSchedulePageAsync]. */ + class Builder internal constructor() { - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + private var service: SubscriptionServiceAsync? = null + private var params: SubscriptionFetchScheduleParams? = null + private var response: SubscriptionFetchSchedulePageResponse? = null - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false + @JvmSynthetic + internal fun from(subscriptionFetchSchedulePageAsync: SubscriptionFetchSchedulePageAsync) = + apply { + service = subscriptionFetchSchedulePageAsync.service + params = subscriptionFetchSchedulePageAsync.params + response = subscriptionFetchSchedulePageAsync.response } - fun toBuilder() = Builder().from(this) + fun service(service: SubscriptionServiceAsync) = apply { this.service = service } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** The parameters that were used to request this page. */ + fun params(params: SubscriptionFetchScheduleParams) = apply { this.params = params } - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + /** The response that this page was parsed from. */ + fun response(response: SubscriptionFetchSchedulePageResponse) = apply { + this.response = response } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" - - companion object { - - /** - * Returns a mutable builder for constructing an instance of - * [SubscriptionFetchSchedulePageAsync]. - */ - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { - this.data = data - } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + /** + * Returns an immutable instance of [SubscriptionFetchSchedulePageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SubscriptionFetchSchedulePageAsync = + SubscriptionFetchSchedulePageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: SubscriptionFetchSchedulePageAsync) { @@ -240,4 +162,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is SubscriptionFetchSchedulePageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "SubscriptionFetchSchedulePageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageResponse.kt new file mode 100644 index 00000000..58eecc46 --- /dev/null +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageResponse.kt @@ -0,0 +1,239 @@ +// 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.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.checkKnown +import com.withorb.api.core.checkRequired +import com.withorb.api.core.toImmutable +import com.withorb.api.errors.OrbInvalidDataException +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class SubscriptionFetchSchedulePageResponse +private constructor( + private val data: JsonField>, + private val paginationMetadata: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("pagination_metadata") + @ExcludeMissing + paginationMetadata: JsonField = JsonMissing.of(), + ) : this(data, paginationMetadata, mutableMapOf()) + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun paginationMetadata(): PaginationMetadata = + paginationMetadata.getRequired("pagination_metadata") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [paginationMetadata]. + * + * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("pagination_metadata") + @ExcludeMissing + fun _paginationMetadata(): JsonField = paginationMetadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [SubscriptionFetchSchedulePageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SubscriptionFetchSchedulePageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var paginationMetadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + subscriptionFetchSchedulePageResponse: SubscriptionFetchSchedulePageResponse + ) = apply { + data = subscriptionFetchSchedulePageResponse.data.map { it.toMutableList() } + paginationMetadata = subscriptionFetchSchedulePageResponse.paginationMetadata + additionalProperties = + subscriptionFetchSchedulePageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [SubscriptionFetchScheduleResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: SubscriptionFetchScheduleResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun paginationMetadata(paginationMetadata: PaginationMetadata) = + paginationMetadata(JsonField.of(paginationMetadata)) + + /** + * Sets [Builder.paginationMetadata] to an arbitrary JSON value. + * + * You should usually call [Builder.paginationMetadata] with a well-typed + * [PaginationMetadata] value instead. This method is primarily for setting the field to an + * undocumented or not yet supported value. + */ + fun paginationMetadata(paginationMetadata: JsonField) = apply { + this.paginationMetadata = paginationMetadata + } + + 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) + } + + /** + * Returns an immutable instance of [SubscriptionFetchSchedulePageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .paginationMetadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SubscriptionFetchSchedulePageResponse = + SubscriptionFetchSchedulePageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("paginationMetadata", paginationMetadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SubscriptionFetchSchedulePageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + paginationMetadata().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OrbInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is SubscriptionFetchSchedulePageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SubscriptionFetchSchedulePageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" +} diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPage.kt index 21d5b23b..6dbe30e2 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPage.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPage.kt @@ -2,66 +2,40 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.blocking.SubscriptionService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all subscriptions for an account as a - * [paginated](/api-reference/pagination) list, ordered starting from the most recently created - * subscription. For a full discussion of the subscription resource, see - * [Subscription](/core-concepts##subscription). - * - * Subscriptions can be filtered for a specific customer by using either the customer_id or - * external_customer_id query parameters. To filter subscriptions for multiple customers, use the - * customer_id[] or external_customer_id[] query parameters. - */ +/** @see [SubscriptionService.list] */ class SubscriptionListPage private constructor( - private val subscriptionsService: SubscriptionService, + private val service: SubscriptionService, private val params: SubscriptionListParams, - private val response: Response, + private val response: Subscriptions, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is SubscriptionListPage && subscriptionsService == other.subscriptionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionsService, params, response) /* spotless:on */ - - override fun toString() = - "SubscriptionListPage{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -69,141 +43,86 @@ private constructor( } return Optional.of( - SubscriptionListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): Optional { - return getNextPageParams().map { subscriptionsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - subscriptionsService: SubscriptionService, - params: SubscriptionListParams, - response: Response, - ) = SubscriptionListPage(subscriptionsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() + /** The parameters that were used to request this page. */ + fun params(): SubscriptionListParams = params - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") + /** The response that this page was parsed from. */ + fun response(): Subscriptions = response - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + fun toBuilder() = Builder().from(this) - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [SubscriptionListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [SubscriptionListPage]. */ + class Builder internal constructor() { - companion object { + private var service: SubscriptionService? = null + private var params: SubscriptionListParams? = null + private var response: Subscriptions? = null - /** Returns a mutable builder for constructing an instance of [SubscriptionListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(subscriptionListPage: SubscriptionListPage) = apply { + service = subscriptionListPage.service + params = subscriptionListPage.params + response = subscriptionListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: SubscriptionService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: SubscriptionListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: Subscriptions) = apply { this.response = response } + + /** + * Returns an immutable instance of [SubscriptionListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SubscriptionListPage = + SubscriptionListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: SubscriptionListPage) : Iterable { @@ -224,4 +143,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is SubscriptionListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "SubscriptionListPage{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPageAsync.kt index a7e714b9..45595107 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPageAsync.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/SubscriptionListPageAsync.kt @@ -2,17 +2,8 @@ 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.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.errors.OrbInvalidDataException +import com.withorb.api.core.checkRequired import com.withorb.api.services.async.SubscriptionServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,49 +11,32 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * This endpoint returns a list of all subscriptions for an account as a - * [paginated](/api-reference/pagination) list, ordered starting from the most recently created - * subscription. For a full discussion of the subscription resource, see - * [Subscription](/core-concepts##subscription). - * - * Subscriptions can be filtered for a specific customer by using either the customer_id or - * external_customer_id query parameters. To filter subscriptions for multiple customers, use the - * customer_id[] or external_customer_id[] query parameters. - */ +/** @see [SubscriptionServiceAsync.list] */ class SubscriptionListPageAsync private constructor( - private val subscriptionsService: SubscriptionServiceAsync, + private val service: SubscriptionServiceAsync, private val params: SubscriptionListParams, - private val response: Response, + private val response: Subscriptions, ) { - fun response(): Response = response - - fun data(): List = response().data() - - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is SubscriptionListPageAsync && subscriptionsService == other.subscriptionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionsService, params, response) /* spotless:on */ - - override fun toString() = - "SubscriptionListPageAsync{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() + + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") + + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -70,146 +44,89 @@ private constructor( } return Optional.of( - SubscriptionListParams.builder() - .from(params) - .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } } + params + .toBuilder() + .apply { + paginationMetadata() + .flatMap { it._nextCursor().getOptional("next_cursor") } + .ifPresent { cursor(it) } + } .build() ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { subscriptionsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - subscriptionsService: SubscriptionServiceAsync, - params: SubscriptionListParams, - response: Response, - ) = SubscriptionListPageAsync(subscriptionsService, params, response) - } - - class Response( - private val data: JsonField>, - private val paginationMetadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("pagination_metadata") - paginationMetadata: JsonField = JsonMissing.of(), - ) : this(data, paginationMetadata, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun paginationMetadata(): PaginationMetadata = - paginationMetadata.getRequired("pagination_metadata") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("pagination_metadata") - fun _paginationMetadata(): Optional> = - Optional.ofNullable(paginationMetadata) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): SubscriptionListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - paginationMetadata().validate() - validated = true - } + /** The response that this page was parsed from. */ + fun response(): Subscriptions = response - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OrbInvalidDataException) { - false - } + fun toBuilder() = Builder().from(this) - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [SubscriptionListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}" + /** A builder for [SubscriptionListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: SubscriptionServiceAsync? = null + private var params: SubscriptionListParams? = null + private var response: Subscriptions? = null - /** - * Returns a mutable builder for constructing an instance of - * [SubscriptionListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(subscriptionListPageAsync: SubscriptionListPageAsync) = apply { + service = subscriptionListPageAsync.service + params = subscriptionListPageAsync.params + response = subscriptionListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var paginationMetadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.paginationMetadata = page.paginationMetadata - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun paginationMetadata(paginationMetadata: PaginationMetadata) = - paginationMetadata(JsonField.of(paginationMetadata)) - - fun paginationMetadata(paginationMetadata: JsonField) = apply { - this.paginationMetadata = paginationMetadata - } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = - Response(data, paginationMetadata, additionalProperties.toMutableMap()) - } + fun service(service: SubscriptionServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: SubscriptionListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: Subscriptions) = apply { this.response = response } + + /** + * Returns an immutable instance of [SubscriptionListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SubscriptionListPageAsync = + SubscriptionListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: SubscriptionListPageAsync) { @@ -237,4 +154,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is SubscriptionListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "SubscriptionListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsyncImpl.kt index 7b552015..3a07f60d 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsyncImpl.kt @@ -22,6 +22,7 @@ import com.withorb.api.models.AlertCreateForSubscriptionParams import com.withorb.api.models.AlertDisableParams import com.withorb.api.models.AlertEnableParams import com.withorb.api.models.AlertListPageAsync +import com.withorb.api.models.AlertListPageResponse import com.withorb.api.models.AlertListParams import com.withorb.api.models.AlertRetrieveParams import com.withorb.api.models.AlertUpdateParams @@ -156,8 +157,8 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -183,11 +184,11 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie } } .let { - AlertListPageAsync.of( - AlertServiceAsyncImpl(clientOptions), - params, - it, - ) + AlertListPageAsync.builder() + .service(AlertServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CouponServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CouponServiceAsyncImpl.kt index cc36bb5b..38a83bca 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CouponServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CouponServiceAsyncImpl.kt @@ -20,6 +20,7 @@ import com.withorb.api.models.CouponArchiveParams import com.withorb.api.models.CouponCreateParams import com.withorb.api.models.CouponFetchParams import com.withorb.api.models.CouponListPageAsync +import com.withorb.api.models.CouponListPageResponse import com.withorb.api.models.CouponListParams import com.withorb.api.services.async.coupons.SubscriptionServiceAsync import com.withorb.api.services.async.coupons.SubscriptionServiceAsyncImpl @@ -109,8 +110,8 @@ class CouponServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -136,11 +137,11 @@ class CouponServiceAsyncImpl internal constructor(private val clientOptions: Cli } } .let { - CouponListPageAsync.of( - CouponServiceAsyncImpl(clientOptions), - params, - it, - ) + CouponListPageAsync.builder() + .service(CouponServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CreditNoteServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CreditNoteServiceAsyncImpl.kt index 5ac5ea04..1c25b2ee 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CreditNoteServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CreditNoteServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.withorb.api.models.CreditNote import com.withorb.api.models.CreditNoteCreateParams import com.withorb.api.models.CreditNoteFetchParams import com.withorb.api.models.CreditNoteListPageAsync +import com.withorb.api.models.CreditNoteListPageResponse import com.withorb.api.models.CreditNoteListParams import java.util.concurrent.CompletableFuture @@ -87,8 +88,8 @@ class CreditNoteServiceAsyncImpl internal constructor(private val clientOptions: } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -114,11 +115,11 @@ class CreditNoteServiceAsyncImpl internal constructor(private val clientOptions: } } .let { - CreditNoteListPageAsync.of( - CreditNoteServiceAsyncImpl(clientOptions), - params, - it, - ) + CreditNoteListPageAsync.builder() + .service(CreditNoteServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsyncImpl.kt index bda9bcf2..7ed7766f 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsyncImpl.kt @@ -23,6 +23,7 @@ import com.withorb.api.models.CustomerDeleteParams import com.withorb.api.models.CustomerFetchByExternalIdParams import com.withorb.api.models.CustomerFetchParams import com.withorb.api.models.CustomerListPageAsync +import com.withorb.api.models.CustomerListPageResponse import com.withorb.api.models.CustomerListParams import com.withorb.api.models.CustomerSyncPaymentMethodsFromGatewayByExternalCustomerIdParams import com.withorb.api.models.CustomerSyncPaymentMethodsFromGatewayParams @@ -209,8 +210,8 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -236,11 +237,11 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C } } .let { - CustomerListPageAsync.of( - CustomerServiceAsyncImpl(clientOptions), - params, - it, - ) + CustomerListPageAsync.builder() + .service(CustomerServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsyncImpl.kt index 7c1ead25..b6523976 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsyncImpl.kt @@ -20,6 +20,7 @@ import com.withorb.api.models.DimensionalPriceGroupCreateParams import com.withorb.api.models.DimensionalPriceGroupListPageAsync import com.withorb.api.models.DimensionalPriceGroupListParams import com.withorb.api.models.DimensionalPriceGroupRetrieveParams +import com.withorb.api.models.DimensionalPriceGroups import com.withorb.api.services.async.dimensionalPriceGroups.ExternalDimensionalPriceGroupIdServiceAsync import com.withorb.api.services.async.dimensionalPriceGroups.ExternalDimensionalPriceGroupIdServiceAsyncImpl import java.util.concurrent.CompletableFuture @@ -138,8 +139,8 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -165,11 +166,11 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric } } .let { - DimensionalPriceGroupListPageAsync.of( - DimensionalPriceGroupServiceAsyncImpl(clientOptions), - params, - it, - ) + DimensionalPriceGroupListPageAsync.builder() + .service(DimensionalPriceGroupServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncImpl.kt index 522765d4..e63e0397 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncImpl.kt @@ -22,6 +22,7 @@ import com.withorb.api.models.InvoiceFetchUpcomingParams import com.withorb.api.models.InvoiceFetchUpcomingResponse import com.withorb.api.models.InvoiceIssueParams import com.withorb.api.models.InvoiceListPageAsync +import com.withorb.api.models.InvoiceListPageResponse import com.withorb.api.models.InvoiceListParams import com.withorb.api.models.InvoiceMarkPaidParams import com.withorb.api.models.InvoicePayParams @@ -166,8 +167,8 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -193,11 +194,11 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl } } .let { - InvoiceListPageAsync.of( - InvoiceServiceAsyncImpl(clientOptions), - params, - it, - ) + InvoiceListPageAsync.builder() + .service(InvoiceServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/ItemServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/ItemServiceAsyncImpl.kt index f49a8d57..3bca007f 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/ItemServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/ItemServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.withorb.api.models.Item import com.withorb.api.models.ItemCreateParams import com.withorb.api.models.ItemFetchParams import com.withorb.api.models.ItemListPageAsync +import com.withorb.api.models.ItemListPageResponse import com.withorb.api.models.ItemListParams import com.withorb.api.models.ItemUpdateParams import java.util.concurrent.CompletableFuture @@ -125,8 +126,8 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -152,11 +153,11 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien } } .let { - ItemListPageAsync.of( - ItemServiceAsyncImpl(clientOptions), - params, - it, - ) + ItemListPageAsync.builder() + .service(ItemServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/MetricServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/MetricServiceAsyncImpl.kt index 80641249..7fcfab11 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/MetricServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/MetricServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.withorb.api.models.BillableMetric import com.withorb.api.models.MetricCreateParams import com.withorb.api.models.MetricFetchParams import com.withorb.api.models.MetricListPageAsync +import com.withorb.api.models.MetricListPageResponse import com.withorb.api.models.MetricListParams import com.withorb.api.models.MetricUpdateParams import java.util.concurrent.CompletableFuture @@ -125,8 +126,8 @@ class MetricServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -152,11 +153,11 @@ class MetricServiceAsyncImpl internal constructor(private val clientOptions: Cli } } .let { - MetricListPageAsync.of( - MetricServiceAsyncImpl(clientOptions), - params, - it, - ) + MetricListPageAsync.builder() + .service(MetricServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsyncImpl.kt index 33a0a4cc..6ed6bd37 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.withorb.api.models.Plan import com.withorb.api.models.PlanCreateParams import com.withorb.api.models.PlanFetchParams import com.withorb.api.models.PlanListPageAsync +import com.withorb.api.models.PlanListPageResponse import com.withorb.api.models.PlanListParams import com.withorb.api.models.PlanUpdateParams import com.withorb.api.services.async.plans.ExternalPlanIdServiceAsync @@ -139,8 +140,8 @@ class PlanServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -166,11 +167,11 @@ class PlanServiceAsyncImpl internal constructor(private val clientOptions: Clien } } .let { - PlanListPageAsync.of( - PlanServiceAsyncImpl(clientOptions), - params, - it, - ) + PlanListPageAsync.builder() + .service(PlanServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PriceServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PriceServiceAsyncImpl.kt index 62dc3652..0e1e32a6 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PriceServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PriceServiceAsyncImpl.kt @@ -21,6 +21,7 @@ import com.withorb.api.models.PriceEvaluateParams import com.withorb.api.models.PriceEvaluateResponse import com.withorb.api.models.PriceFetchParams import com.withorb.api.models.PriceListPageAsync +import com.withorb.api.models.PriceListPageResponse import com.withorb.api.models.PriceListParams import com.withorb.api.models.PriceUpdateParams import com.withorb.api.services.async.prices.ExternalPriceIdServiceAsync @@ -149,8 +150,8 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -176,11 +177,11 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie } } .let { - PriceListPageAsync.of( - PriceServiceAsyncImpl(clientOptions), - params, - it, - ) + PriceListPageAsync.builder() + .service(PriceServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncImpl.kt index e04aaf48..add175fc 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncImpl.kt @@ -24,6 +24,7 @@ import com.withorb.api.models.SubscriptionFetchCostsParams import com.withorb.api.models.SubscriptionFetchCostsResponse import com.withorb.api.models.SubscriptionFetchParams import com.withorb.api.models.SubscriptionFetchSchedulePageAsync +import com.withorb.api.models.SubscriptionFetchSchedulePageResponse import com.withorb.api.models.SubscriptionFetchScheduleParams import com.withorb.api.models.SubscriptionFetchUsageParams import com.withorb.api.models.SubscriptionListPageAsync @@ -46,6 +47,7 @@ import com.withorb.api.models.SubscriptionUpdateParams import com.withorb.api.models.SubscriptionUpdateTrialParams import com.withorb.api.models.SubscriptionUpdateTrialResponse import com.withorb.api.models.SubscriptionUsage +import com.withorb.api.models.Subscriptions import java.util.concurrent.CompletableFuture class SubscriptionServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : @@ -239,9 +241,8 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) override fun list( params: SubscriptionListParams, @@ -266,11 +267,11 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption } } .let { - SubscriptionListPageAsync.of( - SubscriptionServiceAsyncImpl(clientOptions), - params, - it, - ) + SubscriptionListPageAsync.builder() + .service(SubscriptionServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } @@ -366,8 +367,8 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption } } - private val fetchScheduleHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val fetchScheduleHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun fetchSchedule( @@ -393,11 +394,11 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption } } .let { - SubscriptionFetchSchedulePageAsync.of( - SubscriptionServiceAsyncImpl(clientOptions), - params, - it, - ) + SubscriptionFetchSchedulePageAsync.builder() + .service(SubscriptionServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/coupons/SubscriptionServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/coupons/SubscriptionServiceAsyncImpl.kt index f16d7df4..f749a531 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/coupons/SubscriptionServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/coupons/SubscriptionServiceAsyncImpl.kt @@ -16,6 +16,7 @@ import com.withorb.api.core.http.parseable import com.withorb.api.core.prepareAsync import com.withorb.api.models.CouponSubscriptionListPageAsync import com.withorb.api.models.CouponSubscriptionListParams +import com.withorb.api.models.Subscriptions import java.util.concurrent.CompletableFuture class SubscriptionServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : @@ -39,9 +40,8 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) override fun list( params: CouponSubscriptionListParams, @@ -66,11 +66,11 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption } } .let { - CouponSubscriptionListPageAsync.of( - SubscriptionServiceAsyncImpl(clientOptions), - params, - it, - ) + CouponSubscriptionListPageAsync.builder() + .service(SubscriptionServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/BalanceTransactionServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/BalanceTransactionServiceAsyncImpl.kt index 86f9e5a9..b2c2284d 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/BalanceTransactionServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/BalanceTransactionServiceAsyncImpl.kt @@ -18,6 +18,7 @@ import com.withorb.api.core.prepareAsync import com.withorb.api.models.CustomerBalanceTransactionCreateParams import com.withorb.api.models.CustomerBalanceTransactionCreateResponse import com.withorb.api.models.CustomerBalanceTransactionListPageAsync +import com.withorb.api.models.CustomerBalanceTransactionListPageResponse import com.withorb.api.models.CustomerBalanceTransactionListParams import java.util.concurrent.CompletableFuture @@ -80,8 +81,8 @@ internal constructor(private val clientOptions: ClientOptions) : BalanceTransact } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -107,11 +108,11 @@ internal constructor(private val clientOptions: ClientOptions) : BalanceTransact } } .let { - CustomerBalanceTransactionListPageAsync.of( - BalanceTransactionServiceAsyncImpl(clientOptions), - params, - it, - ) + CustomerBalanceTransactionListPageAsync.builder() + .service(BalanceTransactionServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CreditServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CreditServiceAsyncImpl.kt index 057c0ac6..39fad882 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CreditServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CreditServiceAsyncImpl.kt @@ -15,8 +15,10 @@ import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable import com.withorb.api.core.prepareAsync import com.withorb.api.models.CustomerCreditListByExternalIdPageAsync +import com.withorb.api.models.CustomerCreditListByExternalIdPageResponse import com.withorb.api.models.CustomerCreditListByExternalIdParams import com.withorb.api.models.CustomerCreditListPageAsync +import com.withorb.api.models.CustomerCreditListPageResponse import com.withorb.api.models.CustomerCreditListParams import com.withorb.api.services.async.customers.credits.LedgerServiceAsync import com.withorb.api.services.async.customers.credits.LedgerServiceAsyncImpl @@ -72,8 +74,8 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli override fun topUps(): TopUpServiceAsync.WithRawResponse = topUps - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -99,19 +101,18 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli } } .let { - CustomerCreditListPageAsync.of( - CreditServiceAsyncImpl(clientOptions), - params, - it, - ) + CustomerCreditListPageAsync.builder() + .service(CreditServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } } - private val listByExternalIdHandler: - Handler = - jsonHandler(clientOptions.jsonMapper) + private val listByExternalIdHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listByExternalId( @@ -142,11 +143,11 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli } } .let { - CustomerCreditListByExternalIdPageAsync.of( - CreditServiceAsyncImpl(clientOptions), - params, - it, - ) + CustomerCreditListByExternalIdPageAsync.builder() + .service(CreditServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncImpl.kt index 23fb93e9..111daf6a 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncImpl.kt @@ -20,8 +20,10 @@ import com.withorb.api.models.CustomerCreditLedgerCreateEntryByExternalIdRespons import com.withorb.api.models.CustomerCreditLedgerCreateEntryParams import com.withorb.api.models.CustomerCreditLedgerCreateEntryResponse import com.withorb.api.models.CustomerCreditLedgerListByExternalIdPageAsync +import com.withorb.api.models.CustomerCreditLedgerListByExternalIdPageResponse import com.withorb.api.models.CustomerCreditLedgerListByExternalIdParams import com.withorb.api.models.CustomerCreditLedgerListPageAsync +import com.withorb.api.models.CustomerCreditLedgerListPageResponse import com.withorb.api.models.CustomerCreditLedgerListParams import java.util.concurrent.CompletableFuture @@ -67,8 +69,8 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -94,11 +96,11 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli } } .let { - CustomerCreditLedgerListPageAsync.of( - LedgerServiceAsyncImpl(clientOptions), - params, - it, - ) + CustomerCreditLedgerListPageAsync.builder() + .service(LedgerServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } @@ -176,10 +178,8 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli } private val listByExternalIdHandler: - Handler = - jsonHandler( - clientOptions.jsonMapper - ) + Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listByExternalId( @@ -211,11 +211,11 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli } } .let { - CustomerCreditLedgerListByExternalIdPageAsync.of( - LedgerServiceAsyncImpl(clientOptions), - params, - it, - ) + CustomerCreditLedgerListByExternalIdPageAsync.builder() + .service(LedgerServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/TopUpServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/TopUpServiceAsyncImpl.kt index 9e647dd2..09ca2531 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/TopUpServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/TopUpServiceAsyncImpl.kt @@ -24,8 +24,10 @@ import com.withorb.api.models.CustomerCreditTopUpCreateResponse import com.withorb.api.models.CustomerCreditTopUpDeleteByExternalIdParams import com.withorb.api.models.CustomerCreditTopUpDeleteParams import com.withorb.api.models.CustomerCreditTopUpListByExternalIdPageAsync +import com.withorb.api.models.CustomerCreditTopUpListByExternalIdPageResponse import com.withorb.api.models.CustomerCreditTopUpListByExternalIdParams import com.withorb.api.models.CustomerCreditTopUpListPageAsync +import com.withorb.api.models.CustomerCreditTopUpListPageResponse import com.withorb.api.models.CustomerCreditTopUpListParams import java.util.concurrent.CompletableFuture @@ -116,8 +118,8 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -143,11 +145,11 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie } } .let { - CustomerCreditTopUpListPageAsync.of( - TopUpServiceAsyncImpl(clientOptions), - params, - it, - ) + CustomerCreditTopUpListPageAsync.builder() + .service(TopUpServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } @@ -248,10 +250,8 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie } private val listByExternalIdHandler: - Handler = - jsonHandler( - clientOptions.jsonMapper - ) + Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listByExternalId( @@ -283,11 +283,11 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie } } .let { - CustomerCreditTopUpListByExternalIdPageAsync.of( - TopUpServiceAsyncImpl(clientOptions), - params, - it, - ) + CustomerCreditTopUpListByExternalIdPageAsync.builder() + .service(TopUpServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsyncImpl.kt index 26392fd4..cff62b17 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsyncImpl.kt @@ -22,6 +22,7 @@ import com.withorb.api.models.EventBackfillCreateResponse import com.withorb.api.models.EventBackfillFetchParams import com.withorb.api.models.EventBackfillFetchResponse import com.withorb.api.models.EventBackfillListPageAsync +import com.withorb.api.models.EventBackfillListPageResponse import com.withorb.api.models.EventBackfillListParams import com.withorb.api.models.EventBackfillRevertParams import com.withorb.api.models.EventBackfillRevertResponse @@ -107,8 +108,8 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -134,11 +135,11 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C } } .let { - EventBackfillListPageAsync.of( - BackfillServiceAsyncImpl(clientOptions), - params, - it, - ) + EventBackfillListPageAsync.builder() + .service(BackfillServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/AlertServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/AlertServiceImpl.kt index 78449d3e..31e2fed9 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/AlertServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/AlertServiceImpl.kt @@ -22,6 +22,7 @@ import com.withorb.api.models.AlertCreateForSubscriptionParams import com.withorb.api.models.AlertDisableParams import com.withorb.api.models.AlertEnableParams import com.withorb.api.models.AlertListPage +import com.withorb.api.models.AlertListPageResponse import com.withorb.api.models.AlertListParams import com.withorb.api.models.AlertRetrieveParams import com.withorb.api.models.AlertUpdateParams @@ -134,8 +135,8 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -158,7 +159,13 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt it.validate() } } - .let { AlertListPage.of(AlertServiceImpl(clientOptions), params, it) } + .let { + AlertListPage.builder() + .service(AlertServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CouponServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CouponServiceImpl.kt index f14f6514..517aa4ba 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CouponServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CouponServiceImpl.kt @@ -20,6 +20,7 @@ import com.withorb.api.models.CouponArchiveParams import com.withorb.api.models.CouponCreateParams import com.withorb.api.models.CouponFetchParams import com.withorb.api.models.CouponListPage +import com.withorb.api.models.CouponListPageResponse import com.withorb.api.models.CouponListParams import com.withorb.api.services.blocking.coupons.SubscriptionService import com.withorb.api.services.blocking.coupons.SubscriptionServiceImpl @@ -93,8 +94,8 @@ class CouponServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -117,7 +118,13 @@ class CouponServiceImpl internal constructor(private val clientOptions: ClientOp it.validate() } } - .let { CouponListPage.of(CouponServiceImpl(clientOptions), params, it) } + .let { + CouponListPage.builder() + .service(CouponServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CreditNoteServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CreditNoteServiceImpl.kt index 3ca147c0..a036d08b 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CreditNoteServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CreditNoteServiceImpl.kt @@ -19,6 +19,7 @@ import com.withorb.api.models.CreditNote import com.withorb.api.models.CreditNoteCreateParams import com.withorb.api.models.CreditNoteFetchParams import com.withorb.api.models.CreditNoteListPage +import com.withorb.api.models.CreditNoteListPageResponse import com.withorb.api.models.CreditNoteListParams class CreditNoteServiceImpl internal constructor(private val clientOptions: ClientOptions) : @@ -80,8 +81,8 @@ class CreditNoteServiceImpl internal constructor(private val clientOptions: Clie } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -104,7 +105,13 @@ class CreditNoteServiceImpl internal constructor(private val clientOptions: Clie it.validate() } } - .let { CreditNoteListPage.of(CreditNoteServiceImpl(clientOptions), params, it) } + .let { + CreditNoteListPage.builder() + .service(CreditNoteServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerServiceImpl.kt index dea8ffd8..da329b17 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerServiceImpl.kt @@ -23,6 +23,7 @@ import com.withorb.api.models.CustomerDeleteParams import com.withorb.api.models.CustomerFetchByExternalIdParams import com.withorb.api.models.CustomerFetchParams import com.withorb.api.models.CustomerListPage +import com.withorb.api.models.CustomerListPageResponse import com.withorb.api.models.CustomerListParams import com.withorb.api.models.CustomerSyncPaymentMethodsFromGatewayByExternalCustomerIdParams import com.withorb.api.models.CustomerSyncPaymentMethodsFromGatewayParams @@ -191,8 +192,8 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -215,7 +216,13 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client it.validate() } } - .let { CustomerListPage.of(CustomerServiceImpl(clientOptions), params, it) } + .let { + CustomerListPage.builder() + .service(CustomerServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupServiceImpl.kt index 9b6aeab2..5aef9624 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupServiceImpl.kt @@ -20,6 +20,7 @@ import com.withorb.api.models.DimensionalPriceGroupCreateParams import com.withorb.api.models.DimensionalPriceGroupListPage import com.withorb.api.models.DimensionalPriceGroupListParams import com.withorb.api.models.DimensionalPriceGroupRetrieveParams +import com.withorb.api.models.DimensionalPriceGroups import com.withorb.api.services.blocking.dimensionalPriceGroups.ExternalDimensionalPriceGroupIdService import com.withorb.api.services.blocking.dimensionalPriceGroups.ExternalDimensionalPriceGroupIdServiceImpl @@ -128,8 +129,8 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -153,11 +154,11 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric } } .let { - DimensionalPriceGroupListPage.of( - DimensionalPriceGroupServiceImpl(clientOptions), - params, - it, - ) + DimensionalPriceGroupListPage.builder() + .service(DimensionalPriceGroupServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceServiceImpl.kt index 99caab96..9ca3b288 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceServiceImpl.kt @@ -22,6 +22,7 @@ import com.withorb.api.models.InvoiceFetchUpcomingParams import com.withorb.api.models.InvoiceFetchUpcomingResponse import com.withorb.api.models.InvoiceIssueParams import com.withorb.api.models.InvoiceListPage +import com.withorb.api.models.InvoiceListPageResponse import com.withorb.api.models.InvoiceListParams import com.withorb.api.models.InvoiceMarkPaidParams import com.withorb.api.models.InvoicePayParams @@ -138,8 +139,8 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -162,7 +163,13 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO it.validate() } } - .let { InvoiceListPage.of(InvoiceServiceImpl(clientOptions), params, it) } + .let { + InvoiceListPage.builder() + .service(InvoiceServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/ItemServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/ItemServiceImpl.kt index fd65f62a..04065b32 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/ItemServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/ItemServiceImpl.kt @@ -19,6 +19,7 @@ import com.withorb.api.models.Item import com.withorb.api.models.ItemCreateParams import com.withorb.api.models.ItemFetchParams import com.withorb.api.models.ItemListPage +import com.withorb.api.models.ItemListPageResponse import com.withorb.api.models.ItemListParams import com.withorb.api.models.ItemUpdateParams @@ -105,8 +106,8 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -129,7 +130,13 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti it.validate() } } - .let { ItemListPage.of(ItemServiceImpl(clientOptions), params, it) } + .let { + ItemListPage.builder() + .service(ItemServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/MetricServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/MetricServiceImpl.kt index fa83164d..cc6119c6 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/MetricServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/MetricServiceImpl.kt @@ -19,6 +19,7 @@ import com.withorb.api.models.BillableMetric import com.withorb.api.models.MetricCreateParams import com.withorb.api.models.MetricFetchParams import com.withorb.api.models.MetricListPage +import com.withorb.api.models.MetricListPageResponse import com.withorb.api.models.MetricListParams import com.withorb.api.models.MetricUpdateParams @@ -112,8 +113,8 @@ class MetricServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -136,7 +137,13 @@ class MetricServiceImpl internal constructor(private val clientOptions: ClientOp it.validate() } } - .let { MetricListPage.of(MetricServiceImpl(clientOptions), params, it) } + .let { + MetricListPage.builder() + .service(MetricServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PlanServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PlanServiceImpl.kt index a3d43019..a817592d 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PlanServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PlanServiceImpl.kt @@ -19,6 +19,7 @@ import com.withorb.api.models.Plan import com.withorb.api.models.PlanCreateParams import com.withorb.api.models.PlanFetchParams import com.withorb.api.models.PlanListPage +import com.withorb.api.models.PlanListPageResponse import com.withorb.api.models.PlanListParams import com.withorb.api.models.PlanUpdateParams import com.withorb.api.services.blocking.plans.ExternalPlanIdService @@ -119,8 +120,8 @@ class PlanServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -143,7 +144,13 @@ class PlanServiceImpl internal constructor(private val clientOptions: ClientOpti it.validate() } } - .let { PlanListPage.of(PlanServiceImpl(clientOptions), params, it) } + .let { + PlanListPage.builder() + .service(PlanServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PriceServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PriceServiceImpl.kt index d2722631..556cb014 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PriceServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PriceServiceImpl.kt @@ -21,6 +21,7 @@ import com.withorb.api.models.PriceEvaluateParams import com.withorb.api.models.PriceEvaluateResponse import com.withorb.api.models.PriceFetchParams import com.withorb.api.models.PriceListPage +import com.withorb.api.models.PriceListPageResponse import com.withorb.api.models.PriceListParams import com.withorb.api.models.PriceUpdateParams import com.withorb.api.services.blocking.prices.ExternalPriceIdService @@ -129,8 +130,8 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -153,7 +154,13 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt it.validate() } } - .let { PriceListPage.of(PriceServiceImpl(clientOptions), params, it) } + .let { + PriceListPage.builder() + .service(PriceServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionServiceImpl.kt index 072646a2..f327e26b 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionServiceImpl.kt @@ -24,6 +24,7 @@ import com.withorb.api.models.SubscriptionFetchCostsParams import com.withorb.api.models.SubscriptionFetchCostsResponse import com.withorb.api.models.SubscriptionFetchParams import com.withorb.api.models.SubscriptionFetchSchedulePage +import com.withorb.api.models.SubscriptionFetchSchedulePageResponse import com.withorb.api.models.SubscriptionFetchScheduleParams import com.withorb.api.models.SubscriptionFetchUsageParams import com.withorb.api.models.SubscriptionListPage @@ -46,6 +47,7 @@ import com.withorb.api.models.SubscriptionUpdateParams import com.withorb.api.models.SubscriptionUpdateTrialParams import com.withorb.api.models.SubscriptionUpdateTrialResponse import com.withorb.api.models.SubscriptionUsage +import com.withorb.api.models.Subscriptions class SubscriptionServiceImpl internal constructor(private val clientOptions: ClientOptions) : SubscriptionService { @@ -228,9 +230,8 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) override fun list( params: SubscriptionListParams, @@ -253,7 +254,11 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl } } .let { - SubscriptionListPage.of(SubscriptionServiceImpl(clientOptions), params, it) + SubscriptionListPage.builder() + .service(SubscriptionServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } @@ -339,8 +344,8 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl } } - private val fetchScheduleHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val fetchScheduleHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun fetchSchedule( @@ -364,11 +369,11 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl } } .let { - SubscriptionFetchSchedulePage.of( - SubscriptionServiceImpl(clientOptions), - params, - it, - ) + SubscriptionFetchSchedulePage.builder() + .service(SubscriptionServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/coupons/SubscriptionServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/coupons/SubscriptionServiceImpl.kt index ff1b5ac5..d19b9301 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/coupons/SubscriptionServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/coupons/SubscriptionServiceImpl.kt @@ -16,6 +16,7 @@ import com.withorb.api.core.http.parseable import com.withorb.api.core.prepare import com.withorb.api.models.CouponSubscriptionListPage import com.withorb.api.models.CouponSubscriptionListParams +import com.withorb.api.models.Subscriptions class SubscriptionServiceImpl internal constructor(private val clientOptions: ClientOptions) : SubscriptionService { @@ -38,9 +39,8 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) override fun list( params: CouponSubscriptionListParams, @@ -63,11 +63,11 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl } } .let { - CouponSubscriptionListPage.of( - SubscriptionServiceImpl(clientOptions), - params, - it, - ) + CouponSubscriptionListPage.builder() + .service(SubscriptionServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/BalanceTransactionServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/BalanceTransactionServiceImpl.kt index 60f17384..f5b3f888 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/BalanceTransactionServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/BalanceTransactionServiceImpl.kt @@ -18,6 +18,7 @@ import com.withorb.api.core.prepare import com.withorb.api.models.CustomerBalanceTransactionCreateParams import com.withorb.api.models.CustomerBalanceTransactionCreateResponse import com.withorb.api.models.CustomerBalanceTransactionListPage +import com.withorb.api.models.CustomerBalanceTransactionListPageResponse import com.withorb.api.models.CustomerBalanceTransactionListParams class BalanceTransactionServiceImpl internal constructor(private val clientOptions: ClientOptions) : @@ -76,8 +77,8 @@ class BalanceTransactionServiceImpl internal constructor(private val clientOptio } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -101,11 +102,11 @@ class BalanceTransactionServiceImpl internal constructor(private val clientOptio } } .let { - CustomerBalanceTransactionListPage.of( - BalanceTransactionServiceImpl(clientOptions), - params, - it, - ) + CustomerBalanceTransactionListPage.builder() + .service(BalanceTransactionServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CreditServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CreditServiceImpl.kt index cb3c858d..421613a6 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CreditServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CreditServiceImpl.kt @@ -15,8 +15,10 @@ import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable import com.withorb.api.core.prepare import com.withorb.api.models.CustomerCreditListByExternalIdPage +import com.withorb.api.models.CustomerCreditListByExternalIdPageResponse import com.withorb.api.models.CustomerCreditListByExternalIdParams import com.withorb.api.models.CustomerCreditListPage +import com.withorb.api.models.CustomerCreditListPageResponse import com.withorb.api.models.CustomerCreditListParams import com.withorb.api.services.blocking.customers.credits.LedgerService import com.withorb.api.services.blocking.customers.credits.LedgerServiceImpl @@ -71,8 +73,8 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp override fun topUps(): TopUpService.WithRawResponse = topUps - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -95,12 +97,18 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp it.validate() } } - .let { CustomerCreditListPage.of(CreditServiceImpl(clientOptions), params, it) } + .let { + CustomerCreditListPage.builder() + .service(CreditServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } - private val listByExternalIdHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listByExternalIdHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listByExternalId( @@ -129,11 +137,11 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp } } .let { - CustomerCreditListByExternalIdPage.of( - CreditServiceImpl(clientOptions), - params, - it, - ) + CustomerCreditListByExternalIdPage.builder() + .service(CreditServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceImpl.kt index 278d574e..25a4c60b 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceImpl.kt @@ -20,8 +20,10 @@ import com.withorb.api.models.CustomerCreditLedgerCreateEntryByExternalIdRespons import com.withorb.api.models.CustomerCreditLedgerCreateEntryParams import com.withorb.api.models.CustomerCreditLedgerCreateEntryResponse import com.withorb.api.models.CustomerCreditLedgerListByExternalIdPage +import com.withorb.api.models.CustomerCreditLedgerListByExternalIdPageResponse import com.withorb.api.models.CustomerCreditLedgerListByExternalIdParams import com.withorb.api.models.CustomerCreditLedgerListPage +import com.withorb.api.models.CustomerCreditLedgerListPageResponse import com.withorb.api.models.CustomerCreditLedgerListParams class LedgerServiceImpl internal constructor(private val clientOptions: ClientOptions) : @@ -66,8 +68,8 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -91,11 +93,11 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp } } .let { - CustomerCreditLedgerListPage.of( - LedgerServiceImpl(clientOptions), - params, - it, - ) + CustomerCreditLedgerListPage.builder() + .service(LedgerServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } @@ -166,8 +168,8 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp } private val listByExternalIdHandler: - Handler = - jsonHandler(clientOptions.jsonMapper) + Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listByExternalId( @@ -197,11 +199,11 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp } } .let { - CustomerCreditLedgerListByExternalIdPage.of( - LedgerServiceImpl(clientOptions), - params, - it, - ) + CustomerCreditLedgerListByExternalIdPage.builder() + .service(LedgerServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/TopUpServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/TopUpServiceImpl.kt index c7b4b5c2..626104a6 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/TopUpServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/TopUpServiceImpl.kt @@ -24,8 +24,10 @@ import com.withorb.api.models.CustomerCreditTopUpCreateResponse import com.withorb.api.models.CustomerCreditTopUpDeleteByExternalIdParams import com.withorb.api.models.CustomerCreditTopUpDeleteParams import com.withorb.api.models.CustomerCreditTopUpListByExternalIdPage +import com.withorb.api.models.CustomerCreditTopUpListByExternalIdPageResponse import com.withorb.api.models.CustomerCreditTopUpListByExternalIdParams import com.withorb.api.models.CustomerCreditTopUpListPage +import com.withorb.api.models.CustomerCreditTopUpListPageResponse import com.withorb.api.models.CustomerCreditTopUpListParams class TopUpServiceImpl internal constructor(private val clientOptions: ClientOptions) : @@ -111,8 +113,8 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -136,7 +138,11 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt } } .let { - CustomerCreditTopUpListPage.of(TopUpServiceImpl(clientOptions), params, it) + CustomerCreditTopUpListPage.builder() + .service(TopUpServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } @@ -227,8 +233,8 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt } private val listByExternalIdHandler: - Handler = - jsonHandler(clientOptions.jsonMapper) + Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listByExternalId( @@ -258,11 +264,11 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt } } .let { - CustomerCreditTopUpListByExternalIdPage.of( - TopUpServiceImpl(clientOptions), - params, - it, - ) + CustomerCreditTopUpListByExternalIdPage.builder() + .service(TopUpServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillServiceImpl.kt index cb5140f9..5f2af318 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillServiceImpl.kt @@ -22,6 +22,7 @@ import com.withorb.api.models.EventBackfillCreateResponse import com.withorb.api.models.EventBackfillFetchParams import com.withorb.api.models.EventBackfillFetchResponse import com.withorb.api.models.EventBackfillListPage +import com.withorb.api.models.EventBackfillListPageResponse import com.withorb.api.models.EventBackfillListParams import com.withorb.api.models.EventBackfillRevertParams import com.withorb.api.models.EventBackfillRevertResponse @@ -103,8 +104,8 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -128,7 +129,11 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client } } .let { - EventBackfillListPage.of(BackfillServiceImpl(clientOptions), params, it) + EventBackfillListPage.builder() + .service(BackfillServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/AlertListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/AlertListPageResponseTest.kt new file mode 100644 index 00000000..e941c2a8 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/AlertListPageResponseTest.kt @@ -0,0 +1,123 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AlertListPageResponseTest { + + @Test + fun create() { + val alertListPageResponse = + AlertListPageResponse.builder() + .addData( + Alert.builder() + .id("XuxCbt7x9L82yyeF") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .currency("currency") + .customer( + Alert.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .enabled(true) + .metric(Alert.Metric.builder().id("id").build()) + .plan( + Alert.Plan.builder() + .id("m2t5akQeh2obwxeU") + .externalPlanId("m2t5akQeh2obwxeU") + .name("Example plan") + .planVersion("plan_version") + .build() + ) + .subscription(Alert.Subscription.builder().id("VDGsT23osdLb84KD").build()) + .addThreshold(Alert.Threshold.builder().value(0.0).build()) + .type(Alert.Type.CREDIT_BALANCE_DEPLETED) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(alertListPageResponse.data()) + .containsExactly( + Alert.builder() + .id("XuxCbt7x9L82yyeF") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .currency("currency") + .customer( + Alert.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .enabled(true) + .metric(Alert.Metric.builder().id("id").build()) + .plan( + Alert.Plan.builder() + .id("m2t5akQeh2obwxeU") + .externalPlanId("m2t5akQeh2obwxeU") + .name("Example plan") + .planVersion("plan_version") + .build() + ) + .subscription(Alert.Subscription.builder().id("VDGsT23osdLb84KD").build()) + .addThreshold(Alert.Threshold.builder().value(0.0).build()) + .type(Alert.Type.CREDIT_BALANCE_DEPLETED) + .build() + ) + assertThat(alertListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val alertListPageResponse = + AlertListPageResponse.builder() + .addData( + Alert.builder() + .id("XuxCbt7x9L82yyeF") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .currency("currency") + .customer( + Alert.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .enabled(true) + .metric(Alert.Metric.builder().id("id").build()) + .plan( + Alert.Plan.builder() + .id("m2t5akQeh2obwxeU") + .externalPlanId("m2t5akQeh2obwxeU") + .name("Example plan") + .planVersion("plan_version") + .build() + ) + .subscription(Alert.Subscription.builder().id("VDGsT23osdLb84KD").build()) + .addThreshold(Alert.Threshold.builder().value(0.0).build()) + .type(Alert.Type.CREDIT_BALANCE_DEPLETED) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedAlertListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(alertListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAlertListPageResponse).isEqualTo(alertListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CouponListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CouponListPageResponseTest.kt new file mode 100644 index 00000000..7016198a --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CouponListPageResponseTest.kt @@ -0,0 +1,102 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CouponListPageResponseTest { + + @Test + fun create() { + val couponListPageResponse = + CouponListPageResponse.builder() + .addData( + Coupon.builder() + .id("7iz2yanVjQoBZhyH") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .durationInMonths(12L) + .maxRedemptions(0L) + .redemptionCode("HALFOFF") + .timesRedeemed(0L) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(couponListPageResponse.data()) + .containsExactly( + Coupon.builder() + .id("7iz2yanVjQoBZhyH") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .durationInMonths(12L) + .maxRedemptions(0L) + .redemptionCode("HALFOFF") + .timesRedeemed(0L) + .build() + ) + assertThat(couponListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val couponListPageResponse = + CouponListPageResponse.builder() + .addData( + Coupon.builder() + .id("7iz2yanVjQoBZhyH") + .archivedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .durationInMonths(12L) + .maxRedemptions(0L) + .redemptionCode("HALFOFF") + .timesRedeemed(0L) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedCouponListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(couponListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCouponListPageResponse).isEqualTo(couponListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CreditNoteListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CreditNoteListPageResponseTest.kt new file mode 100644 index 00000000..8273676b --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CreditNoteListPageResponseTest.kt @@ -0,0 +1,291 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CreditNoteListPageResponseTest { + + @Test + fun create() { + val creditNoteListPageResponse = + CreditNoteListPageResponse.builder() + .addData( + CreditNote.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditNoteNumber("credit_note_number") + .creditNotePdf("credit_note_pdf") + .customer( + CreditNote.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .invoiceId("invoice_id") + .addLineItem( + CreditNote.LineItem.builder() + .id("id") + .amount("amount") + .itemId("item_id") + .name("name") + .quantity(0.0) + .subtotal("subtotal") + .addTaxAmount( + CreditNote.LineItem.TaxAmount.builder() + .amount("amount") + .taxRateDescription("tax_rate_description") + .taxRatePercentage("tax_rate_percentage") + .build() + ) + .addDiscount( + CreditNote.LineItem.Discount.builder() + .id("id") + .amountApplied("amount_applied") + .addAppliesToPriceId("string") + .discountType( + CreditNote.LineItem.Discount.DiscountType.PERCENTAGE + ) + .percentageDiscount(0.0) + .amountDiscount("amount_discount") + .reason("reason") + .build() + ) + .build() + ) + .maximumAmountAdjustment( + CreditNote.MaximumAmountAdjustment.builder() + .amountApplied("amount_applied") + .discountType( + CreditNote.MaximumAmountAdjustment.DiscountType.PERCENTAGE + ) + .percentageDiscount(0.0) + .addAppliesToPrice( + CreditNote.MaximumAmountAdjustment.AppliesToPrice.builder() + .id("id") + .name("name") + .build() + ) + .reason("reason") + .build() + ) + .memo("memo") + .minimumAmountRefunded("minimum_amount_refunded") + .reason(CreditNote.Reason.DUPLICATE) + .subtotal("subtotal") + .total("total") + .type(CreditNote.Type.REFUND) + .voidedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addDiscount( + CreditNote.Discount.builder() + .amountApplied("amount_applied") + .discountType(CreditNote.Discount.DiscountType.PERCENTAGE) + .percentageDiscount(0.0) + .addAppliesToPrice( + CreditNote.Discount.AppliesToPrice.builder() + .id("id") + .name("name") + .build() + ) + .reason("reason") + .build() + ) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(creditNoteListPageResponse.data()) + .containsExactly( + CreditNote.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditNoteNumber("credit_note_number") + .creditNotePdf("credit_note_pdf") + .customer( + CreditNote.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .invoiceId("invoice_id") + .addLineItem( + CreditNote.LineItem.builder() + .id("id") + .amount("amount") + .itemId("item_id") + .name("name") + .quantity(0.0) + .subtotal("subtotal") + .addTaxAmount( + CreditNote.LineItem.TaxAmount.builder() + .amount("amount") + .taxRateDescription("tax_rate_description") + .taxRatePercentage("tax_rate_percentage") + .build() + ) + .addDiscount( + CreditNote.LineItem.Discount.builder() + .id("id") + .amountApplied("amount_applied") + .addAppliesToPriceId("string") + .discountType( + CreditNote.LineItem.Discount.DiscountType.PERCENTAGE + ) + .percentageDiscount(0.0) + .amountDiscount("amount_discount") + .reason("reason") + .build() + ) + .build() + ) + .maximumAmountAdjustment( + CreditNote.MaximumAmountAdjustment.builder() + .amountApplied("amount_applied") + .discountType( + CreditNote.MaximumAmountAdjustment.DiscountType.PERCENTAGE + ) + .percentageDiscount(0.0) + .addAppliesToPrice( + CreditNote.MaximumAmountAdjustment.AppliesToPrice.builder() + .id("id") + .name("name") + .build() + ) + .reason("reason") + .build() + ) + .memo("memo") + .minimumAmountRefunded("minimum_amount_refunded") + .reason(CreditNote.Reason.DUPLICATE) + .subtotal("subtotal") + .total("total") + .type(CreditNote.Type.REFUND) + .voidedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addDiscount( + CreditNote.Discount.builder() + .amountApplied("amount_applied") + .discountType(CreditNote.Discount.DiscountType.PERCENTAGE) + .percentageDiscount(0.0) + .addAppliesToPrice( + CreditNote.Discount.AppliesToPrice.builder() + .id("id") + .name("name") + .build() + ) + .reason("reason") + .build() + ) + .build() + ) + assertThat(creditNoteListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val creditNoteListPageResponse = + CreditNoteListPageResponse.builder() + .addData( + CreditNote.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditNoteNumber("credit_note_number") + .creditNotePdf("credit_note_pdf") + .customer( + CreditNote.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .invoiceId("invoice_id") + .addLineItem( + CreditNote.LineItem.builder() + .id("id") + .amount("amount") + .itemId("item_id") + .name("name") + .quantity(0.0) + .subtotal("subtotal") + .addTaxAmount( + CreditNote.LineItem.TaxAmount.builder() + .amount("amount") + .taxRateDescription("tax_rate_description") + .taxRatePercentage("tax_rate_percentage") + .build() + ) + .addDiscount( + CreditNote.LineItem.Discount.builder() + .id("id") + .amountApplied("amount_applied") + .addAppliesToPriceId("string") + .discountType( + CreditNote.LineItem.Discount.DiscountType.PERCENTAGE + ) + .percentageDiscount(0.0) + .amountDiscount("amount_discount") + .reason("reason") + .build() + ) + .build() + ) + .maximumAmountAdjustment( + CreditNote.MaximumAmountAdjustment.builder() + .amountApplied("amount_applied") + .discountType( + CreditNote.MaximumAmountAdjustment.DiscountType.PERCENTAGE + ) + .percentageDiscount(0.0) + .addAppliesToPrice( + CreditNote.MaximumAmountAdjustment.AppliesToPrice.builder() + .id("id") + .name("name") + .build() + ) + .reason("reason") + .build() + ) + .memo("memo") + .minimumAmountRefunded("minimum_amount_refunded") + .reason(CreditNote.Reason.DUPLICATE) + .subtotal("subtotal") + .total("total") + .type(CreditNote.Type.REFUND) + .voidedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addDiscount( + CreditNote.Discount.builder() + .amountApplied("amount_applied") + .discountType(CreditNote.Discount.DiscountType.PERCENTAGE) + .percentageDiscount(0.0) + .addAppliesToPrice( + CreditNote.Discount.AppliesToPrice.builder() + .id("id") + .name("name") + .build() + ) + .reason("reason") + .build() + ) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedCreditNoteListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(creditNoteListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCreditNoteListPageResponse).isEqualTo(creditNoteListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageResponseTest.kt new file mode 100644 index 00000000..16c904d8 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageResponseTest.kt @@ -0,0 +1,110 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CustomerBalanceTransactionListPageResponseTest { + + @Test + fun create() { + val customerBalanceTransactionListPageResponse = + CustomerBalanceTransactionListPageResponse.builder() + .addData( + CustomerBalanceTransactionListResponse.builder() + .id("cgZa3SXcsPTVyC4Y") + .action(CustomerBalanceTransactionListResponse.Action.APPLIED_TO_INVOICE) + .amount("11.00") + .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .creditNote( + CustomerBalanceTransactionListResponse.CreditNote.builder() + .id("id") + .build() + ) + .description("An optional description") + .endingBalance("22.00") + .invoice( + CustomerBalanceTransactionListResponse.Invoice.builder() + .id("gXcsPTVyC4YZa3Sc") + .build() + ) + .startingBalance("33.00") + .type(CustomerBalanceTransactionListResponse.Type.INCREMENT) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(customerBalanceTransactionListPageResponse.data()) + .containsExactly( + CustomerBalanceTransactionListResponse.builder() + .id("cgZa3SXcsPTVyC4Y") + .action(CustomerBalanceTransactionListResponse.Action.APPLIED_TO_INVOICE) + .amount("11.00") + .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .creditNote( + CustomerBalanceTransactionListResponse.CreditNote.builder().id("id").build() + ) + .description("An optional description") + .endingBalance("22.00") + .invoice( + CustomerBalanceTransactionListResponse.Invoice.builder() + .id("gXcsPTVyC4YZa3Sc") + .build() + ) + .startingBalance("33.00") + .type(CustomerBalanceTransactionListResponse.Type.INCREMENT) + .build() + ) + assertThat(customerBalanceTransactionListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val customerBalanceTransactionListPageResponse = + CustomerBalanceTransactionListPageResponse.builder() + .addData( + CustomerBalanceTransactionListResponse.builder() + .id("cgZa3SXcsPTVyC4Y") + .action(CustomerBalanceTransactionListResponse.Action.APPLIED_TO_INVOICE) + .amount("11.00") + .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .creditNote( + CustomerBalanceTransactionListResponse.CreditNote.builder() + .id("id") + .build() + ) + .description("An optional description") + .endingBalance("22.00") + .invoice( + CustomerBalanceTransactionListResponse.Invoice.builder() + .id("gXcsPTVyC4YZa3Sc") + .build() + ) + .startingBalance("33.00") + .type(CustomerBalanceTransactionListResponse.Type.INCREMENT) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedCustomerBalanceTransactionListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(customerBalanceTransactionListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCustomerBalanceTransactionListPageResponse) + .isEqualTo(customerBalanceTransactionListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponseTest.kt new file mode 100644 index 00000000..40ee16c7 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListByExternalIdPageResponseTest.kt @@ -0,0 +1,187 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.JsonValue +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CustomerCreditLedgerListByExternalIdPageResponseTest { + + @Test + fun create() { + val customerCreditLedgerListByExternalIdPageResponse = + CustomerCreditLedgerListByExternalIdPageResponse.builder() + .addData( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry.builder() + .id("id") + .amount(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditBlock( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .CreditBlock + .builder() + .id("id") + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .perUnitCostBasis("per_unit_cost_basis") + .build() + ) + .currency("currency") + .customer( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .Customer + .builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .description("description") + .endingBalance(0.0) + .entryStatus( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .EntryStatus + .COMMITTED + ) + .entryType( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .EntryType + .INCREMENT + ) + .ledgerSequenceNumber(0L) + .metadata( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .Metadata + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .startingBalance(0.0) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(customerCreditLedgerListByExternalIdPageResponse.data()) + .containsExactly( + CustomerCreditLedgerListByExternalIdResponse.ofIncrementLedgerEntry( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry.builder() + .id("id") + .amount(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditBlock( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .CreditBlock + .builder() + .id("id") + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .perUnitCostBasis("per_unit_cost_basis") + .build() + ) + .currency("currency") + .customer( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .Customer + .builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .description("description") + .endingBalance(0.0) + .entryStatus( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .EntryStatus + .COMMITTED + ) + .entryType( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .EntryType + .INCREMENT + ) + .ledgerSequenceNumber(0L) + .metadata( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .Metadata + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .startingBalance(0.0) + .build() + ) + ) + assertThat(customerCreditLedgerListByExternalIdPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val customerCreditLedgerListByExternalIdPageResponse = + CustomerCreditLedgerListByExternalIdPageResponse.builder() + .addData( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry.builder() + .id("id") + .amount(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditBlock( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .CreditBlock + .builder() + .id("id") + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .perUnitCostBasis("per_unit_cost_basis") + .build() + ) + .currency("currency") + .customer( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .Customer + .builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .description("description") + .endingBalance(0.0) + .entryStatus( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .EntryStatus + .COMMITTED + ) + .entryType( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .EntryType + .INCREMENT + ) + .ledgerSequenceNumber(0L) + .metadata( + CustomerCreditLedgerListByExternalIdResponse.IncrementLedgerEntry + .Metadata + .builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .startingBalance(0.0) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedCustomerCreditLedgerListByExternalIdPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(customerCreditLedgerListByExternalIdPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCustomerCreditLedgerListByExternalIdPageResponse) + .isEqualTo(customerCreditLedgerListByExternalIdPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponseTest.kt new file mode 100644 index 00000000..44788165 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerListPageResponseTest.kt @@ -0,0 +1,166 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.JsonValue +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CustomerCreditLedgerListPageResponseTest { + + @Test + fun create() { + val customerCreditLedgerListPageResponse = + CustomerCreditLedgerListPageResponse.builder() + .addData( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.builder() + .id("id") + .amount(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditBlock( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.CreditBlock + .builder() + .id("id") + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .perUnitCostBasis("per_unit_cost_basis") + .build() + ) + .currency("currency") + .customer( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .description("description") + .endingBalance(0.0) + .entryStatus( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.EntryStatus + .COMMITTED + ) + .entryType( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.EntryType + .INCREMENT + ) + .ledgerSequenceNumber(0L) + .metadata( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .startingBalance(0.0) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(customerCreditLedgerListPageResponse.data()) + .containsExactly( + CustomerCreditLedgerListResponse.ofIncrementLedgerEntry( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.builder() + .id("id") + .amount(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditBlock( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.CreditBlock + .builder() + .id("id") + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .perUnitCostBasis("per_unit_cost_basis") + .build() + ) + .currency("currency") + .customer( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .description("description") + .endingBalance(0.0) + .entryStatus( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.EntryStatus + .COMMITTED + ) + .entryType( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.EntryType + .INCREMENT + ) + .ledgerSequenceNumber(0L) + .metadata( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .startingBalance(0.0) + .build() + ) + ) + assertThat(customerCreditLedgerListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val customerCreditLedgerListPageResponse = + CustomerCreditLedgerListPageResponse.builder() + .addData( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.builder() + .id("id") + .amount(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditBlock( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.CreditBlock + .builder() + .id("id") + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .perUnitCostBasis("per_unit_cost_basis") + .build() + ) + .currency("currency") + .customer( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .description("description") + .endingBalance(0.0) + .entryStatus( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.EntryStatus + .COMMITTED + ) + .entryType( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.EntryType + .INCREMENT + ) + .ledgerSequenceNumber(0L) + .metadata( + CustomerCreditLedgerListResponse.IncrementLedgerEntry.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .startingBalance(0.0) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedCustomerCreditLedgerListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(customerCreditLedgerListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCustomerCreditLedgerListPageResponse) + .isEqualTo(customerCreditLedgerListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponseTest.kt new file mode 100644 index 00000000..d9fcc180 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListByExternalIdPageResponseTest.kt @@ -0,0 +1,79 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CustomerCreditListByExternalIdPageResponseTest { + + @Test + fun create() { + val customerCreditListByExternalIdPageResponse = + CustomerCreditListByExternalIdPageResponse.builder() + .addData( + CustomerCreditListByExternalIdResponse.builder() + .id("id") + .balance(0.0) + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .maximumInitialBalance(0.0) + .perUnitCostBasis("per_unit_cost_basis") + .status(CustomerCreditListByExternalIdResponse.Status.ACTIVE) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(customerCreditListByExternalIdPageResponse.data()) + .containsExactly( + CustomerCreditListByExternalIdResponse.builder() + .id("id") + .balance(0.0) + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .maximumInitialBalance(0.0) + .perUnitCostBasis("per_unit_cost_basis") + .status(CustomerCreditListByExternalIdResponse.Status.ACTIVE) + .build() + ) + assertThat(customerCreditListByExternalIdPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val customerCreditListByExternalIdPageResponse = + CustomerCreditListByExternalIdPageResponse.builder() + .addData( + CustomerCreditListByExternalIdResponse.builder() + .id("id") + .balance(0.0) + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .maximumInitialBalance(0.0) + .perUnitCostBasis("per_unit_cost_basis") + .status(CustomerCreditListByExternalIdResponse.Status.ACTIVE) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedCustomerCreditListByExternalIdPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(customerCreditListByExternalIdPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCustomerCreditListByExternalIdPageResponse) + .isEqualTo(customerCreditListByExternalIdPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListPageResponseTest.kt new file mode 100644 index 00000000..3d5abe3f --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditListPageResponseTest.kt @@ -0,0 +1,79 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CustomerCreditListPageResponseTest { + + @Test + fun create() { + val customerCreditListPageResponse = + CustomerCreditListPageResponse.builder() + .addData( + CustomerCreditListResponse.builder() + .id("id") + .balance(0.0) + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .maximumInitialBalance(0.0) + .perUnitCostBasis("per_unit_cost_basis") + .status(CustomerCreditListResponse.Status.ACTIVE) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(customerCreditListPageResponse.data()) + .containsExactly( + CustomerCreditListResponse.builder() + .id("id") + .balance(0.0) + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .maximumInitialBalance(0.0) + .perUnitCostBasis("per_unit_cost_basis") + .status(CustomerCreditListResponse.Status.ACTIVE) + .build() + ) + assertThat(customerCreditListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val customerCreditListPageResponse = + CustomerCreditListPageResponse.builder() + .addData( + CustomerCreditListResponse.builder() + .id("id") + .balance(0.0) + .effectiveDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .expiryDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .maximumInitialBalance(0.0) + .perUnitCostBasis("per_unit_cost_basis") + .status(CustomerCreditListResponse.Status.ACTIVE) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedCustomerCreditListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(customerCreditListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCustomerCreditListPageResponse) + .isEqualTo(customerCreditListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageResponseTest.kt new file mode 100644 index 00000000..0df6206a --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditTopUpListByExternalIdPageResponseTest.kt @@ -0,0 +1,108 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CustomerCreditTopUpListByExternalIdPageResponseTest { + + @Test + fun create() { + val customerCreditTopUpListByExternalIdPageResponse = + CustomerCreditTopUpListByExternalIdPageResponse.builder() + .addData( + CustomerCreditTopUpListByExternalIdResponse.builder() + .id("id") + .amount("amount") + .currency("currency") + .invoiceSettings( + CustomerCreditTopUpListByExternalIdResponse.InvoiceSettings.builder() + .autoCollection(true) + .netTerms(0L) + .memo("memo") + .requireSuccessfulPayment(true) + .build() + ) + .perUnitCostBasis("per_unit_cost_basis") + .threshold("threshold") + .expiresAfter(0L) + .expiresAfterUnit( + CustomerCreditTopUpListByExternalIdResponse.ExpiresAfterUnit.DAY + ) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(customerCreditTopUpListByExternalIdPageResponse.data()) + .containsExactly( + CustomerCreditTopUpListByExternalIdResponse.builder() + .id("id") + .amount("amount") + .currency("currency") + .invoiceSettings( + CustomerCreditTopUpListByExternalIdResponse.InvoiceSettings.builder() + .autoCollection(true) + .netTerms(0L) + .memo("memo") + .requireSuccessfulPayment(true) + .build() + ) + .perUnitCostBasis("per_unit_cost_basis") + .threshold("threshold") + .expiresAfter(0L) + .expiresAfterUnit( + CustomerCreditTopUpListByExternalIdResponse.ExpiresAfterUnit.DAY + ) + .build() + ) + assertThat(customerCreditTopUpListByExternalIdPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val customerCreditTopUpListByExternalIdPageResponse = + CustomerCreditTopUpListByExternalIdPageResponse.builder() + .addData( + CustomerCreditTopUpListByExternalIdResponse.builder() + .id("id") + .amount("amount") + .currency("currency") + .invoiceSettings( + CustomerCreditTopUpListByExternalIdResponse.InvoiceSettings.builder() + .autoCollection(true) + .netTerms(0L) + .memo("memo") + .requireSuccessfulPayment(true) + .build() + ) + .perUnitCostBasis("per_unit_cost_basis") + .threshold("threshold") + .expiresAfter(0L) + .expiresAfterUnit( + CustomerCreditTopUpListByExternalIdResponse.ExpiresAfterUnit.DAY + ) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedCustomerCreditTopUpListByExternalIdPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(customerCreditTopUpListByExternalIdPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCustomerCreditTopUpListByExternalIdPageResponse) + .isEqualTo(customerCreditTopUpListByExternalIdPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageResponseTest.kt new file mode 100644 index 00000000..628e5672 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditTopUpListPageResponseTest.kt @@ -0,0 +1,102 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CustomerCreditTopUpListPageResponseTest { + + @Test + fun create() { + val customerCreditTopUpListPageResponse = + CustomerCreditTopUpListPageResponse.builder() + .addData( + CustomerCreditTopUpListResponse.builder() + .id("id") + .amount("amount") + .currency("currency") + .invoiceSettings( + CustomerCreditTopUpListResponse.InvoiceSettings.builder() + .autoCollection(true) + .netTerms(0L) + .memo("memo") + .requireSuccessfulPayment(true) + .build() + ) + .perUnitCostBasis("per_unit_cost_basis") + .threshold("threshold") + .expiresAfter(0L) + .expiresAfterUnit(CustomerCreditTopUpListResponse.ExpiresAfterUnit.DAY) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(customerCreditTopUpListPageResponse.data()) + .containsExactly( + CustomerCreditTopUpListResponse.builder() + .id("id") + .amount("amount") + .currency("currency") + .invoiceSettings( + CustomerCreditTopUpListResponse.InvoiceSettings.builder() + .autoCollection(true) + .netTerms(0L) + .memo("memo") + .requireSuccessfulPayment(true) + .build() + ) + .perUnitCostBasis("per_unit_cost_basis") + .threshold("threshold") + .expiresAfter(0L) + .expiresAfterUnit(CustomerCreditTopUpListResponse.ExpiresAfterUnit.DAY) + .build() + ) + assertThat(customerCreditTopUpListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val customerCreditTopUpListPageResponse = + CustomerCreditTopUpListPageResponse.builder() + .addData( + CustomerCreditTopUpListResponse.builder() + .id("id") + .amount("amount") + .currency("currency") + .invoiceSettings( + CustomerCreditTopUpListResponse.InvoiceSettings.builder() + .autoCollection(true) + .netTerms(0L) + .memo("memo") + .requireSuccessfulPayment(true) + .build() + ) + .perUnitCostBasis("per_unit_cost_basis") + .threshold("threshold") + .expiresAfter(0L) + .expiresAfterUnit(CustomerCreditTopUpListResponse.ExpiresAfterUnit.DAY) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedCustomerCreditTopUpListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(customerCreditTopUpListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCustomerCreditTopUpListPageResponse) + .isEqualTo(customerCreditTopUpListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerListPageResponseTest.kt new file mode 100644 index 00000000..26b725f9 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerListPageResponseTest.kt @@ -0,0 +1,303 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.JsonValue +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CustomerListPageResponseTest { + + @Test + fun create() { + val customerListPageResponse = + CustomerListPageResponse.builder() + .addData( + Customer.builder() + .id("id") + .addAdditionalEmail("string") + .autoCollection(true) + .balance("balance") + .billingAddress( + Customer.BillingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .currency("currency") + .email("email") + .emailDelivery(true) + .exemptFromAutomatedTax(true) + .externalCustomerId("external_customer_id") + .hierarchy( + Customer.Hierarchy.builder() + .addChild( + Customer.Hierarchy.Child.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .parent( + Customer.Hierarchy.Parent.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .build() + ) + .metadata( + Customer.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("name") + .paymentProvider(Customer.PaymentProvider.QUICKBOOKS) + .paymentProviderId("payment_provider_id") + .portalUrl("portal_url") + .shippingAddress( + Customer.ShippingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .taxId( + Customer.TaxId.builder() + .country(Customer.TaxId.Country.AD) + .type(Customer.TaxId.Type.AD_NRT) + .value("value") + .build() + ) + .timezone("timezone") + .accountingSyncConfiguration( + Customer.AccountingSyncConfiguration.builder() + .addAccountingProvider( + Customer.AccountingSyncConfiguration.AccountingProvider + .builder() + .externalProviderId("external_provider_id") + .providerType( + Customer.AccountingSyncConfiguration.AccountingProvider + .ProviderType + .QUICKBOOKS + ) + .build() + ) + .excluded(true) + .build() + ) + .reportingConfiguration( + Customer.ReportingConfiguration.builder().exempt(true).build() + ) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(customerListPageResponse.data()) + .containsExactly( + Customer.builder() + .id("id") + .addAdditionalEmail("string") + .autoCollection(true) + .balance("balance") + .billingAddress( + Customer.BillingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .currency("currency") + .email("email") + .emailDelivery(true) + .exemptFromAutomatedTax(true) + .externalCustomerId("external_customer_id") + .hierarchy( + Customer.Hierarchy.builder() + .addChild( + Customer.Hierarchy.Child.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .parent( + Customer.Hierarchy.Parent.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .build() + ) + .metadata( + Customer.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("name") + .paymentProvider(Customer.PaymentProvider.QUICKBOOKS) + .paymentProviderId("payment_provider_id") + .portalUrl("portal_url") + .shippingAddress( + Customer.ShippingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .taxId( + Customer.TaxId.builder() + .country(Customer.TaxId.Country.AD) + .type(Customer.TaxId.Type.AD_NRT) + .value("value") + .build() + ) + .timezone("timezone") + .accountingSyncConfiguration( + Customer.AccountingSyncConfiguration.builder() + .addAccountingProvider( + Customer.AccountingSyncConfiguration.AccountingProvider.builder() + .externalProviderId("external_provider_id") + .providerType( + Customer.AccountingSyncConfiguration.AccountingProvider + .ProviderType + .QUICKBOOKS + ) + .build() + ) + .excluded(true) + .build() + ) + .reportingConfiguration( + Customer.ReportingConfiguration.builder().exempt(true).build() + ) + .build() + ) + assertThat(customerListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val customerListPageResponse = + CustomerListPageResponse.builder() + .addData( + Customer.builder() + .id("id") + .addAdditionalEmail("string") + .autoCollection(true) + .balance("balance") + .billingAddress( + Customer.BillingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .currency("currency") + .email("email") + .emailDelivery(true) + .exemptFromAutomatedTax(true) + .externalCustomerId("external_customer_id") + .hierarchy( + Customer.Hierarchy.builder() + .addChild( + Customer.Hierarchy.Child.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .parent( + Customer.Hierarchy.Parent.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .build() + ) + .metadata( + Customer.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("name") + .paymentProvider(Customer.PaymentProvider.QUICKBOOKS) + .paymentProviderId("payment_provider_id") + .portalUrl("portal_url") + .shippingAddress( + Customer.ShippingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .taxId( + Customer.TaxId.builder() + .country(Customer.TaxId.Country.AD) + .type(Customer.TaxId.Type.AD_NRT) + .value("value") + .build() + ) + .timezone("timezone") + .accountingSyncConfiguration( + Customer.AccountingSyncConfiguration.builder() + .addAccountingProvider( + Customer.AccountingSyncConfiguration.AccountingProvider + .builder() + .externalProviderId("external_provider_id") + .providerType( + Customer.AccountingSyncConfiguration.AccountingProvider + .ProviderType + .QUICKBOOKS + ) + .build() + ) + .excluded(true) + .build() + ) + .reportingConfiguration( + Customer.ReportingConfiguration.builder().exempt(true).build() + ) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedCustomerListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(customerListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCustomerListPageResponse).isEqualTo(customerListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/EventBackfillListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/EventBackfillListPageResponseTest.kt new file mode 100644 index 00000000..2ce6687f --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/EventBackfillListPageResponseTest.kt @@ -0,0 +1,95 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class EventBackfillListPageResponseTest { + + @Test + fun create() { + val eventBackfillListPageResponse = + EventBackfillListPageResponse.builder() + .addData( + EventBackfillListResponse.builder() + .id("id") + .closeTime(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .customerId("customer_id") + .eventsIngested(0L) + .replaceExistingEvents(true) + .revertedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .status(EventBackfillListResponse.Status.PENDING) + .timeframeEnd(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .timeframeStart(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deprecationFilter( + "my_numeric_property > 100 AND my_other_property = 'bar'" + ) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(eventBackfillListPageResponse.data()) + .containsExactly( + EventBackfillListResponse.builder() + .id("id") + .closeTime(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .customerId("customer_id") + .eventsIngested(0L) + .replaceExistingEvents(true) + .revertedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .status(EventBackfillListResponse.Status.PENDING) + .timeframeEnd(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .timeframeStart(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deprecationFilter("my_numeric_property > 100 AND my_other_property = 'bar'") + .build() + ) + assertThat(eventBackfillListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val eventBackfillListPageResponse = + EventBackfillListPageResponse.builder() + .addData( + EventBackfillListResponse.builder() + .id("id") + .closeTime(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .customerId("customer_id") + .eventsIngested(0L) + .replaceExistingEvents(true) + .revertedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .status(EventBackfillListResponse.Status.PENDING) + .timeframeEnd(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .timeframeStart(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .deprecationFilter( + "my_numeric_property > 100 AND my_other_property = 'bar'" + ) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedEventBackfillListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(eventBackfillListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedEventBackfillListPageResponse) + .isEqualTo(eventBackfillListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/InvoiceListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/InvoiceListPageResponseTest.kt new file mode 100644 index 00000000..a784bdda --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/InvoiceListPageResponseTest.kt @@ -0,0 +1,1034 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.JsonValue +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class InvoiceListPageResponseTest { + + @Test + fun create() { + val invoiceListPageResponse = + InvoiceListPageResponse.builder() + .addData( + Invoice.builder() + .id("id") + .amountDue("8.00") + .autoCollection( + Invoice.AutoCollection.builder() + .enabled(true) + .nextAttemptAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .numAttempts(0L) + .previouslyAttemptedAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .billingAddress( + Invoice.BillingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .addCreditNote( + Invoice.CreditNote.builder() + .id("id") + .creditNoteNumber("credit_note_number") + .memo("memo") + .reason("reason") + .total("total") + .type("type") + .voidedAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .build() + ) + .currency("USD") + .customer( + Invoice.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .addCustomerBalanceTransaction( + Invoice.CustomerBalanceTransaction.builder() + .id("cgZa3SXcsPTVyC4Y") + .action( + Invoice.CustomerBalanceTransaction.Action.APPLIED_TO_INVOICE + ) + .amount("11.00") + .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .creditNote( + Invoice.CustomerBalanceTransaction.CreditNote.builder() + .id("id") + .build() + ) + .description("An optional description") + .endingBalance("22.00") + .invoice( + Invoice.CustomerBalanceTransaction.InnerInvoice.builder() + .id("gXcsPTVyC4YZa3Sc") + .build() + ) + .startingBalance("33.00") + .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .build() + ) + .customerTaxId( + Invoice.CustomerTaxId.builder() + .country(Invoice.CustomerTaxId.Country.AD) + .type(Invoice.CustomerTaxId.Type.AD_NRT) + .value("value") + .build() + ) + .discount(JsonValue.from(mapOf())) + .addDiscount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .dueDate(OffsetDateTime.parse("2022-05-30T07:00:00+00:00")) + .eligibleToIssueAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .hostedInvoiceUrl("hosted_invoice_url") + .invoiceDate(OffsetDateTime.parse("2022-05-01T07:00:00+00:00")) + .invoiceNumber("JYEFHK-00001") + .invoicePdf( + "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) + .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addLineItem( + Invoice.LineItem.builder() + .id("id") + .adjustedSubtotal("5.00") + .addAdjustment( + Invoice.LineItem.Adjustment.MonetaryUsageDiscountAdjustment + .builder() + .id("id") + .adjustmentType( + Invoice.LineItem.Adjustment + .MonetaryUsageDiscountAdjustment + .AdjustmentType + .USAGE_DISCOUNT + ) + .amount("amount") + .addAppliesToPriceId("string") + .isInvoiceLevel(true) + .reason("reason") + .usageDiscount(0.0) + .build() + ) + .amount("7.00") + .creditsApplied("6.00") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) + .filter("filter") + .grouping("grouping") + .maximum( + Invoice.LineItem.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .minimum( + Invoice.LineItem.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("Fixed Fee") + .partiallyInvoicedAmount("4.00") + .price( + Price.UnitPrice.builder() + .id("id") + .billableMetric( + Price.UnitPrice.BillableMetric.builder() + .id("id") + .build() + ) + .billingCycleConfiguration( + Price.UnitPrice.BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.BillingCycleConfiguration + .DurationUnit + .DAY + ) + .build() + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .conversionRate(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Price.UnitPrice.CreditAllocation.builder() + .allowsRollover(true) + .currency("currency") + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType( + PercentageDiscount.DiscountType.PERCENTAGE + ) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + Price.UnitPrice.InvoicingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.InvoicingCycleConfiguration + .DurationUnit + .DAY + ) + .build() + ) + .item( + Price.UnitPrice.Item.builder() + .id("id") + .name("name") + .build() + ) + .maximum( + Price.UnitPrice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.UnitPrice.Metadata.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .minimum( + Price.UnitPrice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .modelType(Price.UnitPrice.ModelType.UNIT) + .name("name") + .planPhaseOrder(0L) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) + .unitConfig( + Price.UnitPrice.UnitConfig.builder() + .unitAmount("unit_amount") + .build() + ) + .dimensionalPriceConfiguration( + Price.UnitPrice.DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId( + "dimensional_price_group_id" + ) + .build() + ) + .build() + ) + .quantity(1.0) + .startDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) + .addSubLineItem( + Invoice.LineItem.SubLineItem.MatrixSubLineItem.builder() + .amount("9.00") + .grouping( + Invoice.LineItem.SubLineItem.MatrixSubLineItem.Grouping + .builder() + .key("region") + .value("west") + .build() + ) + .matrixConfig( + Invoice.LineItem.SubLineItem.MatrixSubLineItem + .MatrixConfig + .builder() + .addDimensionValue("string") + .build() + ) + .name("Tier One") + .quantity(5.0) + .type( + Invoice.LineItem.SubLineItem.MatrixSubLineItem.Type + .MATRIX + ) + .build() + ) + .subtotal("9.00") + .addTaxAmount( + Invoice.LineItem.TaxAmount.builder() + .amount("amount") + .taxRateDescription("tax_rate_description") + .taxRatePercentage("tax_rate_percentage") + .build() + ) + .addUsageCustomerId("string") + .build() + ) + .maximum( + Invoice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .memo("memo") + .metadata( + Invoice.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Invoice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addPaymentAttempt( + Invoice.PaymentAttempt.builder() + .id("id") + .amount("amount") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) + .paymentProviderId("payment_provider_id") + .succeeded(true) + .build() + ) + .paymentFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .paymentStartedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .scheduledIssueAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .shippingAddress( + Invoice.ShippingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .status(Invoice.Status.ISSUED) + .subscription(Invoice.Subscription.builder().id("VDGsT23osdLb84KD").build()) + .subtotal("8.00") + .syncFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .total("8.00") + .voidedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .willAutoIssue(true) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(invoiceListPageResponse.data()) + .containsExactly( + Invoice.builder() + .id("id") + .amountDue("8.00") + .autoCollection( + Invoice.AutoCollection.builder() + .enabled(true) + .nextAttemptAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .numAttempts(0L) + .previouslyAttemptedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .billingAddress( + Invoice.BillingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .addCreditNote( + Invoice.CreditNote.builder() + .id("id") + .creditNoteNumber("credit_note_number") + .memo("memo") + .reason("reason") + .total("total") + .type("type") + .voidedAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .build() + ) + .currency("USD") + .customer( + Invoice.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .addCustomerBalanceTransaction( + Invoice.CustomerBalanceTransaction.builder() + .id("cgZa3SXcsPTVyC4Y") + .action(Invoice.CustomerBalanceTransaction.Action.APPLIED_TO_INVOICE) + .amount("11.00") + .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .creditNote( + Invoice.CustomerBalanceTransaction.CreditNote.builder() + .id("id") + .build() + ) + .description("An optional description") + .endingBalance("22.00") + .invoice( + Invoice.CustomerBalanceTransaction.InnerInvoice.builder() + .id("gXcsPTVyC4YZa3Sc") + .build() + ) + .startingBalance("33.00") + .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .build() + ) + .customerTaxId( + Invoice.CustomerTaxId.builder() + .country(Invoice.CustomerTaxId.Country.AD) + .type(Invoice.CustomerTaxId.Type.AD_NRT) + .value("value") + .build() + ) + .discount(JsonValue.from(mapOf())) + .addDiscount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .dueDate(OffsetDateTime.parse("2022-05-30T07:00:00+00:00")) + .eligibleToIssueAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .hostedInvoiceUrl("hosted_invoice_url") + .invoiceDate(OffsetDateTime.parse("2022-05-01T07:00:00+00:00")) + .invoiceNumber("JYEFHK-00001") + .invoicePdf( + "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) + .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addLineItem( + Invoice.LineItem.builder() + .id("id") + .adjustedSubtotal("5.00") + .addAdjustment( + Invoice.LineItem.Adjustment.MonetaryUsageDiscountAdjustment + .builder() + .id("id") + .adjustmentType( + Invoice.LineItem.Adjustment.MonetaryUsageDiscountAdjustment + .AdjustmentType + .USAGE_DISCOUNT + ) + .amount("amount") + .addAppliesToPriceId("string") + .isInvoiceLevel(true) + .reason("reason") + .usageDiscount(0.0) + .build() + ) + .amount("7.00") + .creditsApplied("6.00") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) + .filter("filter") + .grouping("grouping") + .maximum( + Invoice.LineItem.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .minimum( + Invoice.LineItem.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("Fixed Fee") + .partiallyInvoicedAmount("4.00") + .price( + Price.UnitPrice.builder() + .id("id") + .billableMetric( + Price.UnitPrice.BillableMetric.builder().id("id").build() + ) + .billingCycleConfiguration( + Price.UnitPrice.BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.BillingCycleConfiguration + .DurationUnit + .DAY + ) + .build() + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .conversionRate(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Price.UnitPrice.CreditAllocation.builder() + .allowsRollover(true) + .currency("currency") + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType( + PercentageDiscount.DiscountType.PERCENTAGE + ) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + Price.UnitPrice.InvoicingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.InvoicingCycleConfiguration + .DurationUnit + .DAY + ) + .build() + ) + .item( + Price.UnitPrice.Item.builder().id("id").name("name").build() + ) + .maximum( + Price.UnitPrice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.UnitPrice.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Price.UnitPrice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .modelType(Price.UnitPrice.ModelType.UNIT) + .name("name") + .planPhaseOrder(0L) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) + .unitConfig( + Price.UnitPrice.UnitConfig.builder() + .unitAmount("unit_amount") + .build() + ) + .dimensionalPriceConfiguration( + Price.UnitPrice.DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId("dimensional_price_group_id") + .build() + ) + .build() + ) + .quantity(1.0) + .startDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) + .addSubLineItem( + Invoice.LineItem.SubLineItem.MatrixSubLineItem.builder() + .amount("9.00") + .grouping( + Invoice.LineItem.SubLineItem.MatrixSubLineItem.Grouping + .builder() + .key("region") + .value("west") + .build() + ) + .matrixConfig( + Invoice.LineItem.SubLineItem.MatrixSubLineItem.MatrixConfig + .builder() + .addDimensionValue("string") + .build() + ) + .name("Tier One") + .quantity(5.0) + .type( + Invoice.LineItem.SubLineItem.MatrixSubLineItem.Type.MATRIX + ) + .build() + ) + .subtotal("9.00") + .addTaxAmount( + Invoice.LineItem.TaxAmount.builder() + .amount("amount") + .taxRateDescription("tax_rate_description") + .taxRatePercentage("tax_rate_percentage") + .build() + ) + .addUsageCustomerId("string") + .build() + ) + .maximum( + Invoice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .memo("memo") + .metadata( + Invoice.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Invoice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addPaymentAttempt( + Invoice.PaymentAttempt.builder() + .id("id") + .amount("amount") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) + .paymentProviderId("payment_provider_id") + .succeeded(true) + .build() + ) + .paymentFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .paymentStartedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .scheduledIssueAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .shippingAddress( + Invoice.ShippingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .status(Invoice.Status.ISSUED) + .subscription(Invoice.Subscription.builder().id("VDGsT23osdLb84KD").build()) + .subtotal("8.00") + .syncFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .total("8.00") + .voidedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .willAutoIssue(true) + .build() + ) + assertThat(invoiceListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val invoiceListPageResponse = + InvoiceListPageResponse.builder() + .addData( + Invoice.builder() + .id("id") + .amountDue("8.00") + .autoCollection( + Invoice.AutoCollection.builder() + .enabled(true) + .nextAttemptAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .numAttempts(0L) + .previouslyAttemptedAt( + OffsetDateTime.parse("2019-12-27T18:11:19.117Z") + ) + .build() + ) + .billingAddress( + Invoice.BillingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .addCreditNote( + Invoice.CreditNote.builder() + .id("id") + .creditNoteNumber("credit_note_number") + .memo("memo") + .reason("reason") + .total("total") + .type("type") + .voidedAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .build() + ) + .currency("USD") + .customer( + Invoice.Customer.builder() + .id("id") + .externalCustomerId("external_customer_id") + .build() + ) + .addCustomerBalanceTransaction( + Invoice.CustomerBalanceTransaction.builder() + .id("cgZa3SXcsPTVyC4Y") + .action( + Invoice.CustomerBalanceTransaction.Action.APPLIED_TO_INVOICE + ) + .amount("11.00") + .createdAt(OffsetDateTime.parse("2022-05-01T07:01:31+00:00")) + .creditNote( + Invoice.CustomerBalanceTransaction.CreditNote.builder() + .id("id") + .build() + ) + .description("An optional description") + .endingBalance("22.00") + .invoice( + Invoice.CustomerBalanceTransaction.InnerInvoice.builder() + .id("gXcsPTVyC4YZa3Sc") + .build() + ) + .startingBalance("33.00") + .type(Invoice.CustomerBalanceTransaction.Type.INCREMENT) + .build() + ) + .customerTaxId( + Invoice.CustomerTaxId.builder() + .country(Invoice.CustomerTaxId.Country.AD) + .type(Invoice.CustomerTaxId.Type.AD_NRT) + .value("value") + .build() + ) + .discount(JsonValue.from(mapOf())) + .addDiscount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .dueDate(OffsetDateTime.parse("2022-05-30T07:00:00+00:00")) + .eligibleToIssueAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .hostedInvoiceUrl("hosted_invoice_url") + .invoiceDate(OffsetDateTime.parse("2022-05-01T07:00:00+00:00")) + .invoiceNumber("JYEFHK-00001") + .invoicePdf( + "https://assets.withorb.com/invoice/rUHdhmg45vY45DX/qEAeuYePaphGMdFb" + ) + .invoiceSource(Invoice.InvoiceSource.SUBSCRIPTION) + .issueFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .issuedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addLineItem( + Invoice.LineItem.builder() + .id("id") + .adjustedSubtotal("5.00") + .addAdjustment( + Invoice.LineItem.Adjustment.MonetaryUsageDiscountAdjustment + .builder() + .id("id") + .adjustmentType( + Invoice.LineItem.Adjustment + .MonetaryUsageDiscountAdjustment + .AdjustmentType + .USAGE_DISCOUNT + ) + .amount("amount") + .addAppliesToPriceId("string") + .isInvoiceLevel(true) + .reason("reason") + .usageDiscount(0.0) + .build() + ) + .amount("7.00") + .creditsApplied("6.00") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .endDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) + .filter("filter") + .grouping("grouping") + .maximum( + Invoice.LineItem.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .minimum( + Invoice.LineItem.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("Fixed Fee") + .partiallyInvoicedAmount("4.00") + .price( + Price.UnitPrice.builder() + .id("id") + .billableMetric( + Price.UnitPrice.BillableMetric.builder() + .id("id") + .build() + ) + .billingCycleConfiguration( + Price.UnitPrice.BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.BillingCycleConfiguration + .DurationUnit + .DAY + ) + .build() + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .conversionRate(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Price.UnitPrice.CreditAllocation.builder() + .allowsRollover(true) + .currency("currency") + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType( + PercentageDiscount.DiscountType.PERCENTAGE + ) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + Price.UnitPrice.InvoicingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.InvoicingCycleConfiguration + .DurationUnit + .DAY + ) + .build() + ) + .item( + Price.UnitPrice.Item.builder() + .id("id") + .name("name") + .build() + ) + .maximum( + Price.UnitPrice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.UnitPrice.Metadata.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("string"), + ) + .build() + ) + .minimum( + Price.UnitPrice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .modelType(Price.UnitPrice.ModelType.UNIT) + .name("name") + .planPhaseOrder(0L) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) + .unitConfig( + Price.UnitPrice.UnitConfig.builder() + .unitAmount("unit_amount") + .build() + ) + .dimensionalPriceConfiguration( + Price.UnitPrice.DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId( + "dimensional_price_group_id" + ) + .build() + ) + .build() + ) + .quantity(1.0) + .startDate(OffsetDateTime.parse("2022-02-01T08:00:00+00:00")) + .addSubLineItem( + Invoice.LineItem.SubLineItem.MatrixSubLineItem.builder() + .amount("9.00") + .grouping( + Invoice.LineItem.SubLineItem.MatrixSubLineItem.Grouping + .builder() + .key("region") + .value("west") + .build() + ) + .matrixConfig( + Invoice.LineItem.SubLineItem.MatrixSubLineItem + .MatrixConfig + .builder() + .addDimensionValue("string") + .build() + ) + .name("Tier One") + .quantity(5.0) + .type( + Invoice.LineItem.SubLineItem.MatrixSubLineItem.Type + .MATRIX + ) + .build() + ) + .subtotal("9.00") + .addTaxAmount( + Invoice.LineItem.TaxAmount.builder() + .amount("amount") + .taxRateDescription("tax_rate_description") + .taxRatePercentage("tax_rate_percentage") + .build() + ) + .addUsageCustomerId("string") + .build() + ) + .maximum( + Invoice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .memo("memo") + .metadata( + Invoice.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Invoice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .paidAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addPaymentAttempt( + Invoice.PaymentAttempt.builder() + .id("id") + .amount("amount") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .paymentProvider(Invoice.PaymentAttempt.PaymentProvider.STRIPE) + .paymentProviderId("payment_provider_id") + .succeeded(true) + .build() + ) + .paymentFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .paymentStartedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .scheduledIssueAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .shippingAddress( + Invoice.ShippingAddress.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .status(Invoice.Status.ISSUED) + .subscription(Invoice.Subscription.builder().id("VDGsT23osdLb84KD").build()) + .subtotal("8.00") + .syncFailedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .total("8.00") + .voidedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .willAutoIssue(true) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedInvoiceListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(invoiceListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedInvoiceListPageResponse).isEqualTo(invoiceListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/ItemListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/ItemListPageResponseTest.kt new file mode 100644 index 00000000..ca8ac661 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/ItemListPageResponseTest.kt @@ -0,0 +1,90 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ItemListPageResponseTest { + + @Test + fun create() { + val itemListPageResponse = + ItemListPageResponse.builder() + .addData( + Item.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addExternalConnection( + Item.ExternalConnection.builder() + .externalConnectionName( + Item.ExternalConnection.ExternalConnectionName.STRIPE + ) + .externalEntityId("external_entity_id") + .build() + ) + .name("name") + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(itemListPageResponse.data()) + .containsExactly( + Item.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addExternalConnection( + Item.ExternalConnection.builder() + .externalConnectionName( + Item.ExternalConnection.ExternalConnectionName.STRIPE + ) + .externalEntityId("external_entity_id") + .build() + ) + .name("name") + .build() + ) + assertThat(itemListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val itemListPageResponse = + ItemListPageResponse.builder() + .addData( + Item.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addExternalConnection( + Item.ExternalConnection.builder() + .externalConnectionName( + Item.ExternalConnection.ExternalConnectionName.STRIPE + ) + .externalEntityId("external_entity_id") + .build() + ) + .name("name") + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedItemListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(itemListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedItemListPageResponse).isEqualTo(itemListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/MetricListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/MetricListPageResponseTest.kt new file mode 100644 index 00000000..a4e88a44 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/MetricListPageResponseTest.kt @@ -0,0 +1,130 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.JsonValue +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class MetricListPageResponseTest { + + @Test + fun create() { + val metricListPageResponse = + MetricListPageResponse.builder() + .addData( + BillableMetric.builder() + .id("id") + .description("description") + .item( + Item.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addExternalConnection( + Item.ExternalConnection.builder() + .externalConnectionName( + Item.ExternalConnection.ExternalConnectionName.STRIPE + ) + .externalEntityId("external_entity_id") + .build() + ) + .name("name") + .build() + ) + .metadata( + BillableMetric.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("name") + .status(BillableMetric.Status.ACTIVE) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(metricListPageResponse.data()) + .containsExactly( + BillableMetric.builder() + .id("id") + .description("description") + .item( + Item.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addExternalConnection( + Item.ExternalConnection.builder() + .externalConnectionName( + Item.ExternalConnection.ExternalConnectionName.STRIPE + ) + .externalEntityId("external_entity_id") + .build() + ) + .name("name") + .build() + ) + .metadata( + BillableMetric.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("name") + .status(BillableMetric.Status.ACTIVE) + .build() + ) + assertThat(metricListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val metricListPageResponse = + MetricListPageResponse.builder() + .addData( + BillableMetric.builder() + .id("id") + .description("description") + .item( + Item.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .addExternalConnection( + Item.ExternalConnection.builder() + .externalConnectionName( + Item.ExternalConnection.ExternalConnectionName.STRIPE + ) + .externalEntityId("external_entity_id") + .build() + ) + .name("name") + .build() + ) + .metadata( + BillableMetric.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("name") + .status(BillableMetric.Status.ACTIVE) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedMetricListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(metricListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMetricListPageResponse).isEqualTo(metricListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/PlanListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/PlanListPageResponseTest.kt new file mode 100644 index 00000000..b10f75a9 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/PlanListPageResponseTest.kt @@ -0,0 +1,623 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.JsonValue +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PlanListPageResponseTest { + + @Test + fun create() { + val planListPageResponse = + PlanListPageResponse.builder() + .addData( + Plan.builder() + .id("id") + .addAdjustment( + Plan.Adjustment.PlanPhaseUsageDiscountAdjustment.builder() + .id("id") + .adjustmentType( + Plan.Adjustment.PlanPhaseUsageDiscountAdjustment.AdjustmentType + .USAGE_DISCOUNT + ) + .addAppliesToPriceId("string") + .isInvoiceLevel(true) + .planPhaseOrder(0L) + .reason("reason") + .usageDiscount(0.0) + .build() + ) + .basePlan( + Plan.BasePlan.builder() + .id("m2t5akQeh2obwxeU") + .externalPlanId("m2t5akQeh2obwxeU") + .name("Example plan") + .build() + ) + .basePlanId("base_plan_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .currency("currency") + .defaultInvoiceMemo("default_invoice_memo") + .description("description") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPlanId("external_plan_id") + .invoicingCurrency("invoicing_currency") + .maximum( + Plan.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Plan.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Plan.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("name") + .netTerms(0L) + .addPlanPhase( + Plan.PlanPhase.builder() + .id("id") + .description("description") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .duration(0L) + .durationUnit(Plan.PlanPhase.DurationUnit.DAILY) + .maximum( + Plan.PlanPhase.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .minimum( + Plan.PlanPhase.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("name") + .order(0L) + .build() + ) + .addPrice( + Price.UnitPrice.builder() + .id("id") + .billableMetric( + Price.UnitPrice.BillableMetric.builder().id("id").build() + ) + .billingCycleConfiguration( + Price.UnitPrice.BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.BillingCycleConfiguration.DurationUnit + .DAY + ) + .build() + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .conversionRate(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Price.UnitPrice.CreditAllocation.builder() + .allowsRollover(true) + .currency("currency") + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + Price.UnitPrice.InvoicingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.InvoicingCycleConfiguration.DurationUnit + .DAY + ) + .build() + ) + .item(Price.UnitPrice.Item.builder().id("id").name("name").build()) + .maximum( + Price.UnitPrice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.UnitPrice.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Price.UnitPrice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .modelType(Price.UnitPrice.ModelType.UNIT) + .name("name") + .planPhaseOrder(0L) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) + .unitConfig( + Price.UnitPrice.UnitConfig.builder() + .unitAmount("unit_amount") + .build() + ) + .dimensionalPriceConfiguration( + Price.UnitPrice.DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId("dimensional_price_group_id") + .build() + ) + .build() + ) + .product( + Plan.Product.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .name("name") + .build() + ) + .status(Plan.Status.ACTIVE) + .trialConfig( + Plan.TrialConfig.builder() + .trialPeriod(0L) + .trialPeriodUnit(Plan.TrialConfig.TrialPeriodUnit.DAYS) + .build() + ) + .version(0L) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(planListPageResponse.data()) + .containsExactly( + Plan.builder() + .id("id") + .addAdjustment( + Plan.Adjustment.PlanPhaseUsageDiscountAdjustment.builder() + .id("id") + .adjustmentType( + Plan.Adjustment.PlanPhaseUsageDiscountAdjustment.AdjustmentType + .USAGE_DISCOUNT + ) + .addAppliesToPriceId("string") + .isInvoiceLevel(true) + .planPhaseOrder(0L) + .reason("reason") + .usageDiscount(0.0) + .build() + ) + .basePlan( + Plan.BasePlan.builder() + .id("m2t5akQeh2obwxeU") + .externalPlanId("m2t5akQeh2obwxeU") + .name("Example plan") + .build() + ) + .basePlanId("base_plan_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .currency("currency") + .defaultInvoiceMemo("default_invoice_memo") + .description("description") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPlanId("external_plan_id") + .invoicingCurrency("invoicing_currency") + .maximum( + Plan.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Plan.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Plan.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("name") + .netTerms(0L) + .addPlanPhase( + Plan.PlanPhase.builder() + .id("id") + .description("description") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .duration(0L) + .durationUnit(Plan.PlanPhase.DurationUnit.DAILY) + .maximum( + Plan.PlanPhase.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .minimum( + Plan.PlanPhase.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("name") + .order(0L) + .build() + ) + .addPrice( + Price.UnitPrice.builder() + .id("id") + .billableMetric( + Price.UnitPrice.BillableMetric.builder().id("id").build() + ) + .billingCycleConfiguration( + Price.UnitPrice.BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.BillingCycleConfiguration.DurationUnit.DAY + ) + .build() + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .conversionRate(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Price.UnitPrice.CreditAllocation.builder() + .allowsRollover(true) + .currency("currency") + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + Price.UnitPrice.InvoicingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.InvoicingCycleConfiguration.DurationUnit.DAY + ) + .build() + ) + .item(Price.UnitPrice.Item.builder().id("id").name("name").build()) + .maximum( + Price.UnitPrice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.UnitPrice.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Price.UnitPrice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .modelType(Price.UnitPrice.ModelType.UNIT) + .name("name") + .planPhaseOrder(0L) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) + .unitConfig( + Price.UnitPrice.UnitConfig.builder() + .unitAmount("unit_amount") + .build() + ) + .dimensionalPriceConfiguration( + Price.UnitPrice.DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId("dimensional_price_group_id") + .build() + ) + .build() + ) + .product( + Plan.Product.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .name("name") + .build() + ) + .status(Plan.Status.ACTIVE) + .trialConfig( + Plan.TrialConfig.builder() + .trialPeriod(0L) + .trialPeriodUnit(Plan.TrialConfig.TrialPeriodUnit.DAYS) + .build() + ) + .version(0L) + .build() + ) + assertThat(planListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val planListPageResponse = + PlanListPageResponse.builder() + .addData( + Plan.builder() + .id("id") + .addAdjustment( + Plan.Adjustment.PlanPhaseUsageDiscountAdjustment.builder() + .id("id") + .adjustmentType( + Plan.Adjustment.PlanPhaseUsageDiscountAdjustment.AdjustmentType + .USAGE_DISCOUNT + ) + .addAppliesToPriceId("string") + .isInvoiceLevel(true) + .planPhaseOrder(0L) + .reason("reason") + .usageDiscount(0.0) + .build() + ) + .basePlan( + Plan.BasePlan.builder() + .id("m2t5akQeh2obwxeU") + .externalPlanId("m2t5akQeh2obwxeU") + .name("Example plan") + .build() + ) + .basePlanId("base_plan_id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .currency("currency") + .defaultInvoiceMemo("default_invoice_memo") + .description("description") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPlanId("external_plan_id") + .invoicingCurrency("invoicing_currency") + .maximum( + Plan.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Plan.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Plan.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("name") + .netTerms(0L) + .addPlanPhase( + Plan.PlanPhase.builder() + .id("id") + .description("description") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .duration(0L) + .durationUnit(Plan.PlanPhase.DurationUnit.DAILY) + .maximum( + Plan.PlanPhase.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .minimum( + Plan.PlanPhase.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .name("name") + .order(0L) + .build() + ) + .addPrice( + Price.UnitPrice.builder() + .id("id") + .billableMetric( + Price.UnitPrice.BillableMetric.builder().id("id").build() + ) + .billingCycleConfiguration( + Price.UnitPrice.BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.BillingCycleConfiguration.DurationUnit + .DAY + ) + .build() + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .conversionRate(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Price.UnitPrice.CreditAllocation.builder() + .allowsRollover(true) + .currency("currency") + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + Price.UnitPrice.InvoicingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.InvoicingCycleConfiguration.DurationUnit + .DAY + ) + .build() + ) + .item(Price.UnitPrice.Item.builder().id("id").name("name").build()) + .maximum( + Price.UnitPrice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.UnitPrice.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Price.UnitPrice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .modelType(Price.UnitPrice.ModelType.UNIT) + .name("name") + .planPhaseOrder(0L) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) + .unitConfig( + Price.UnitPrice.UnitConfig.builder() + .unitAmount("unit_amount") + .build() + ) + .dimensionalPriceConfiguration( + Price.UnitPrice.DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId("dimensional_price_group_id") + .build() + ) + .build() + ) + .product( + Plan.Product.builder() + .id("id") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .name("name") + .build() + ) + .status(Plan.Status.ACTIVE) + .trialConfig( + Plan.TrialConfig.builder() + .trialPeriod(0L) + .trialPeriodUnit(Plan.TrialConfig.TrialPeriodUnit.DAYS) + .build() + ) + .version(0L) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedPlanListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(planListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPlanListPageResponse).isEqualTo(planListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/PriceListPageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/PriceListPageResponseTest.kt new file mode 100644 index 00000000..ce5171b1 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/PriceListPageResponseTest.kt @@ -0,0 +1,276 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.JsonValue +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PriceListPageResponseTest { + + @Test + fun create() { + val priceListPageResponse = + PriceListPageResponse.builder() + .addData( + Price.UnitPrice.builder() + .id("id") + .billableMetric(Price.UnitPrice.BillableMetric.builder().id("id").build()) + .billingCycleConfiguration( + Price.UnitPrice.BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.BillingCycleConfiguration.DurationUnit.DAY + ) + .build() + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .conversionRate(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Price.UnitPrice.CreditAllocation.builder() + .allowsRollover(true) + .currency("currency") + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + Price.UnitPrice.InvoicingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.InvoicingCycleConfiguration.DurationUnit.DAY + ) + .build() + ) + .item(Price.UnitPrice.Item.builder().id("id").name("name").build()) + .maximum( + Price.UnitPrice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.UnitPrice.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Price.UnitPrice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .modelType(Price.UnitPrice.ModelType.UNIT) + .name("name") + .planPhaseOrder(0L) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) + .unitConfig( + Price.UnitPrice.UnitConfig.builder().unitAmount("unit_amount").build() + ) + .dimensionalPriceConfiguration( + Price.UnitPrice.DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId("dimensional_price_group_id") + .build() + ) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(priceListPageResponse.data()) + .containsExactly( + Price.ofUnit( + Price.UnitPrice.builder() + .id("id") + .billableMetric(Price.UnitPrice.BillableMetric.builder().id("id").build()) + .billingCycleConfiguration( + Price.UnitPrice.BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.BillingCycleConfiguration.DurationUnit.DAY + ) + .build() + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .conversionRate(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Price.UnitPrice.CreditAllocation.builder() + .allowsRollover(true) + .currency("currency") + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + Price.UnitPrice.InvoicingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.InvoicingCycleConfiguration.DurationUnit.DAY + ) + .build() + ) + .item(Price.UnitPrice.Item.builder().id("id").name("name").build()) + .maximum( + Price.UnitPrice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.UnitPrice.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Price.UnitPrice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .modelType(Price.UnitPrice.ModelType.UNIT) + .name("name") + .planPhaseOrder(0L) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) + .unitConfig( + Price.UnitPrice.UnitConfig.builder().unitAmount("unit_amount").build() + ) + .dimensionalPriceConfiguration( + Price.UnitPrice.DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId("dimensional_price_group_id") + .build() + ) + .build() + ) + ) + assertThat(priceListPageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val priceListPageResponse = + PriceListPageResponse.builder() + .addData( + Price.UnitPrice.builder() + .id("id") + .billableMetric(Price.UnitPrice.BillableMetric.builder().id("id").build()) + .billingCycleConfiguration( + Price.UnitPrice.BillingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.BillingCycleConfiguration.DurationUnit.DAY + ) + .build() + ) + .cadence(Price.UnitPrice.Cadence.ONE_TIME) + .conversionRate(0.0) + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .creditAllocation( + Price.UnitPrice.CreditAllocation.builder() + .allowsRollover(true) + .currency("currency") + .build() + ) + .currency("currency") + .discount( + PercentageDiscount.builder() + .addAppliesToPriceId("h74gfhdjvn7ujokd") + .addAppliesToPriceId("7hfgtgjnbvc3ujkl") + .discountType(PercentageDiscount.DiscountType.PERCENTAGE) + .percentageDiscount(0.15) + .reason("reason") + .build() + ) + .externalPriceId("external_price_id") + .fixedPriceQuantity(0.0) + .invoicingCycleConfiguration( + Price.UnitPrice.InvoicingCycleConfiguration.builder() + .duration(0L) + .durationUnit( + Price.UnitPrice.InvoicingCycleConfiguration.DurationUnit.DAY + ) + .build() + ) + .item(Price.UnitPrice.Item.builder().id("id").name("name").build()) + .maximum( + Price.UnitPrice.Maximum.builder() + .addAppliesToPriceId("string") + .maximumAmount("maximum_amount") + .build() + ) + .maximumAmount("maximum_amount") + .metadata( + Price.UnitPrice.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .minimum( + Price.UnitPrice.Minimum.builder() + .addAppliesToPriceId("string") + .minimumAmount("minimum_amount") + .build() + ) + .minimumAmount("minimum_amount") + .modelType(Price.UnitPrice.ModelType.UNIT) + .name("name") + .planPhaseOrder(0L) + .priceType(Price.UnitPrice.PriceType.USAGE_PRICE) + .unitConfig( + Price.UnitPrice.UnitConfig.builder().unitAmount("unit_amount").build() + ) + .dimensionalPriceConfiguration( + Price.UnitPrice.DimensionalPriceConfiguration.builder() + .addDimensionValue("string") + .dimensionalPriceGroupId("dimensional_price_group_id") + .build() + ) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedPriceListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(priceListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPriceListPageResponse).isEqualTo(priceListPageResponse) + } +} diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageResponseTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageResponseTest.kt new file mode 100644 index 00000000..909e4999 --- /dev/null +++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/SubscriptionFetchSchedulePageResponseTest.kt @@ -0,0 +1,88 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.withorb.api.models + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.withorb.api.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class SubscriptionFetchSchedulePageResponseTest { + + @Test + fun create() { + val subscriptionFetchSchedulePageResponse = + SubscriptionFetchSchedulePageResponse.builder() + .addData( + SubscriptionFetchScheduleResponse.builder() + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .plan( + SubscriptionFetchScheduleResponse.Plan.builder() + .id("m2t5akQeh2obwxeU") + .externalPlanId("m2t5akQeh2obwxeU") + .name("Example plan") + .build() + ) + .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + assertThat(subscriptionFetchSchedulePageResponse.data()) + .containsExactly( + SubscriptionFetchScheduleResponse.builder() + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .plan( + SubscriptionFetchScheduleResponse.Plan.builder() + .id("m2t5akQeh2obwxeU") + .externalPlanId("m2t5akQeh2obwxeU") + .name("Example plan") + .build() + ) + .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + assertThat(subscriptionFetchSchedulePageResponse.paginationMetadata()) + .isEqualTo(PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val subscriptionFetchSchedulePageResponse = + SubscriptionFetchSchedulePageResponse.builder() + .addData( + SubscriptionFetchScheduleResponse.builder() + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .endDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .plan( + SubscriptionFetchScheduleResponse.Plan.builder() + .id("m2t5akQeh2obwxeU") + .externalPlanId("m2t5akQeh2obwxeU") + .name("Example plan") + .build() + ) + .startDate(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .paginationMetadata( + PaginationMetadata.builder().hasMore(true).nextCursor("next_cursor").build() + ) + .build() + + val roundtrippedSubscriptionFetchSchedulePageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(subscriptionFetchSchedulePageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSubscriptionFetchSchedulePageResponse) + .isEqualTo(subscriptionFetchSchedulePageResponse) + } +}