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..96845248 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,17 +2,7 @@ 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.services.blocking.AlertService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -34,14 +24,26 @@ class AlertListPage private constructor( private val alertsService: AlertService, private val params: AlertListParams, - private val response: Response, + private val response: AlertListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): AlertListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [AlertListPageResponse], but gracefully handles missing data. + * + * @see [AlertListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [AlertListPageResponse], but gracefully handles missing data. + * + * @see [AlertListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -56,13 +58,9 @@ private constructor( override fun toString() = "AlertListPage{alertsService=$alertsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -70,9 +68,13 @@ 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() ) } @@ -86,122 +88,11 @@ private constructor( 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") - - @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 - } - - 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 [AlertListPage]. */ - @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()) - } + fun of( + alertsService: AlertService, + params: AlertListParams, + response: AlertListPageResponse, + ) = AlertListPage(alertsService, params, response) } class AutoPager(private val firstPage: AlertListPage) : Iterable { 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..8d822c7e 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,7 @@ 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.services.async.AlertServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -35,14 +25,26 @@ class AlertListPageAsync private constructor( private val alertsService: AlertServiceAsync, private val params: AlertListParams, - private val response: Response, + private val response: AlertListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): AlertListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [AlertListPageResponse], but gracefully handles missing data. + * + * @see [AlertListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [AlertListPageResponse], but gracefully handles missing data. + * + * @see [AlertListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -57,13 +59,9 @@ private constructor( override fun toString() = "AlertListPageAsync{alertsService=$alertsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -71,9 +69,13 @@ 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() ) } @@ -89,122 +91,11 @@ private constructor( 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 - - 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 */ - } - - 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 [AlertListPageAsync]. */ - @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()) - } + fun of( + alertsService: AlertServiceAsync, + params: AlertListParams, + response: AlertListPageResponse, + ) = AlertListPageAsync(alertsService, params, response) } class AutoPager(private val firstPage: AlertListPageAsync) { 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..031a1916 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,17 +2,7 @@ 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.services.blocking.CouponService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -30,14 +20,26 @@ class CouponListPage private constructor( private val couponsService: CouponService, private val params: CouponListParams, - private val response: Response, + private val response: CouponListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): CouponListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [CouponListPageResponse], but gracefully handles missing data. + * + * @see [CouponListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [CouponListPageResponse], but gracefully handles missing data. + * + * @see [CouponListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -52,13 +54,9 @@ private constructor( override fun toString() = "CouponListPage{couponsService=$couponsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -66,9 +64,13 @@ 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() ) } @@ -82,122 +84,11 @@ private constructor( 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") - - @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 - } - - 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 [CouponListPage]. */ - @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()) - } + fun of( + couponsService: CouponService, + params: CouponListParams, + response: CouponListPageResponse, + ) = CouponListPage(couponsService, params, response) } class AutoPager(private val firstPage: CouponListPage) : Iterable { 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..bb16ee29 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,7 @@ 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.services.async.CouponServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -31,14 +21,26 @@ class CouponListPageAsync private constructor( private val couponsService: CouponServiceAsync, private val params: CouponListParams, - private val response: Response, + private val response: CouponListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): CouponListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [CouponListPageResponse], but gracefully handles missing data. + * + * @see [CouponListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [CouponListPageResponse], but gracefully handles missing data. + * + * @see [CouponListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -53,13 +55,9 @@ private constructor( override fun toString() = "CouponListPageAsync{couponsService=$couponsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -67,9 +65,13 @@ 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() ) } @@ -85,122 +87,11 @@ private constructor( 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 - - 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 */ - } - - 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 [CouponListPageAsync]. */ - @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()) - } + fun of( + couponsService: CouponServiceAsync, + params: CouponListParams, + response: CouponListPageResponse, + ) = CouponListPageAsync(couponsService, params, response) } class AutoPager(private val firstPage: CouponListPageAsync) { 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..e32c6d86 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,17 +2,7 @@ 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.services.blocking.coupons.SubscriptionService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -29,14 +19,26 @@ class CouponSubscriptionListPage private constructor( private val subscriptionsService: SubscriptionService, private val params: CouponSubscriptionListParams, - private val response: Response, + private val response: Subscriptions, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): Subscriptions = response - fun data(): List = response().data() + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -51,13 +53,9 @@ private constructor( override fun toString() = "CouponSubscriptionListPage{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -65,9 +63,13 @@ 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() ) } @@ -84,127 +86,10 @@ private constructor( fun of( subscriptionsService: SubscriptionService, params: CouponSubscriptionListParams, - response: Response, + response: Subscriptions, ) = 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() - - 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 - } - - 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 - * [CouponSubscriptionListPage]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CouponSubscriptionListPage) : Iterable { override fun iterator(): Iterator = iterator { 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..460589f6 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,7 @@ 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.services.async.coupons.SubscriptionServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -30,14 +20,26 @@ class CouponSubscriptionListPageAsync private constructor( private val subscriptionsService: SubscriptionServiceAsync, private val params: CouponSubscriptionListParams, - private val response: Response, + private val response: Subscriptions, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): Subscriptions = response - fun data(): List = response().data() + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -52,13 +54,9 @@ private constructor( override fun toString() = "CouponSubscriptionListPageAsync{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -66,9 +64,13 @@ 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() ) } @@ -87,127 +89,10 @@ private constructor( fun of( subscriptionsService: SubscriptionServiceAsync, params: CouponSubscriptionListParams, - response: Response, + response: Subscriptions, ) = 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 - } - - 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 - * [CouponSubscriptionListPageAsync]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CouponSubscriptionListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { 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..4e94cace 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,17 +2,7 @@ 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.services.blocking.CreditNoteService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -28,14 +18,26 @@ class CreditNoteListPage private constructor( private val creditNotesService: CreditNoteService, private val params: CreditNoteListParams, - private val response: Response, + private val response: CreditNoteListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): CreditNoteListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data. + * + * @see [CreditNoteListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data. + * + * @see [CreditNoteListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -50,13 +52,9 @@ private constructor( override fun toString() = "CreditNoteListPage{creditNotesService=$creditNotesService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -64,9 +62,13 @@ 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() ) } @@ -83,124 +85,10 @@ private constructor( fun of( creditNotesService: CreditNoteService, params: CreditNoteListParams, - response: Response, + response: CreditNoteListPageResponse, ) = 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() - - 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 - } - - 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 [CreditNoteListPage]. */ - @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()) - } - } - class AutoPager(private val firstPage: CreditNoteListPage) : Iterable { override fun iterator(): Iterator = iterator { 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..7e1104d7 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,7 @@ 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.services.async.CreditNoteServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -29,14 +19,26 @@ class CreditNoteListPageAsync private constructor( private val creditNotesService: CreditNoteServiceAsync, private val params: CreditNoteListParams, - private val response: Response, + private val response: CreditNoteListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): CreditNoteListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data. + * + * @see [CreditNoteListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data. + * + * @see [CreditNoteListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -51,13 +53,9 @@ private constructor( override fun toString() = "CreditNoteListPageAsync{creditNotesService=$creditNotesService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -65,9 +63,13 @@ 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() ) } @@ -86,126 +88,10 @@ private constructor( fun of( creditNotesService: CreditNoteServiceAsync, params: CreditNoteListParams, - response: Response, + response: CreditNoteListPageResponse, ) = 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 - - 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 */ - } - - 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 [CreditNoteListPageAsync]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CreditNoteListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { 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..3188929b 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,17 +2,7 @@ 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.services.blocking.customers.BalanceTransactionService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -49,14 +39,29 @@ class CustomerBalanceTransactionListPage private constructor( private val balanceTransactionsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerBalanceTransactionListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -71,13 +76,9 @@ private constructor( override fun toString() = "CustomerBalanceTransactionListPage{balanceTransactionsService=$balanceTransactionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -85,9 +86,13 @@ 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() ) } @@ -104,133 +109,10 @@ private constructor( fun of( balanceTransactionsService: BalanceTransactionService, params: CustomerBalanceTransactionListParams, - response: Response, + response: CustomerBalanceTransactionListPageResponse, ) = CustomerBalanceTransactionListPage(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) - - @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 */ - } - - 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 - * [CustomerBalanceTransactionListPage]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CustomerBalanceTransactionListPage) : Iterable { 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..83adacec 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,7 @@ 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.services.async.customers.BalanceTransactionServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -50,14 +40,29 @@ class CustomerBalanceTransactionListPageAsync private constructor( private val balanceTransactionsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerBalanceTransactionListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -72,13 +77,9 @@ private constructor( override fun toString() = "CustomerBalanceTransactionListPageAsync{balanceTransactionsService=$balanceTransactionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -86,9 +87,13 @@ 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() ) } @@ -107,133 +112,10 @@ private constructor( fun of( balanceTransactionsService: BalanceTransactionServiceAsync, params: CustomerBalanceTransactionListParams, - response: Response, + response: CustomerBalanceTransactionListPageResponse, ) = 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) - - @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 */ - } - - 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 - * [CustomerBalanceTransactionListPageAsync]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CustomerBalanceTransactionListPageAsync) { fun forEach( 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..505a0c67 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,17 +2,7 @@ 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.services.blocking.customers.credits.LedgerService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -100,14 +90,29 @@ class CustomerCreditLedgerListByExternalIdPage private constructor( private val ledgerService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditLedgerListByExternalIdPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -122,13 +127,9 @@ private constructor( override fun toString() = "CustomerCreditLedgerListByExternalIdPage{ledgerService=$ledgerService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -136,9 +137,13 @@ 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() ) } @@ -155,134 +160,10 @@ private constructor( fun of( ledgerService: LedgerService, params: CustomerCreditLedgerListByExternalIdParams, - response: Response, + response: CustomerCreditLedgerListByExternalIdPageResponse, ) = CustomerCreditLedgerListByExternalIdPage(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) - - 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 */ - } - - 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() - } - - 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()) - } - } - class AutoPager(private val firstPage: CustomerCreditLedgerListByExternalIdPage) : Iterable { 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..99b78443 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,7 @@ 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.services.async.customers.credits.LedgerServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -101,14 +91,29 @@ class CustomerCreditLedgerListByExternalIdPageAsync private constructor( private val ledgerService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditLedgerListByExternalIdPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -123,13 +128,9 @@ private constructor( override fun toString() = "CustomerCreditLedgerListByExternalIdPageAsync{ledgerService=$ledgerService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -137,9 +138,13 @@ 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() ) } @@ -158,134 +163,10 @@ private constructor( fun of( ledgerService: LedgerServiceAsync, params: CustomerCreditLedgerListByExternalIdParams, - response: Response, + response: CustomerCreditLedgerListByExternalIdPageResponse, ) = CustomerCreditLedgerListByExternalIdPageAsync(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) - - 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 */ - } - - 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() - } - - 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()) - } - } - class AutoPager(private val firstPage: CustomerCreditLedgerListByExternalIdPageAsync) { fun forEach( 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..8e77f055 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,17 +2,7 @@ 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.services.blocking.customers.credits.LedgerService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -100,14 +90,27 @@ class CustomerCreditLedgerListPage private constructor( private val ledgerService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditLedgerListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -122,13 +125,9 @@ private constructor( override fun toString() = "CustomerCreditLedgerListPage{ledgerService=$ledgerService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -136,9 +135,13 @@ 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() ) } @@ -155,132 +158,10 @@ private constructor( fun of( ledgerService: LedgerService, params: CustomerCreditLedgerListParams, - response: Response, + response: CustomerCreditLedgerListPageResponse, ) = 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) - - 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 */ - } - - 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 - * [CustomerCreditLedgerListPage]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CustomerCreditLedgerListPage) : Iterable { 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..e3d10524 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,7 @@ 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.services.async.customers.credits.LedgerServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -101,14 +91,27 @@ class CustomerCreditLedgerListPageAsync private constructor( private val ledgerService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditLedgerListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -123,13 +126,9 @@ private constructor( override fun toString() = "CustomerCreditLedgerListPageAsync{ledgerService=$ledgerService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -137,9 +136,13 @@ 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() ) } @@ -158,132 +161,10 @@ private constructor( fun of( ledgerService: LedgerServiceAsync, params: CustomerCreditLedgerListParams, - response: Response, + response: CustomerCreditLedgerListPageResponse, ) = 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() - - 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 - } - - 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 - * [CustomerCreditLedgerListPageAsync]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CustomerCreditLedgerListPageAsync) { fun forEach( 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..99b3ed70 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,17 +2,7 @@ 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.services.blocking.customers.CreditService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -32,14 +22,29 @@ class CustomerCreditListByExternalIdPage private constructor( private val creditsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditListByExternalIdPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -54,13 +59,9 @@ private constructor( override fun toString() = "CustomerCreditListByExternalIdPage{creditsService=$creditsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -68,9 +69,13 @@ 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() ) } @@ -87,133 +92,10 @@ private constructor( fun of( creditsService: CreditService, params: CustomerCreditListByExternalIdParams, - response: Response, + response: CustomerCreditListByExternalIdPageResponse, ) = CustomerCreditListByExternalIdPage(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 - } - - 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 */ - } - - 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 - * [CustomerCreditListByExternalIdPage]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CustomerCreditListByExternalIdPage) : Iterable { 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..c039f2a6 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,7 @@ 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.services.async.customers.CreditServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -33,14 +23,29 @@ class CustomerCreditListByExternalIdPageAsync private constructor( private val creditsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditListByExternalIdPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -55,13 +60,9 @@ private constructor( override fun toString() = "CustomerCreditListByExternalIdPageAsync{creditsService=$creditsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -69,9 +70,13 @@ 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() ) } @@ -90,133 +95,10 @@ private constructor( fun of( creditsService: CreditServiceAsync, params: CustomerCreditListByExternalIdParams, - response: Response, + response: CustomerCreditListByExternalIdPageResponse, ) = 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) - - 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 */ - } - - 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 - * [CustomerCreditListByExternalIdPageAsync]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CustomerCreditListByExternalIdPageAsync) { fun forEach( 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..0ded908e 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,17 +2,7 @@ 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.services.blocking.customers.CreditService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -32,14 +22,27 @@ class CustomerCreditListPage private constructor( private val creditsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -54,13 +57,9 @@ private constructor( override fun toString() = "CustomerCreditListPage{creditsService=$creditsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -68,9 +67,13 @@ 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() ) } @@ -87,129 +90,10 @@ private constructor( fun of( creditsService: CreditService, params: CustomerCreditListParams, - response: Response, + response: CustomerCreditListPageResponse, ) = 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) - - 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 */ - } - - 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 [CustomerCreditListPage]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CustomerCreditListPage) : Iterable { 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..4115333d 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,7 @@ 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.services.async.customers.CreditServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -33,14 +23,27 @@ class CustomerCreditListPageAsync private constructor( private val creditsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -55,13 +58,9 @@ private constructor( override fun toString() = "CustomerCreditListPageAsync{creditsService=$creditsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -69,9 +68,13 @@ 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() ) } @@ -90,130 +93,10 @@ private constructor( fun of( creditsService: CreditServiceAsync, params: CustomerCreditListParams, - response: Response, + response: CustomerCreditListPageResponse, ) = 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 - } - - 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 */ - } - - 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 - * [CustomerCreditListPageAsync]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CustomerCreditListPageAsync) { fun forEach( 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..60fb7149 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,17 +2,7 @@ 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.services.blocking.customers.credits.TopUpService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -24,14 +14,29 @@ class CustomerCreditTopUpListByExternalIdPage private constructor( private val topUpsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditTopUpListByExternalIdPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -46,13 +51,9 @@ private constructor( override fun toString() = "CustomerCreditTopUpListByExternalIdPage{topUpsService=$topUpsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -60,9 +61,13 @@ 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() ) } @@ -79,134 +84,10 @@ private constructor( fun of( topUpsService: TopUpService, params: CustomerCreditTopUpListByExternalIdParams, - response: Response, + response: CustomerCreditTopUpListByExternalIdPageResponse, ) = 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) - - 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 */ - } - - 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 - * [CustomerCreditTopUpListByExternalIdPage]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CustomerCreditTopUpListByExternalIdPage) : Iterable { 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..dadcc696 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,7 @@ 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.services.async.customers.credits.TopUpServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -25,14 +15,29 @@ class CustomerCreditTopUpListByExternalIdPageAsync private constructor( private val topUpsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditTopUpListByExternalIdPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,13 +52,9 @@ private constructor( override fun toString() = "CustomerCreditTopUpListByExternalIdPageAsync{topUpsService=$topUpsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -61,9 +62,13 @@ 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() ) } @@ -82,134 +87,10 @@ private constructor( fun of( topUpsService: TopUpServiceAsync, params: CustomerCreditTopUpListByExternalIdParams, - response: Response, + response: CustomerCreditTopUpListByExternalIdPageResponse, ) = CustomerCreditTopUpListByExternalIdPageAsync(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) - - 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 */ - } - - 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() - } - - 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()) - } - } - class AutoPager(private val firstPage: CustomerCreditTopUpListByExternalIdPageAsync) { fun forEach( 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..a75a867c 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,17 +2,7 @@ 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.services.blocking.customers.credits.TopUpService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -24,14 +14,27 @@ class CustomerCreditTopUpListPage private constructor( private val topUpsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditTopUpListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -46,13 +49,9 @@ private constructor( override fun toString() = "CustomerCreditTopUpListPage{topUpsService=$topUpsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -60,9 +59,13 @@ 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() ) } @@ -79,132 +82,10 @@ private constructor( fun of( topUpsService: TopUpService, params: CustomerCreditTopUpListParams, - response: Response, + response: CustomerCreditTopUpListPageResponse, ) = CustomerCreditTopUpListPage(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) - - 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 */ - } - - 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 - * [CustomerCreditTopUpListPage]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CustomerCreditTopUpListPage) : Iterable { 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..3602bce0 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,7 @@ 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.services.async.customers.credits.TopUpServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -25,14 +15,27 @@ class CustomerCreditTopUpListPageAsync private constructor( private val topUpsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): CustomerCreditTopUpListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,13 +50,9 @@ private constructor( override fun toString() = "CustomerCreditTopUpListPageAsync{topUpsService=$topUpsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -61,9 +60,13 @@ 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() ) } @@ -82,132 +85,10 @@ private constructor( fun of( topUpsService: TopUpServiceAsync, params: CustomerCreditTopUpListParams, - response: Response, + response: CustomerCreditTopUpListPageResponse, ) = CustomerCreditTopUpListPageAsync(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) - - 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 */ - } - - 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()) - } - } - class AutoPager(private val firstPage: CustomerCreditTopUpListPageAsync) { fun forEach( 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..ba2dacdd 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,17 +2,7 @@ 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.services.blocking.CustomerService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -30,14 +20,26 @@ class CustomerListPage private constructor( private val customersService: CustomerService, private val params: CustomerListParams, - private val response: Response, + private val response: CustomerListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): CustomerListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [CustomerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [CustomerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -52,13 +54,9 @@ private constructor( override fun toString() = "CustomerListPage{customersService=$customersService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -66,9 +64,13 @@ 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() ) } @@ -82,122 +84,11 @@ private constructor( 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() - - 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 - } - - 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 [CustomerListPage]. */ - @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()) - } + fun of( + customersService: CustomerService, + params: CustomerListParams, + response: CustomerListPageResponse, + ) = CustomerListPage(customersService, params, response) } class AutoPager(private val firstPage: CustomerListPage) : Iterable { 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..70618337 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,7 @@ 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.services.async.CustomerServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -31,14 +21,26 @@ class CustomerListPageAsync private constructor( private val customersService: CustomerServiceAsync, private val params: CustomerListParams, - private val response: Response, + private val response: CustomerListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): CustomerListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [CustomerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [CustomerListPageResponse], but gracefully handles missing data. + * + * @see [CustomerListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -53,13 +55,9 @@ private constructor( override fun toString() = "CustomerListPageAsync{customersService=$customersService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -67,9 +65,13 @@ 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() ) } @@ -88,126 +90,10 @@ private constructor( fun of( customersService: CustomerServiceAsync, params: CustomerListParams, - response: Response, + response: CustomerListPageResponse, ) = 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 - - 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 */ - } - - 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 [CustomerListPageAsync]. - */ - @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()) - } - } - class AutoPager(private val firstPage: CustomerListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { 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..b15fd504 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,17 +2,7 @@ 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.services.blocking.DimensionalPriceGroupService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -24,14 +14,27 @@ class DimensionalPriceGroupListPage private constructor( private val dimensionalPriceGroupsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): DimensionalPriceGroups = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -46,13 +49,9 @@ private constructor( override fun toString() = "DimensionalPriceGroupListPage{dimensionalPriceGroupsService=$dimensionalPriceGroupsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -60,9 +59,13 @@ 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() ) } @@ -79,127 +82,10 @@ private constructor( fun of( dimensionalPriceGroupsService: DimensionalPriceGroupService, params: DimensionalPriceGroupListParams, - response: Response, + response: DimensionalPriceGroups, ) = 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() - - 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 - } - - 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 - * [DimensionalPriceGroupListPage]. - */ - @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()) - } - } - class AutoPager(private val firstPage: DimensionalPriceGroupListPage) : Iterable { 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..4e36fe97 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,7 @@ 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.services.async.DimensionalPriceGroupServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -25,14 +15,27 @@ class DimensionalPriceGroupListPageAsync private constructor( private val dimensionalPriceGroupsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): DimensionalPriceGroups = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,13 +50,9 @@ private constructor( override fun toString() = "DimensionalPriceGroupListPageAsync{dimensionalPriceGroupsService=$dimensionalPriceGroupsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -61,9 +60,13 @@ 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() ) } @@ -82,127 +85,10 @@ private constructor( fun of( dimensionalPriceGroupsService: DimensionalPriceGroupServiceAsync, params: DimensionalPriceGroupListParams, - response: Response, + response: DimensionalPriceGroups, ) = 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 - } - - 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 - * [DimensionalPriceGroupListPageAsync]. - */ - @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()) - } - } - class AutoPager(private val firstPage: DimensionalPriceGroupListPageAsync) { fun forEach( 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..296e9dc0 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,17 +2,7 @@ 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.services.blocking.events.BackfillService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -31,14 +21,27 @@ class EventBackfillListPage private constructor( private val backfillsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): EventBackfillListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -53,13 +56,9 @@ private constructor( override fun toString() = "EventBackfillListPage{backfillsService=$backfillsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -67,9 +66,13 @@ 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() ) } @@ -86,129 +89,10 @@ private constructor( fun of( backfillsService: BackfillService, params: EventBackfillListParams, - response: Response, + response: EventBackfillListPageResponse, ) = 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) - - 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 */ - } - - 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 [EventBackfillListPage]. - */ - @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()) - } - } - class AutoPager(private val firstPage: EventBackfillListPage) : Iterable { 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..623ca86e 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,7 @@ 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.services.async.events.BackfillServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -32,14 +22,27 @@ class EventBackfillListPageAsync private constructor( private val backfillsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): EventBackfillListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -54,13 +57,9 @@ private constructor( override fun toString() = "EventBackfillListPageAsync{backfillsService=$backfillsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -68,9 +67,13 @@ 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() ) } @@ -89,130 +92,10 @@ private constructor( fun of( backfillsService: BackfillServiceAsync, params: EventBackfillListParams, - response: Response, + response: EventBackfillListPageResponse, ) = 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 - } - - 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 */ - } - - 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 - * [EventBackfillListPageAsync]. - */ - @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()) - } - } - class AutoPager(private val firstPage: EventBackfillListPageAsync) { fun forEach( 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..d125013b 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,17 +2,7 @@ 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.services.blocking.InvoiceService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -37,14 +27,26 @@ class InvoiceListPage private constructor( private val invoicesService: InvoiceService, private val params: InvoiceListParams, - private val response: Response, + private val response: InvoiceListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): InvoiceListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [InvoiceListPageResponse], but gracefully handles missing data. + * + * @see [InvoiceListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [InvoiceListPageResponse], but gracefully handles missing data. + * + * @see [InvoiceListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -59,13 +61,9 @@ private constructor( override fun toString() = "InvoiceListPage{invoicesService=$invoicesService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -73,9 +71,13 @@ 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() ) } @@ -89,122 +91,11 @@ private constructor( 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() - - 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 - } - - 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 [InvoiceListPage]. */ - @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()) - } + fun of( + invoicesService: InvoiceService, + params: InvoiceListParams, + response: InvoiceListPageResponse, + ) = InvoiceListPage(invoicesService, params, response) } class AutoPager(private val firstPage: InvoiceListPage) : Iterable { 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..2796213d 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,7 @@ 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.services.async.InvoiceServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -38,14 +28,26 @@ class InvoiceListPageAsync private constructor( private val invoicesService: InvoiceServiceAsync, private val params: InvoiceListParams, - private val response: Response, + private val response: InvoiceListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): InvoiceListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [InvoiceListPageResponse], but gracefully handles missing data. + * + * @see [InvoiceListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [InvoiceListPageResponse], but gracefully handles missing data. + * + * @see [InvoiceListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -60,13 +62,9 @@ private constructor( override fun toString() = "InvoiceListPageAsync{invoicesService=$invoicesService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -74,9 +72,13 @@ 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() ) } @@ -95,124 +97,10 @@ private constructor( fun of( invoicesService: InvoiceServiceAsync, params: InvoiceListParams, - response: Response, + response: InvoiceListPageResponse, ) = 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 - - 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 */ - } - - 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 [InvoiceListPageAsync]. */ - @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()) - } - } - class AutoPager(private val firstPage: InvoiceListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { 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..86b88d77 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,17 +2,7 @@ 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.services.blocking.ItemService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -24,14 +14,26 @@ class ItemListPage private constructor( private val itemsService: ItemService, private val params: ItemListParams, - private val response: Response, + private val response: ItemListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ItemListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [ItemListPageResponse], but gracefully handles missing data. + * + * @see [ItemListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [ItemListPageResponse], but gracefully handles missing data. + * + * @see [ItemListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -46,13 +48,9 @@ private constructor( override fun toString() = "ItemListPage{itemsService=$itemsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -60,9 +58,13 @@ 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() ) } @@ -76,124 +78,10 @@ private constructor( companion object { @JvmStatic - fun of(itemsService: ItemService, params: ItemListParams, response: Response) = + fun of(itemsService: ItemService, params: ItemListParams, response: ItemListPageResponse) = 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") - - @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 - } - - 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 [ItemListPage]. */ - @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()) - } - } - class AutoPager(private val firstPage: ItemListPage) : Iterable { override fun iterator(): Iterator = iterator { 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..d0178cd6 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,7 @@ 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.services.async.ItemServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -25,14 +15,26 @@ class ItemListPageAsync private constructor( private val itemsService: ItemServiceAsync, private val params: ItemListParams, - private val response: Response, + private val response: ItemListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): ItemListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [ItemListPageResponse], but gracefully handles missing data. + * + * @see [ItemListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [ItemListPageResponse], but gracefully handles missing data. + * + * @see [ItemListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -47,13 +49,9 @@ private constructor( override fun toString() = "ItemListPageAsync{itemsService=$itemsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -61,9 +59,13 @@ 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() ) } @@ -79,122 +81,11 @@ private constructor( 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 - - 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 */ - } - - 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 [ItemListPageAsync]. */ - @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()) - } + fun of( + itemsService: ItemServiceAsync, + params: ItemListParams, + response: ItemListPageResponse, + ) = ItemListPageAsync(itemsService, params, response) } class AutoPager(private val firstPage: ItemListPageAsync) { 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..a2154ad2 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,17 +2,7 @@ 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.services.blocking.MetricService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,14 +17,27 @@ class MetricListPage private constructor( private val metricsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): MetricListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -49,13 +52,9 @@ private constructor( override fun toString() = "MetricListPage{metricsService=$metricsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -63,9 +62,13 @@ 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() ) } @@ -79,122 +82,11 @@ private constructor( 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") - - @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 - } - - 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 [MetricListPage]. */ - @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()) - } + fun of( + metricsService: MetricService, + params: MetricListParams, + response: MetricListPageResponse, + ) = MetricListPage(metricsService, params, response) } class AutoPager(private val firstPage: MetricListPage) : Iterable { 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..9f1c9d41 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,7 @@ 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.services.async.MetricServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,14 +18,27 @@ class MetricListPageAsync private constructor( private val metricsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): MetricListPageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -50,13 +53,9 @@ private constructor( override fun toString() = "MetricListPageAsync{metricsService=$metricsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -64,9 +63,13 @@ 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() ) } @@ -82,122 +85,11 @@ private constructor( 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 - - 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 */ - } - - 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 [MetricListPageAsync]. */ - @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()) - } + fun of( + metricsService: MetricServiceAsync, + params: MetricListParams, + response: MetricListPageResponse, + ) = MetricListPageAsync(metricsService, params, response) } class AutoPager(private val firstPage: MetricListPageAsync) { 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..9df79080 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,17 +2,7 @@ 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.services.blocking.PlanService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -29,14 +19,26 @@ class PlanListPage private constructor( private val plansService: PlanService, private val params: PlanListParams, - private val response: Response, + private val response: PlanListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): PlanListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [PlanListPageResponse], but gracefully handles missing data. + * + * @see [PlanListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [PlanListPageResponse], but gracefully handles missing data. + * + * @see [PlanListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -51,13 +53,9 @@ private constructor( override fun toString() = "PlanListPage{plansService=$plansService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -65,9 +63,13 @@ 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() ) } @@ -81,124 +83,10 @@ private constructor( companion object { @JvmStatic - fun of(plansService: PlanService, params: PlanListParams, response: Response) = + fun of(plansService: PlanService, params: PlanListParams, response: PlanListPageResponse) = 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") - - @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 - } - - 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 [PlanListPage]. */ - @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()) - } - } - class AutoPager(private val firstPage: PlanListPage) : Iterable { override fun iterator(): Iterator = iterator { 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..f8154d59 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,7 @@ 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.services.async.PlanServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -30,14 +20,26 @@ class PlanListPageAsync private constructor( private val plansService: PlanServiceAsync, private val params: PlanListParams, - private val response: Response, + private val response: PlanListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): PlanListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [PlanListPageResponse], but gracefully handles missing data. + * + * @see [PlanListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [PlanListPageResponse], but gracefully handles missing data. + * + * @see [PlanListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -52,13 +54,9 @@ private constructor( override fun toString() = "PlanListPageAsync{plansService=$plansService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -66,9 +64,13 @@ 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() ) } @@ -84,122 +86,11 @@ private constructor( 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 - - 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 */ - } - - 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 [PlanListPageAsync]. */ - @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()) - } + fun of( + plansService: PlanServiceAsync, + params: PlanListParams, + response: PlanListPageResponse, + ) = PlanListPageAsync(plansService, params, response) } class AutoPager(private val firstPage: PlanListPageAsync) { 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..a465d17a 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,17 +2,7 @@ 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.services.blocking.PriceService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -27,14 +17,26 @@ class PriceListPage private constructor( private val pricesService: PriceService, private val params: PriceListParams, - private val response: Response, + private val response: PriceListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): PriceListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [PriceListPageResponse], but gracefully handles missing data. + * + * @see [PriceListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [PriceListPageResponse], but gracefully handles missing data. + * + * @see [PriceListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -49,13 +51,9 @@ private constructor( override fun toString() = "PriceListPage{pricesService=$pricesService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -63,9 +61,13 @@ 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() ) } @@ -79,122 +81,11 @@ private constructor( 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") - - @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 - } - - 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 [PriceListPage]. */ - @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()) - } + fun of( + pricesService: PriceService, + params: PriceListParams, + response: PriceListPageResponse, + ) = PriceListPage(pricesService, params, response) } class AutoPager(private val firstPage: PriceListPage) : Iterable { 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..d149b008 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,7 @@ 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.services.async.PriceServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -28,14 +18,26 @@ class PriceListPageAsync private constructor( private val pricesService: PriceServiceAsync, private val params: PriceListParams, - private val response: Response, + private val response: PriceListPageResponse, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): PriceListPageResponse = response - fun data(): List = response().data() + /** + * Delegates to [PriceListPageResponse], but gracefully handles missing data. + * + * @see [PriceListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [PriceListPageResponse], but gracefully handles missing data. + * + * @see [PriceListPageResponse.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -50,13 +52,9 @@ private constructor( override fun toString() = "PriceListPageAsync{pricesService=$pricesService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -64,9 +62,13 @@ 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() ) } @@ -82,122 +84,11 @@ private constructor( 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 - - 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 */ - } - - 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 [PriceListPageAsync]. */ - @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()) - } + fun of( + pricesService: PriceServiceAsync, + params: PriceListParams, + response: PriceListPageResponse, + ) = PriceListPageAsync(pricesService, params, response) } class AutoPager(private val firstPage: PriceListPageAsync) { 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..d9442f31 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,17 +2,7 @@ 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.services.blocking.SubscriptionService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -28,14 +18,27 @@ class SubscriptionFetchSchedulePage private constructor( private val subscriptionsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): SubscriptionFetchSchedulePageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -50,13 +53,9 @@ private constructor( override fun toString() = "SubscriptionFetchSchedulePage{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -64,9 +63,13 @@ 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() ) } @@ -83,132 +86,10 @@ private constructor( fun of( subscriptionsService: SubscriptionService, params: SubscriptionFetchScheduleParams, - response: Response, + response: SubscriptionFetchSchedulePageResponse, ) = SubscriptionFetchSchedulePage(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 - } - - 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 - * [SubscriptionFetchSchedulePage]. - */ - @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()) - } - } - class AutoPager(private val firstPage: SubscriptionFetchSchedulePage) : Iterable { 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..c8e1a196 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,7 @@ 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.services.async.SubscriptionServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -29,14 +19,27 @@ class SubscriptionFetchSchedulePageAsync private constructor( private val subscriptionsService: 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() + /** Returns the response that this page was parsed from. */ + fun response(): SubscriptionFetchSchedulePageResponse = response + + /** + * 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") override fun equals(other: Any?): Boolean { if (this === other) { @@ -51,13 +54,9 @@ private constructor( override fun toString() = "SubscriptionFetchSchedulePageAsync{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -65,9 +64,13 @@ 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() ) } @@ -86,132 +89,10 @@ private constructor( fun of( subscriptionsService: SubscriptionServiceAsync, params: SubscriptionFetchScheduleParams, - response: Response, + response: SubscriptionFetchSchedulePageResponse, ) = SubscriptionFetchSchedulePageAsync(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 - } - - 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 - * [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()) - } - } - class AutoPager(private val firstPage: SubscriptionFetchSchedulePageAsync) { fun forEach( 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..f052b950 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,17 +2,7 @@ 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.services.blocking.SubscriptionService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream @@ -33,14 +23,26 @@ class SubscriptionListPage private constructor( private val subscriptionsService: SubscriptionService, private val params: SubscriptionListParams, - private val response: Response, + private val response: Subscriptions, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): Subscriptions = response - fun data(): List = response().data() + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -55,13 +57,9 @@ private constructor( override fun toString() = "SubscriptionListPage{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -69,9 +67,13 @@ 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() ) } @@ -88,124 +90,10 @@ private constructor( fun of( subscriptionsService: SubscriptionService, params: SubscriptionListParams, - response: Response, + response: Subscriptions, ) = 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() - - 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 - } - - 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 [SubscriptionListPage]. */ - @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()) - } - } - class AutoPager(private val firstPage: SubscriptionListPage) : Iterable { override fun iterator(): Iterator = iterator { 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..16d9c420 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,7 @@ 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.services.async.SubscriptionServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -34,14 +24,26 @@ class SubscriptionListPageAsync private constructor( private val subscriptionsService: SubscriptionServiceAsync, private val params: SubscriptionListParams, - private val response: Response, + private val response: Subscriptions, ) { - fun response(): Response = response + /** Returns the response that this page was parsed from. */ + fun response(): Subscriptions = response - fun data(): List = response().data() + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun paginationMetadata(): PaginationMetadata = response().paginationMetadata() + /** + * Delegates to [Subscriptions], but gracefully handles missing data. + * + * @see [Subscriptions.paginationMetadata] + */ + fun paginationMetadata(): Optional = + response._paginationMetadata().getOptional("pagination_metadata") override fun equals(other: Any?): Boolean { if (this === other) { @@ -56,13 +58,9 @@ private constructor( override fun toString() = "SubscriptionListPageAsync{subscriptionsService=$subscriptionsService, params=$params, response=$response}" - fun hasNextPage(): Boolean { - if (data().isEmpty()) { - return false - } - - return paginationMetadata().nextCursor().isPresent - } + fun hasNextPage(): Boolean = + data().isNotEmpty() && + paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -70,9 +68,13 @@ 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() ) } @@ -91,127 +93,10 @@ private constructor( fun of( subscriptionsService: SubscriptionServiceAsync, params: SubscriptionListParams, - response: Response, + response: Subscriptions, ) = 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 - - 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 */ - } - - 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 - * [SubscriptionListPageAsync]. - */ - @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()) - } - } - class AutoPager(private val firstPage: SubscriptionListPageAsync) { fun forEach(action: Predicate, executor: Executor): CompletableFuture { 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..eed3630c 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( 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..d4991cdc 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( 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..891b2d6c 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( 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..480be906 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( 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..d1f32baf 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( 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..ab74d753 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( 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..c8208fdf 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( 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..9f5c7008 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( 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..34d60774 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( 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..c3224575 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( 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..3ef14351 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, @@ -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( 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..50cd7012 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, 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..1efbff97 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( 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..47c8154c 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( @@ -109,9 +111,8 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val listByExternalIdHandler: - Handler = - jsonHandler(clientOptions.jsonMapper) + private val listByExternalIdHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listByExternalId( 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..7aa39f4d 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( @@ -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( 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..2abbb3ed 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( @@ -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( 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..a9f522f9 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( 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..85bed6a7 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( 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..9c51dfb8 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( 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..211aa5be 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( 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..54521122 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( 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..39ad5f9b 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( 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..62401c8b 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( 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..b69537f3 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( 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..36f676bc 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( 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..002b5244 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( 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..3bcec6ac 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( 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..81070321 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, @@ -339,8 +340,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( 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..72ccf425 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, 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..ad57833c 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( 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..4be4dbfc 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( @@ -99,8 +101,8 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val listByExternalIdHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listByExternalIdHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listByExternalId( 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..373c4511 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( @@ -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( 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..5051e0e9 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( @@ -227,8 +229,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( 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..7de1684e 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( 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) + } +}