diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index d0ab6645f..2a8f4ffdd 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "1.2.0"
+ ".": "1.3.0"
}
\ No newline at end of file
diff --git a/.stats.yml b/.stats.yml
index 4db8fd706..31ac085db 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,4 +1,4 @@
configured_endpoints: 116
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-d4db2933d3d6b8c855e3351dcce658777ec9a413eb78f176b2e63b1e99fddf68.yml
-openapi_spec_hash: 858adc7f2e0c8c631ef733dfd8f9ea0a
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-0db984d367f9ae04249fb6c72789b0a38ef1785d156b438fe03290fa4e262a7d.yml
+openapi_spec_hash: c901c8b4fc2b0399a33b1346f8521850
config_hash: 3c3524be9607afb24d2139ce26ce5389
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 173d318b4..040abd393 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,13 @@
# Changelog
+## 1.3.0 (2025-07-08)
+
+Full Changelog: [v1.2.0...v1.3.0](https://github.com/orbcorp/orb-java/compare/v1.2.0...v1.3.0)
+
+### Features
+
+* **api:** api update ([a00c440](https://github.com/orbcorp/orb-java/commit/a00c44048af7b073e3ec72ea61239f57aa46c291))
+
## 1.2.0 (2025-07-04)
Full Changelog: [v1.1.0...v1.2.0](https://github.com/orbcorp/orb-java/compare/v1.1.0...v1.2.0)
diff --git a/README.md b/README.md
index 7865b06ba..09e41e3b5 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
-[](https://central.sonatype.com/artifact/com.withorb.api/orb-java/1.2.0)
+[](https://central.sonatype.com/artifact/com.withorb.api/orb-java/1.3.0)
@@ -19,7 +19,7 @@ The REST API documentation can be found on [docs.withorb.com](https://docs.witho
### Gradle
```kotlin
-implementation("com.withorb.api:orb-java:1.2.0")
+implementation("com.withorb.api:orb-java:1.3.0")
```
### Maven
@@ -28,7 +28,7 @@ implementation("com.withorb.api:orb-java:1.2.0")
com.withorb.api
orb-java
- 1.2.0
+ 1.3.0
```
diff --git a/build.gradle.kts b/build.gradle.kts
index d322f3768..347ed7433 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,4 +1,4 @@
allprojects {
group = "com.withorb.api"
- version = "1.2.0" // x-release-please-version
+ version = "1.3.0" // x-release-please-version
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParams.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParams.kt
index a5860df11..46ec1b4b2 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParams.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParams.kt
@@ -21,6 +21,7 @@ import com.withorb.api.core.JsonField
import com.withorb.api.core.JsonMissing
import com.withorb.api.core.JsonValue
import com.withorb.api.core.Params
+import com.withorb.api.core.allMaxBy
import com.withorb.api.core.checkRequired
import com.withorb.api.core.getOrThrow
import com.withorb.api.core.http.Headers
@@ -1179,6 +1180,7 @@ private constructor(
private constructor(
private val autoCollection: JsonField,
private val netTerms: JsonField,
+ private val invoiceDate: JsonField,
private val memo: JsonField,
private val requireSuccessfulPayment: JsonField,
private val additionalProperties: MutableMap,
@@ -1192,13 +1194,23 @@ private constructor(
@JsonProperty("net_terms")
@ExcludeMissing
netTerms: JsonField = JsonMissing.of(),
+ @JsonProperty("invoice_date")
+ @ExcludeMissing
+ invoiceDate: JsonField = JsonMissing.of(),
@JsonProperty("memo")
@ExcludeMissing
memo: JsonField = JsonMissing.of(),
@JsonProperty("require_successful_payment")
@ExcludeMissing
requireSuccessfulPayment: JsonField = JsonMissing.of(),
- ) : this(autoCollection, netTerms, memo, requireSuccessfulPayment, mutableMapOf())
+ ) : this(
+ autoCollection,
+ netTerms,
+ invoiceDate,
+ memo,
+ requireSuccessfulPayment,
+ mutableMapOf(),
+ )
/**
* Whether the credits purchase invoice should auto collect with the customer's
@@ -1221,6 +1233,16 @@ private constructor(
*/
fun netTerms(): Long = netTerms.getRequired("net_terms")
+ /**
+ * An ISO 8601 format date that denotes when this invoice should be dated in the
+ * customer's timezone. If not provided, the invoice date will default to the credit
+ * block's effective date.
+ *
+ * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if
+ * the server responded with an unexpected value).
+ */
+ fun invoiceDate(): Optional = invoiceDate.getOptional("invoice_date")
+
/**
* An optional memo to display on the invoice.
*
@@ -1259,6 +1281,16 @@ private constructor(
@ExcludeMissing
fun _netTerms(): JsonField = netTerms
+ /**
+ * Returns the raw JSON value of [invoiceDate].
+ *
+ * Unlike [invoiceDate], this method doesn't throw if the JSON field has an
+ * unexpected type.
+ */
+ @JsonProperty("invoice_date")
+ @ExcludeMissing
+ fun _invoiceDate(): JsonField = invoiceDate
+
/**
* Returns the raw JSON value of [memo].
*
@@ -1308,6 +1340,7 @@ private constructor(
private var autoCollection: JsonField? = null
private var netTerms: JsonField? = null
+ private var invoiceDate: JsonField = JsonMissing.of()
private var memo: JsonField = JsonMissing.of()
private var requireSuccessfulPayment: JsonField = JsonMissing.of()
private var additionalProperties: MutableMap = mutableMapOf()
@@ -1316,6 +1349,7 @@ private constructor(
internal fun from(invoiceSettings: InvoiceSettings) = apply {
autoCollection = invoiceSettings.autoCollection
netTerms = invoiceSettings.netTerms
+ invoiceDate = invoiceSettings.invoiceDate
memo = invoiceSettings.memo
requireSuccessfulPayment = invoiceSettings.requireSuccessfulPayment
additionalProperties = invoiceSettings.additionalProperties.toMutableMap()
@@ -1355,6 +1389,36 @@ private constructor(
*/
fun netTerms(netTerms: JsonField) = apply { this.netTerms = netTerms }
+ /**
+ * An ISO 8601 format date that denotes when this invoice should be dated in the
+ * customer's timezone. If not provided, the invoice date will default to the
+ * credit block's effective date.
+ */
+ fun invoiceDate(invoiceDate: InvoiceDate?) =
+ invoiceDate(JsonField.ofNullable(invoiceDate))
+
+ /** Alias for calling [Builder.invoiceDate] with `invoiceDate.orElse(null)`. */
+ fun invoiceDate(invoiceDate: Optional) =
+ invoiceDate(invoiceDate.getOrNull())
+
+ /**
+ * Sets [Builder.invoiceDate] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.invoiceDate] with a well-typed [InvoiceDate]
+ * value instead. This method is primarily for setting the field to an
+ * undocumented or not yet supported value.
+ */
+ fun invoiceDate(invoiceDate: JsonField) = apply {
+ this.invoiceDate = invoiceDate
+ }
+
+ /** Alias for calling [invoiceDate] with `InvoiceDate.ofDate(date)`. */
+ fun invoiceDate(date: LocalDate) = invoiceDate(InvoiceDate.ofDate(date))
+
+ /** Alias for calling [invoiceDate] with `InvoiceDate.ofDateTime(dateTime)`. */
+ fun invoiceDate(dateTime: OffsetDateTime) =
+ invoiceDate(InvoiceDate.ofDateTime(dateTime))
+
/** An optional memo to display on the invoice. */
fun memo(memo: String?) = memo(JsonField.ofNullable(memo))
@@ -1428,6 +1492,7 @@ private constructor(
InvoiceSettings(
checkRequired("autoCollection", autoCollection),
checkRequired("netTerms", netTerms),
+ invoiceDate,
memo,
requireSuccessfulPayment,
additionalProperties.toMutableMap(),
@@ -1443,6 +1508,7 @@ private constructor(
autoCollection()
netTerms()
+ invoiceDate().ifPresent { it.validate() }
memo()
requireSuccessfulPayment()
validated = true
@@ -1466,25 +1532,204 @@ private constructor(
internal fun validity(): Int =
(if (autoCollection.asKnown().isPresent) 1 else 0) +
(if (netTerms.asKnown().isPresent) 1 else 0) +
+ (invoiceDate.asKnown().getOrNull()?.validity() ?: 0) +
(if (memo.asKnown().isPresent) 1 else 0) +
(if (requireSuccessfulPayment.asKnown().isPresent) 1 else 0)
+ /**
+ * An ISO 8601 format date that denotes when this invoice should be dated in the
+ * customer's timezone. If not provided, the invoice date will default to the credit
+ * block's effective date.
+ */
+ @JsonDeserialize(using = InvoiceDate.Deserializer::class)
+ @JsonSerialize(using = InvoiceDate.Serializer::class)
+ class InvoiceDate
+ private constructor(
+ private val date: LocalDate? = null,
+ private val dateTime: OffsetDateTime? = null,
+ private val _json: JsonValue? = null,
+ ) {
+
+ fun date(): Optional = Optional.ofNullable(date)
+
+ fun dateTime(): Optional = Optional.ofNullable(dateTime)
+
+ fun isDate(): Boolean = date != null
+
+ fun isDateTime(): Boolean = dateTime != null
+
+ fun asDate(): LocalDate = date.getOrThrow("date")
+
+ fun asDateTime(): OffsetDateTime = dateTime.getOrThrow("dateTime")
+
+ fun _json(): Optional = Optional.ofNullable(_json)
+
+ fun accept(visitor: Visitor): T =
+ when {
+ date != null -> visitor.visitDate(date)
+ dateTime != null -> visitor.visitDateTime(dateTime)
+ else -> visitor.unknown(_json)
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): InvoiceDate = apply {
+ if (validated) {
+ return@apply
+ }
+
+ accept(
+ object : Visitor {
+ override fun visitDate(date: LocalDate) {}
+
+ override fun visitDateTime(dateTime: OffsetDateTime) {}
+ }
+ )
+ 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 =
+ accept(
+ object : Visitor {
+ override fun visitDate(date: LocalDate) = 1
+
+ override fun visitDateTime(dateTime: OffsetDateTime) = 1
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is InvoiceDate && date == other.date && dateTime == other.dateTime /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(date, dateTime) /* spotless:on */
+
+ override fun toString(): String =
+ when {
+ date != null -> "InvoiceDate{date=$date}"
+ dateTime != null -> "InvoiceDate{dateTime=$dateTime}"
+ _json != null -> "InvoiceDate{_unknown=$_json}"
+ else -> throw IllegalStateException("Invalid InvoiceDate")
+ }
+
+ companion object {
+
+ @JvmStatic fun ofDate(date: LocalDate) = InvoiceDate(date = date)
+
+ @JvmStatic
+ fun ofDateTime(dateTime: OffsetDateTime) = InvoiceDate(dateTime = dateTime)
+ }
+
+ /**
+ * An interface that defines how to map each variant of [InvoiceDate] to a value
+ * of type [T].
+ */
+ interface Visitor {
+
+ fun visitDate(date: LocalDate): T
+
+ fun visitDateTime(dateTime: OffsetDateTime): T
+
+ /**
+ * Maps an unknown variant of [InvoiceDate] to a value of type [T].
+ *
+ * An instance of [InvoiceDate] can contain an unknown variant if it was
+ * deserialized from data that doesn't match any known variant. For example,
+ * if the SDK is on an older version than the API, then the API may respond
+ * with new variants that the SDK is unaware of.
+ *
+ * @throws OrbInvalidDataException in the default implementation.
+ */
+ fun unknown(json: JsonValue?): T {
+ throw OrbInvalidDataException("Unknown InvoiceDate: $json")
+ }
+ }
+
+ internal class Deserializer :
+ BaseDeserializer(InvoiceDate::class) {
+
+ override fun ObjectCodec.deserialize(node: JsonNode): InvoiceDate {
+ val json = JsonValue.fromJsonNode(node)
+
+ val bestMatches =
+ sequenceOf(
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ InvoiceDate(date = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())
+ ?.let { InvoiceDate(dateTime = it, _json = json) },
+ )
+ .filterNotNull()
+ .allMaxBy { it.validity() }
+ .toList()
+ return when (bestMatches.size) {
+ // This can happen if what we're deserializing is completely
+ // incompatible with all the possible variants (e.g. deserializing
+ // from object).
+ 0 -> InvoiceDate(_json = json)
+ 1 -> bestMatches.single()
+ // If there's more than one match with the highest validity, then
+ // use the first completely valid match, or simply the first match
+ // if none are completely valid.
+ else ->
+ bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first()
+ }
+ }
+ }
+
+ internal class Serializer : BaseSerializer(InvoiceDate::class) {
+
+ override fun serialize(
+ value: InvoiceDate,
+ generator: JsonGenerator,
+ provider: SerializerProvider,
+ ) {
+ when {
+ value.date != null -> generator.writeObject(value.date)
+ value.dateTime != null -> generator.writeObject(value.dateTime)
+ value._json != null -> generator.writeObject(value._json)
+ else -> throw IllegalStateException("Invalid InvoiceDate")
+ }
+ }
+ }
+ }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
- return /* spotless:off */ other is InvoiceSettings && autoCollection == other.autoCollection && netTerms == other.netTerms && memo == other.memo && requireSuccessfulPayment == other.requireSuccessfulPayment && additionalProperties == other.additionalProperties /* spotless:on */
+ return /* spotless:off */ other is InvoiceSettings && autoCollection == other.autoCollection && netTerms == other.netTerms && invoiceDate == other.invoiceDate && memo == other.memo && requireSuccessfulPayment == other.requireSuccessfulPayment && additionalProperties == other.additionalProperties /* spotless:on */
}
/* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(autoCollection, netTerms, memo, requireSuccessfulPayment, additionalProperties) }
+ private val hashCode: Int by lazy { Objects.hash(autoCollection, netTerms, invoiceDate, memo, requireSuccessfulPayment, additionalProperties) }
/* spotless:on */
override fun hashCode(): Int = hashCode
override fun toString() =
- "InvoiceSettings{autoCollection=$autoCollection, netTerms=$netTerms, memo=$memo, requireSuccessfulPayment=$requireSuccessfulPayment, additionalProperties=$additionalProperties}"
+ "InvoiceSettings{autoCollection=$autoCollection, netTerms=$netTerms, invoiceDate=$invoiceDate, memo=$memo, requireSuccessfulPayment=$requireSuccessfulPayment, additionalProperties=$additionalProperties}"
}
/**
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParams.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParams.kt
index 8f64f8fb6..458078873 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParams.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParams.kt
@@ -21,6 +21,7 @@ import com.withorb.api.core.JsonField
import com.withorb.api.core.JsonMissing
import com.withorb.api.core.JsonValue
import com.withorb.api.core.Params
+import com.withorb.api.core.allMaxBy
import com.withorb.api.core.checkRequired
import com.withorb.api.core.getOrThrow
import com.withorb.api.core.http.Headers
@@ -1171,6 +1172,7 @@ private constructor(
private constructor(
private val autoCollection: JsonField,
private val netTerms: JsonField,
+ private val invoiceDate: JsonField,
private val memo: JsonField,
private val requireSuccessfulPayment: JsonField,
private val additionalProperties: MutableMap,
@@ -1184,13 +1186,23 @@ private constructor(
@JsonProperty("net_terms")
@ExcludeMissing
netTerms: JsonField = JsonMissing.of(),
+ @JsonProperty("invoice_date")
+ @ExcludeMissing
+ invoiceDate: JsonField = JsonMissing.of(),
@JsonProperty("memo")
@ExcludeMissing
memo: JsonField = JsonMissing.of(),
@JsonProperty("require_successful_payment")
@ExcludeMissing
requireSuccessfulPayment: JsonField = JsonMissing.of(),
- ) : this(autoCollection, netTerms, memo, requireSuccessfulPayment, mutableMapOf())
+ ) : this(
+ autoCollection,
+ netTerms,
+ invoiceDate,
+ memo,
+ requireSuccessfulPayment,
+ mutableMapOf(),
+ )
/**
* Whether the credits purchase invoice should auto collect with the customer's
@@ -1213,6 +1225,16 @@ private constructor(
*/
fun netTerms(): Long = netTerms.getRequired("net_terms")
+ /**
+ * An ISO 8601 format date that denotes when this invoice should be dated in the
+ * customer's timezone. If not provided, the invoice date will default to the credit
+ * block's effective date.
+ *
+ * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if
+ * the server responded with an unexpected value).
+ */
+ fun invoiceDate(): Optional = invoiceDate.getOptional("invoice_date")
+
/**
* An optional memo to display on the invoice.
*
@@ -1251,6 +1273,16 @@ private constructor(
@ExcludeMissing
fun _netTerms(): JsonField = netTerms
+ /**
+ * Returns the raw JSON value of [invoiceDate].
+ *
+ * Unlike [invoiceDate], this method doesn't throw if the JSON field has an
+ * unexpected type.
+ */
+ @JsonProperty("invoice_date")
+ @ExcludeMissing
+ fun _invoiceDate(): JsonField = invoiceDate
+
/**
* Returns the raw JSON value of [memo].
*
@@ -1300,6 +1332,7 @@ private constructor(
private var autoCollection: JsonField? = null
private var netTerms: JsonField? = null
+ private var invoiceDate: JsonField = JsonMissing.of()
private var memo: JsonField = JsonMissing.of()
private var requireSuccessfulPayment: JsonField = JsonMissing.of()
private var additionalProperties: MutableMap = mutableMapOf()
@@ -1308,6 +1341,7 @@ private constructor(
internal fun from(invoiceSettings: InvoiceSettings) = apply {
autoCollection = invoiceSettings.autoCollection
netTerms = invoiceSettings.netTerms
+ invoiceDate = invoiceSettings.invoiceDate
memo = invoiceSettings.memo
requireSuccessfulPayment = invoiceSettings.requireSuccessfulPayment
additionalProperties = invoiceSettings.additionalProperties.toMutableMap()
@@ -1347,6 +1381,36 @@ private constructor(
*/
fun netTerms(netTerms: JsonField) = apply { this.netTerms = netTerms }
+ /**
+ * An ISO 8601 format date that denotes when this invoice should be dated in the
+ * customer's timezone. If not provided, the invoice date will default to the
+ * credit block's effective date.
+ */
+ fun invoiceDate(invoiceDate: InvoiceDate?) =
+ invoiceDate(JsonField.ofNullable(invoiceDate))
+
+ /** Alias for calling [Builder.invoiceDate] with `invoiceDate.orElse(null)`. */
+ fun invoiceDate(invoiceDate: Optional) =
+ invoiceDate(invoiceDate.getOrNull())
+
+ /**
+ * Sets [Builder.invoiceDate] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.invoiceDate] with a well-typed [InvoiceDate]
+ * value instead. This method is primarily for setting the field to an
+ * undocumented or not yet supported value.
+ */
+ fun invoiceDate(invoiceDate: JsonField) = apply {
+ this.invoiceDate = invoiceDate
+ }
+
+ /** Alias for calling [invoiceDate] with `InvoiceDate.ofDate(date)`. */
+ fun invoiceDate(date: LocalDate) = invoiceDate(InvoiceDate.ofDate(date))
+
+ /** Alias for calling [invoiceDate] with `InvoiceDate.ofDateTime(dateTime)`. */
+ fun invoiceDate(dateTime: OffsetDateTime) =
+ invoiceDate(InvoiceDate.ofDateTime(dateTime))
+
/** An optional memo to display on the invoice. */
fun memo(memo: String?) = memo(JsonField.ofNullable(memo))
@@ -1420,6 +1484,7 @@ private constructor(
InvoiceSettings(
checkRequired("autoCollection", autoCollection),
checkRequired("netTerms", netTerms),
+ invoiceDate,
memo,
requireSuccessfulPayment,
additionalProperties.toMutableMap(),
@@ -1435,6 +1500,7 @@ private constructor(
autoCollection()
netTerms()
+ invoiceDate().ifPresent { it.validate() }
memo()
requireSuccessfulPayment()
validated = true
@@ -1458,25 +1524,204 @@ private constructor(
internal fun validity(): Int =
(if (autoCollection.asKnown().isPresent) 1 else 0) +
(if (netTerms.asKnown().isPresent) 1 else 0) +
+ (invoiceDate.asKnown().getOrNull()?.validity() ?: 0) +
(if (memo.asKnown().isPresent) 1 else 0) +
(if (requireSuccessfulPayment.asKnown().isPresent) 1 else 0)
+ /**
+ * An ISO 8601 format date that denotes when this invoice should be dated in the
+ * customer's timezone. If not provided, the invoice date will default to the credit
+ * block's effective date.
+ */
+ @JsonDeserialize(using = InvoiceDate.Deserializer::class)
+ @JsonSerialize(using = InvoiceDate.Serializer::class)
+ class InvoiceDate
+ private constructor(
+ private val date: LocalDate? = null,
+ private val dateTime: OffsetDateTime? = null,
+ private val _json: JsonValue? = null,
+ ) {
+
+ fun date(): Optional = Optional.ofNullable(date)
+
+ fun dateTime(): Optional = Optional.ofNullable(dateTime)
+
+ fun isDate(): Boolean = date != null
+
+ fun isDateTime(): Boolean = dateTime != null
+
+ fun asDate(): LocalDate = date.getOrThrow("date")
+
+ fun asDateTime(): OffsetDateTime = dateTime.getOrThrow("dateTime")
+
+ fun _json(): Optional = Optional.ofNullable(_json)
+
+ fun accept(visitor: Visitor): T =
+ when {
+ date != null -> visitor.visitDate(date)
+ dateTime != null -> visitor.visitDateTime(dateTime)
+ else -> visitor.unknown(_json)
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): InvoiceDate = apply {
+ if (validated) {
+ return@apply
+ }
+
+ accept(
+ object : Visitor {
+ override fun visitDate(date: LocalDate) {}
+
+ override fun visitDateTime(dateTime: OffsetDateTime) {}
+ }
+ )
+ 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 =
+ accept(
+ object : Visitor {
+ override fun visitDate(date: LocalDate) = 1
+
+ override fun visitDateTime(dateTime: OffsetDateTime) = 1
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is InvoiceDate && date == other.date && dateTime == other.dateTime /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(date, dateTime) /* spotless:on */
+
+ override fun toString(): String =
+ when {
+ date != null -> "InvoiceDate{date=$date}"
+ dateTime != null -> "InvoiceDate{dateTime=$dateTime}"
+ _json != null -> "InvoiceDate{_unknown=$_json}"
+ else -> throw IllegalStateException("Invalid InvoiceDate")
+ }
+
+ companion object {
+
+ @JvmStatic fun ofDate(date: LocalDate) = InvoiceDate(date = date)
+
+ @JvmStatic
+ fun ofDateTime(dateTime: OffsetDateTime) = InvoiceDate(dateTime = dateTime)
+ }
+
+ /**
+ * An interface that defines how to map each variant of [InvoiceDate] to a value
+ * of type [T].
+ */
+ interface Visitor {
+
+ fun visitDate(date: LocalDate): T
+
+ fun visitDateTime(dateTime: OffsetDateTime): T
+
+ /**
+ * Maps an unknown variant of [InvoiceDate] to a value of type [T].
+ *
+ * An instance of [InvoiceDate] can contain an unknown variant if it was
+ * deserialized from data that doesn't match any known variant. For example,
+ * if the SDK is on an older version than the API, then the API may respond
+ * with new variants that the SDK is unaware of.
+ *
+ * @throws OrbInvalidDataException in the default implementation.
+ */
+ fun unknown(json: JsonValue?): T {
+ throw OrbInvalidDataException("Unknown InvoiceDate: $json")
+ }
+ }
+
+ internal class Deserializer :
+ BaseDeserializer(InvoiceDate::class) {
+
+ override fun ObjectCodec.deserialize(node: JsonNode): InvoiceDate {
+ val json = JsonValue.fromJsonNode(node)
+
+ val bestMatches =
+ sequenceOf(
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ InvoiceDate(date = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())
+ ?.let { InvoiceDate(dateTime = it, _json = json) },
+ )
+ .filterNotNull()
+ .allMaxBy { it.validity() }
+ .toList()
+ return when (bestMatches.size) {
+ // This can happen if what we're deserializing is completely
+ // incompatible with all the possible variants (e.g. deserializing
+ // from object).
+ 0 -> InvoiceDate(_json = json)
+ 1 -> bestMatches.single()
+ // If there's more than one match with the highest validity, then
+ // use the first completely valid match, or simply the first match
+ // if none are completely valid.
+ else ->
+ bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first()
+ }
+ }
+ }
+
+ internal class Serializer : BaseSerializer(InvoiceDate::class) {
+
+ override fun serialize(
+ value: InvoiceDate,
+ generator: JsonGenerator,
+ provider: SerializerProvider,
+ ) {
+ when {
+ value.date != null -> generator.writeObject(value.date)
+ value.dateTime != null -> generator.writeObject(value.dateTime)
+ value._json != null -> generator.writeObject(value._json)
+ else -> throw IllegalStateException("Invalid InvoiceDate")
+ }
+ }
+ }
+ }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
- return /* spotless:off */ other is InvoiceSettings && autoCollection == other.autoCollection && netTerms == other.netTerms && memo == other.memo && requireSuccessfulPayment == other.requireSuccessfulPayment && additionalProperties == other.additionalProperties /* spotless:on */
+ return /* spotless:off */ other is InvoiceSettings && autoCollection == other.autoCollection && netTerms == other.netTerms && invoiceDate == other.invoiceDate && memo == other.memo && requireSuccessfulPayment == other.requireSuccessfulPayment && additionalProperties == other.additionalProperties /* spotless:on */
}
/* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(autoCollection, netTerms, memo, requireSuccessfulPayment, additionalProperties) }
+ private val hashCode: Int by lazy { Objects.hash(autoCollection, netTerms, invoiceDate, memo, requireSuccessfulPayment, additionalProperties) }
/* spotless:on */
override fun hashCode(): Int = hashCode
override fun toString() =
- "InvoiceSettings{autoCollection=$autoCollection, netTerms=$netTerms, memo=$memo, requireSuccessfulPayment=$requireSuccessfulPayment, additionalProperties=$additionalProperties}"
+ "InvoiceSettings{autoCollection=$autoCollection, netTerms=$netTerms, invoiceDate=$invoiceDate, memo=$memo, requireSuccessfulPayment=$requireSuccessfulPayment, additionalProperties=$additionalProperties}"
}
/**
diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParamsTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParamsTest.kt
index 547cfd51e..23a9caafa 100644
--- a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParamsTest.kt
+++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryByExternalIdParamsTest.kt
@@ -3,6 +3,7 @@
package com.withorb.api.models
import com.withorb.api.core.JsonValue
+import java.time.LocalDate
import java.time.OffsetDateTime
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
@@ -26,6 +27,7 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdParamsTest {
.builder()
.autoCollection(true)
.netTerms(0L)
+ .invoiceDate(LocalDate.parse("2019-12-27"))
.memo("memo")
.requireSuccessfulPayment(true)
.build()
@@ -73,6 +75,7 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdParamsTest {
.builder()
.autoCollection(true)
.netTerms(0L)
+ .invoiceDate(LocalDate.parse("2019-12-27"))
.memo("memo")
.requireSuccessfulPayment(true)
.build()
@@ -106,6 +109,7 @@ internal class CustomerCreditLedgerCreateEntryByExternalIdParamsTest {
.builder()
.autoCollection(true)
.netTerms(0L)
+ .invoiceDate(LocalDate.parse("2019-12-27"))
.memo("memo")
.requireSuccessfulPayment(true)
.build()
diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParamsTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParamsTest.kt
index 2296b12a4..615cba892 100644
--- a/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParamsTest.kt
+++ b/orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreditLedgerCreateEntryParamsTest.kt
@@ -3,6 +3,7 @@
package com.withorb.api.models
import com.withorb.api.core.JsonValue
+import java.time.LocalDate
import java.time.OffsetDateTime
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
@@ -25,6 +26,7 @@ internal class CustomerCreditLedgerCreateEntryParamsTest {
.builder()
.autoCollection(true)
.netTerms(0L)
+ .invoiceDate(LocalDate.parse("2019-12-27"))
.memo("memo")
.requireSuccessfulPayment(true)
.build()
@@ -70,6 +72,7 @@ internal class CustomerCreditLedgerCreateEntryParamsTest {
.builder()
.autoCollection(true)
.netTerms(0L)
+ .invoiceDate(LocalDate.parse("2019-12-27"))
.memo("memo")
.requireSuccessfulPayment(true)
.build()
@@ -100,6 +103,7 @@ internal class CustomerCreditLedgerCreateEntryParamsTest {
.builder()
.autoCollection(true)
.netTerms(0L)
+ .invoiceDate(LocalDate.parse("2019-12-27"))
.memo("memo")
.requireSuccessfulPayment(true)
.build()
diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncTest.kt
index d46450b71..bd7fbe144 100644
--- a/orb-java-core/src/test/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncTest.kt
+++ b/orb-java-core/src/test/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncTest.kt
@@ -7,6 +7,7 @@ import com.withorb.api.client.okhttp.OrbOkHttpClientAsync
import com.withorb.api.core.JsonValue
import com.withorb.api.models.CustomerCreditLedgerCreateEntryByExternalIdParams
import com.withorb.api.models.CustomerCreditLedgerCreateEntryParams
+import java.time.LocalDate
import java.time.OffsetDateTime
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
@@ -54,6 +55,7 @@ internal class LedgerServiceAsyncTest {
.builder()
.autoCollection(true)
.netTerms(0L)
+ .invoiceDate(LocalDate.parse("2019-12-27"))
.memo("memo")
.requireSuccessfulPayment(true)
.build()
@@ -100,6 +102,7 @@ internal class LedgerServiceAsyncTest {
.builder()
.autoCollection(true)
.netTerms(0L)
+ .invoiceDate(LocalDate.parse("2019-12-27"))
.memo("memo")
.requireSuccessfulPayment(true)
.build()
diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceTest.kt
index 65c238cc7..c484ee91e 100644
--- a/orb-java-core/src/test/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceTest.kt
+++ b/orb-java-core/src/test/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceTest.kt
@@ -7,6 +7,7 @@ import com.withorb.api.client.okhttp.OrbOkHttpClient
import com.withorb.api.core.JsonValue
import com.withorb.api.models.CustomerCreditLedgerCreateEntryByExternalIdParams
import com.withorb.api.models.CustomerCreditLedgerCreateEntryParams
+import java.time.LocalDate
import java.time.OffsetDateTime
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
@@ -53,6 +54,7 @@ internal class LedgerServiceTest {
.builder()
.autoCollection(true)
.netTerms(0L)
+ .invoiceDate(LocalDate.parse("2019-12-27"))
.memo("memo")
.requireSuccessfulPayment(true)
.build()
@@ -98,6 +100,7 @@ internal class LedgerServiceTest {
.builder()
.autoCollection(true)
.netTerms(0L)
+ .invoiceDate(LocalDate.parse("2019-12-27"))
.memo("memo")
.requireSuccessfulPayment(true)
.build()