diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index e7562934..0c2ecec6 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.19.0"
+ ".": "0.20.0"
}
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c16b34ce..6c745f0d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,33 @@
# Changelog
+## 0.20.0 (2025-01-07)
+
+Full Changelog: [v0.19.0...v0.20.0](https://github.com/orbcorp/orb-java/compare/v0.19.0...v0.20.0)
+
+### Features
+
+* **client:** add various convenience setters to models ([#184](https://github.com/orbcorp/orb-java/issues/184)) ([5a7e67f](https://github.com/orbcorp/orb-java/commit/5a7e67f4aff5cd005c04148c72c4f9dbb1f65449))
+* **client:** allow setting arbitrary JSON for top-level body params ([5a7e67f](https://github.com/orbcorp/orb-java/commit/5a7e67f4aff5cd005c04148c72c4f9dbb1f65449))
+* **client:** expose getters for `JsonField` of body params ([5a7e67f](https://github.com/orbcorp/orb-java/commit/5a7e67f4aff5cd005c04148c72c4f9dbb1f65449))
+
+
+### Bug Fixes
+
+* **client:** consistently throw on omitting required fields ([5a7e67f](https://github.com/orbcorp/orb-java/commit/5a7e67f4aff5cd005c04148c72c4f9dbb1f65449))
+* **client:** convert `JsonField` containing list type to mutable in builder ([5a7e67f](https://github.com/orbcorp/orb-java/commit/5a7e67f4aff5cd005c04148c72c4f9dbb1f65449))
+
+
+### Documentation
+
+* add params class javadocs ([#182](https://github.com/orbcorp/orb-java/issues/182)) ([e98658d](https://github.com/orbcorp/orb-java/commit/e98658d54e9ef45334ae98fe2901a2db1574a900))
+
+
+### Styles
+
+* **internal:** explicitly add some method return types ([5a7e67f](https://github.com/orbcorp/orb-java/commit/5a7e67f4aff5cd005c04148c72c4f9dbb1f65449))
+* **internal:** move headers and query params setters below others ([5a7e67f](https://github.com/orbcorp/orb-java/commit/5a7e67f4aff5cd005c04148c72c4f9dbb1f65449))
+* **internal:** simplify existing convenience setters on params ([5a7e67f](https://github.com/orbcorp/orb-java/commit/5a7e67f4aff5cd005c04148c72c4f9dbb1f65449))
+
## 0.19.0 (2025-01-06)
Full Changelog: [v0.18.0...v0.19.0](https://github.com/orbcorp/orb-java/compare/v0.18.0...v0.19.0)
diff --git a/README.md b/README.md
index 6654207a..f98dc8ea 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
-[](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.19.0)
+[](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.20.0)
@@ -25,7 +25,7 @@ The REST API documentation can be foundĀ on [docs.withorb.com](https://docs.with
```kotlin
-implementation("com.withorb.api:orb-java:0.19.0")
+implementation("com.withorb.api:orb-java:0.20.0")
```
#### Maven
@@ -34,7 +34,7 @@ implementation("com.withorb.api:orb-java:0.19.0")
com.withorb.api
orb-java
- 0.19.0
+ 0.20.0
```
diff --git a/build.gradle.kts b/build.gradle.kts
index 64a0a083..2cba1d15 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -4,7 +4,7 @@ plugins {
allprojects {
group = "com.withorb.api"
- version = "0.19.0" // x-release-please-version
+ version = "0.20.0" // x-release-please-version
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt
index 39bcc89e..13987e4d 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt
@@ -72,6 +72,19 @@ private constructor(
fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }
+ fun responseValidation(responseValidation: Boolean) = apply {
+ this.responseValidation = responseValidation
+ }
+
+ fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries }
+
+ fun apiKey(apiKey: String) = apply { this.apiKey = apiKey }
+
+ fun webhookSecret(webhookSecret: String?) = apply { this.webhookSecret = webhookSecret }
+
+ fun webhookSecret(webhookSecret: Optional) =
+ webhookSecret(webhookSecret.orElse(null))
+
fun headers(headers: Headers) = apply {
this.headers.clear()
putAllHeaders(headers)
@@ -152,19 +165,6 @@ private constructor(
fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) }
- fun responseValidation(responseValidation: Boolean) = apply {
- this.responseValidation = responseValidation
- }
-
- fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries }
-
- fun apiKey(apiKey: String) = apply { this.apiKey = apiKey }
-
- fun webhookSecret(webhookSecret: String?) = apply { this.webhookSecret = webhookSecret }
-
- fun webhookSecret(webhookSecret: Optional) =
- webhookSecret(webhookSecret.orElse(null))
-
fun fromEnv() = apply {
System.getenv("ORB_API_KEY")?.let { apiKey(it) }
System.getenv("ORB_WEBHOOK_SECRET")?.let { webhookSecret(it) }
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/Alert.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/Alert.kt
index 04d2bcbd..9f81d149 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/Alert.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/Alert.kt
@@ -89,34 +89,40 @@ private constructor(
fun type(): Type = type.getRequired("type")
/** Also referred to as alert_id in this documentation. */
- @JsonProperty("id") @ExcludeMissing fun _id() = id
+ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id
/** The creation time of the resource in Orb. */
- @JsonProperty("created_at") @ExcludeMissing fun _createdAt() = createdAt
+ @JsonProperty("created_at")
+ @ExcludeMissing
+ fun _createdAt(): JsonField = createdAt
/** The name of the currency the credit balance or invoice cost is denominated in. */
- @JsonProperty("currency") @ExcludeMissing fun _currency() = currency
+ @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency
/** The customer the alert applies to. */
- @JsonProperty("customer") @ExcludeMissing fun _customer() = customer
+ @JsonProperty("customer") @ExcludeMissing fun _customer(): JsonField = customer
/** Whether the alert is enabled or disabled. */
- @JsonProperty("enabled") @ExcludeMissing fun _enabled() = enabled
+ @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled
/** The metric the alert applies to. */
- @JsonProperty("metric") @ExcludeMissing fun _metric() = metric
+ @JsonProperty("metric") @ExcludeMissing fun _metric(): JsonField = metric
/** The plan the alert applies to. */
- @JsonProperty("plan") @ExcludeMissing fun _plan() = plan
+ @JsonProperty("plan") @ExcludeMissing fun _plan(): JsonField = plan
/** The subscription the alert applies to. */
- @JsonProperty("subscription") @ExcludeMissing fun _subscription() = subscription
+ @JsonProperty("subscription")
+ @ExcludeMissing
+ fun _subscription(): JsonField = subscription
/** The thresholds that define the conditions under which the alert will be triggered. */
- @JsonProperty("thresholds") @ExcludeMissing fun _thresholds() = thresholds
+ @JsonProperty("thresholds")
+ @ExcludeMissing
+ fun _thresholds(): JsonField> = thresholds
/** The type of alert. This must be a valid alert type. */
- @JsonProperty("type") @ExcludeMissing fun _type() = type
+ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type
@JsonAnyGetter
@ExcludeMissing
@@ -149,16 +155,16 @@ private constructor(
class Builder {
- private var id: JsonField = JsonMissing.of()
- private var createdAt: JsonField = JsonMissing.of()
- private var currency: JsonField = JsonMissing.of()
- private var customer: JsonField = JsonMissing.of()
- private var enabled: JsonField = JsonMissing.of()
- private var metric: JsonField = JsonMissing.of()
- private var plan: JsonField = JsonMissing.of()
- private var subscription: JsonField = JsonMissing.of()
- private var thresholds: JsonField> = JsonMissing.of()
- private var type: JsonField = JsonMissing.of()
+ private var id: JsonField? = null
+ private var createdAt: JsonField? = null
+ private var currency: JsonField? = null
+ private var customer: JsonField? = null
+ private var enabled: JsonField? = null
+ private var metric: JsonField? = null
+ private var plan: JsonField? = null
+ private var subscription: JsonField? = null
+ private var thresholds: JsonField>? = null
+ private var type: JsonField? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
@@ -171,7 +177,7 @@ private constructor(
metric = alert.metric
plan = alert.plan
subscription = alert.subscription
- thresholds = alert.thresholds
+ thresholds = alert.thresholds.map { it.toMutableList() }
type = alert.type
additionalProperties = alert.additionalProperties.toMutableMap()
}
@@ -189,13 +195,19 @@ private constructor(
fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt }
/** The name of the currency the credit balance or invoice cost is denominated in. */
- fun currency(currency: String) = currency(JsonField.of(currency))
+ fun currency(currency: String?) = currency(JsonField.ofNullable(currency))
+
+ /** The name of the currency the credit balance or invoice cost is denominated in. */
+ fun currency(currency: Optional) = currency(currency.orElse(null))
/** The name of the currency the credit balance or invoice cost is denominated in. */
fun currency(currency: JsonField) = apply { this.currency = currency }
/** The customer the alert applies to. */
- fun customer(customer: Customer) = customer(JsonField.of(customer))
+ fun customer(customer: Customer?) = customer(JsonField.ofNullable(customer))
+
+ /** The customer the alert applies to. */
+ fun customer(customer: Optional) = customer(customer.orElse(null))
/** The customer the alert applies to. */
fun customer(customer: JsonField) = apply { this.customer = customer }
@@ -207,19 +219,30 @@ private constructor(
fun enabled(enabled: JsonField) = apply { this.enabled = enabled }
/** The metric the alert applies to. */
- fun metric(metric: Metric) = metric(JsonField.of(metric))
+ fun metric(metric: Metric?) = metric(JsonField.ofNullable(metric))
+
+ /** The metric the alert applies to. */
+ fun metric(metric: Optional) = metric(metric.orElse(null))
/** The metric the alert applies to. */
fun metric(metric: JsonField) = apply { this.metric = metric }
/** The plan the alert applies to. */
- fun plan(plan: Plan) = plan(JsonField.of(plan))
+ fun plan(plan: Plan?) = plan(JsonField.ofNullable(plan))
+
+ /** The plan the alert applies to. */
+ fun plan(plan: Optional) = plan(plan.orElse(null))
/** The plan the alert applies to. */
fun plan(plan: JsonField) = apply { this.plan = plan }
/** The subscription the alert applies to. */
- fun subscription(subscription: Subscription) = subscription(JsonField.of(subscription))
+ fun subscription(subscription: Subscription?) =
+ subscription(JsonField.ofNullable(subscription))
+
+ /** The subscription the alert applies to. */
+ fun subscription(subscription: Optional) =
+ subscription(subscription.orElse(null))
/** The subscription the alert applies to. */
fun subscription(subscription: JsonField) = apply {
@@ -227,11 +250,28 @@ private constructor(
}
/** The thresholds that define the conditions under which the alert will be triggered. */
- fun thresholds(thresholds: List) = thresholds(JsonField.of(thresholds))
+ fun thresholds(thresholds: List?) = thresholds(JsonField.ofNullable(thresholds))
+
+ /** The thresholds that define the conditions under which the alert will be triggered. */
+ fun thresholds(thresholds: Optional>) = thresholds(thresholds.orElse(null))
/** The thresholds that define the conditions under which the alert will be triggered. */
fun thresholds(thresholds: JsonField>) = apply {
- this.thresholds = thresholds
+ this.thresholds = thresholds.map { it.toMutableList() }
+ }
+
+ /** The thresholds that define the conditions under which the alert will be triggered. */
+ fun addThreshold(threshold: Threshold) = apply {
+ thresholds =
+ (thresholds ?: JsonField.of(mutableListOf())).apply {
+ asKnown()
+ .orElseThrow {
+ IllegalStateException(
+ "Field was set to non-list type: ${javaClass.simpleName}"
+ )
+ }
+ .add(threshold)
+ }
}
/** The type of alert. This must be a valid alert type. */
@@ -261,16 +301,17 @@ private constructor(
fun build(): Alert =
Alert(
- id,
- createdAt,
- currency,
- customer,
- enabled,
- metric,
- plan,
- subscription,
- thresholds.map { it.toImmutable() },
- type,
+ checkNotNull(id) { "`id` is required but was not set" },
+ checkNotNull(createdAt) { "`createdAt` is required but was not set" },
+ checkNotNull(currency) { "`currency` is required but was not set" },
+ checkNotNull(customer) { "`customer` is required but was not set" },
+ checkNotNull(enabled) { "`enabled` is required but was not set" },
+ checkNotNull(metric) { "`metric` is required but was not set" },
+ checkNotNull(plan) { "`plan` is required but was not set" },
+ checkNotNull(subscription) { "`subscription` is required but was not set" },
+ checkNotNull(thresholds) { "`thresholds` is required but was not set" }
+ .map { it.toImmutable() },
+ checkNotNull(type) { "`type` is required but was not set" },
additionalProperties.toImmutable(),
)
}
@@ -293,11 +334,11 @@ private constructor(
fun externalCustomerId(): Optional =
Optional.ofNullable(externalCustomerId.getNullable("external_customer_id"))
- @JsonProperty("id") @ExcludeMissing fun _id() = id
+ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id
@JsonProperty("external_customer_id")
@ExcludeMissing
- fun _externalCustomerId() = externalCustomerId
+ fun _externalCustomerId(): JsonField = externalCustomerId
@JsonAnyGetter
@ExcludeMissing
@@ -322,8 +363,8 @@ private constructor(
class Builder {
- private var id: JsonField = JsonMissing.of()
- private var externalCustomerId: JsonField = JsonMissing.of()
+ private var id: JsonField? = null
+ private var externalCustomerId: JsonField? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
@@ -337,8 +378,11 @@ private constructor(
fun id(id: JsonField) = apply { this.id = id }
- fun externalCustomerId(externalCustomerId: String) =
- externalCustomerId(JsonField.of(externalCustomerId))
+ fun externalCustomerId(externalCustomerId: String?) =
+ externalCustomerId(JsonField.ofNullable(externalCustomerId))
+
+ fun externalCustomerId(externalCustomerId: Optional) =
+ externalCustomerId(externalCustomerId.orElse(null))
fun externalCustomerId(externalCustomerId: JsonField) = apply {
this.externalCustomerId = externalCustomerId
@@ -365,8 +409,10 @@ private constructor(
fun build(): Customer =
Customer(
- id,
- externalCustomerId,
+ checkNotNull(id) { "`id` is required but was not set" },
+ checkNotNull(externalCustomerId) {
+ "`externalCustomerId` is required but was not set"
+ },
additionalProperties.toImmutable(),
)
}
@@ -401,7 +447,7 @@ private constructor(
fun id(): String = id.getRequired("id")
- @JsonProperty("id") @ExcludeMissing fun _id() = id
+ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id
@JsonAnyGetter
@ExcludeMissing
@@ -425,7 +471,7 @@ private constructor(
class Builder {
- private var id: JsonField = JsonMissing.of()
+ private var id: JsonField? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
@@ -457,7 +503,11 @@ private constructor(
keys.forEach(::removeAdditionalProperty)
}
- fun build(): Metric = Metric(id, additionalProperties.toImmutable())
+ fun build(): Metric =
+ Metric(
+ checkNotNull(id) { "`id` is required but was not set" },
+ additionalProperties.toImmutable()
+ )
}
override fun equals(other: Any?): Boolean {
@@ -510,18 +560,22 @@ private constructor(
fun planVersion(): String = planVersion.getRequired("plan_version")
- @JsonProperty("id") @ExcludeMissing fun _id() = id
+ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id
/**
* An optional user-defined ID for this plan resource, used throughout the system as an
* alias for this Plan. Use this field to identify a plan by an existing identifier in your
* system.
*/
- @JsonProperty("external_plan_id") @ExcludeMissing fun _externalPlanId() = externalPlanId
+ @JsonProperty("external_plan_id")
+ @ExcludeMissing
+ fun _externalPlanId(): JsonField = externalPlanId
- @JsonProperty("name") @ExcludeMissing fun _name() = name
+ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name
- @JsonProperty("plan_version") @ExcludeMissing fun _planVersion() = planVersion
+ @JsonProperty("plan_version")
+ @ExcludeMissing
+ fun _planVersion(): JsonField = planVersion
@JsonAnyGetter
@ExcludeMissing
@@ -548,10 +602,10 @@ private constructor(
class Builder {
- private var id: JsonField = JsonMissing.of()
- private var externalPlanId: JsonField = JsonMissing.of()
- private var name: JsonField = JsonMissing.of()
- private var planVersion: JsonField = JsonMissing.of()
+ private var id: JsonField? = null
+ private var externalPlanId: JsonField? = null
+ private var name: JsonField? = null
+ private var planVersion: JsonField? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
@@ -563,7 +617,9 @@ private constructor(
additionalProperties = plan.additionalProperties.toMutableMap()
}
- fun id(id: String) = id(JsonField.of(id))
+ fun id(id: String?) = id(JsonField.ofNullable(id))
+
+ fun id(id: Optional) = id(id.orElse(null))
fun id(id: JsonField) = apply { this.id = id }
@@ -572,8 +628,16 @@ private constructor(
* alias for this Plan. Use this field to identify a plan by an existing identifier in
* your system.
*/
- fun externalPlanId(externalPlanId: String) =
- externalPlanId(JsonField.of(externalPlanId))
+ fun externalPlanId(externalPlanId: String?) =
+ externalPlanId(JsonField.ofNullable(externalPlanId))
+
+ /**
+ * An optional user-defined ID for this plan resource, used throughout the system as an
+ * alias for this Plan. Use this field to identify a plan by an existing identifier in
+ * your system.
+ */
+ fun externalPlanId(externalPlanId: Optional) =
+ externalPlanId(externalPlanId.orElse(null))
/**
* An optional user-defined ID for this plan resource, used throughout the system as an
@@ -584,7 +648,9 @@ private constructor(
this.externalPlanId = externalPlanId
}
- fun name(name: String) = name(JsonField.of(name))
+ fun name(name: String?) = name(JsonField.ofNullable(name))
+
+ fun name(name: Optional) = name(name.orElse(null))
fun name(name: JsonField) = apply { this.name = name }
@@ -615,10 +681,10 @@ private constructor(
fun build(): Plan =
Plan(
- id,
- externalPlanId,
- name,
- planVersion,
+ checkNotNull(id) { "`id` is required but was not set" },
+ checkNotNull(externalPlanId) { "`externalPlanId` is required but was not set" },
+ checkNotNull(name) { "`name` is required but was not set" },
+ checkNotNull(planVersion) { "`planVersion` is required but was not set" },
additionalProperties.toImmutable(),
)
}
@@ -653,7 +719,7 @@ private constructor(
fun id(): String = id.getRequired("id")
- @JsonProperty("id") @ExcludeMissing fun _id() = id
+ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id
@JsonAnyGetter
@ExcludeMissing
@@ -677,7 +743,7 @@ private constructor(
class Builder {
- private var id: JsonField = JsonMissing.of()
+ private var id: JsonField? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
@@ -709,7 +775,11 @@ private constructor(
keys.forEach(::removeAdditionalProperty)
}
- fun build(): Subscription = Subscription(id, additionalProperties.toImmutable())
+ fun build(): Subscription =
+ Subscription(
+ checkNotNull(id) { "`id` is required but was not set" },
+ additionalProperties.toImmutable()
+ )
}
override fun equals(other: Any?): Boolean {
@@ -753,7 +823,7 @@ private constructor(
* or below this value. For usage and cost alerts, the alert will fire at or above this
* value.
*/
- @JsonProperty("value") @ExcludeMissing fun _value() = value
+ @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value
@JsonAnyGetter
@ExcludeMissing
@@ -777,7 +847,7 @@ private constructor(
class Builder {
- private var value: JsonField = JsonMissing.of()
+ private var value: JsonField? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
@@ -819,7 +889,11 @@ private constructor(
keys.forEach(::removeAdditionalProperty)
}
- fun build(): Threshold = Threshold(value, additionalProperties.toImmutable())
+ fun build(): Threshold =
+ Threshold(
+ checkNotNull(value) { "`value` is required but was not set" },
+ additionalProperties.toImmutable()
+ )
}
override fun equals(other: Any?): Boolean {
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForCustomerParams.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForCustomerParams.kt
index 1e152e87..1cac4a23 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForCustomerParams.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForCustomerParams.kt
@@ -9,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.withorb.api.core.Enum
import com.withorb.api.core.ExcludeMissing
import com.withorb.api.core.JsonField
+import com.withorb.api.core.JsonMissing
import com.withorb.api.core.JsonValue
import com.withorb.api.core.NoAutoDetect
import com.withorb.api.core.http.Headers
@@ -19,6 +20,14 @@ import com.withorb.api.errors.OrbInvalidDataException
import java.util.Objects
import java.util.Optional
+/**
+ * This endpoint creates a new alert to monitor a customer's credit balance. There are three types
+ * of alerts that can be scoped to customers: `credit_balance_depleted`, `credit_balance_dropped`,
+ * and `credit_balance_recovered`. Customers can have a maximum of one of each type of alert per
+ * [credit balance currency](https://docs.withorb.com/guides/product-catalog/prepurchase).
+ * `credit_balance_dropped` alerts require a list of thresholds to be provided while
+ * `credit_balance_depleted` and `credit_balance_recovered` alerts do not require thresholds.
+ */
class AlertCreateForCustomerParams
constructor(
private val customerId: String,
@@ -38,12 +47,21 @@ constructor(
/** The thresholds that define the values at which the alert will be triggered. */
fun thresholds(): Optional> = body.thresholds()
- fun _additionalHeaders(): Headers = additionalHeaders
+ /** The case sensitive currency or custom pricing unit to use for this alert. */
+ fun _currency(): JsonField = body._currency()
- fun _additionalQueryParams(): QueryParams = additionalQueryParams
+ /** The type of alert to create. This must be a valid alert type. */
+ fun _type(): JsonField = body._type()
+
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun _thresholds(): JsonField> = body._thresholds()
fun _additionalBodyProperties(): Map = body._additionalProperties()
+ fun _additionalHeaders(): Headers = additionalHeaders
+
+ fun _additionalQueryParams(): QueryParams = additionalQueryParams
+
@JvmSynthetic internal fun getBody(): AlertCreateForCustomerBody = body
@JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders
@@ -61,27 +79,53 @@ constructor(
class AlertCreateForCustomerBody
@JsonCreator
internal constructor(
- @JsonProperty("currency") private val currency: String,
- @JsonProperty("type") private val type: Type,
- @JsonProperty("thresholds") private val thresholds: List?,
+ @JsonProperty("currency")
+ @ExcludeMissing
+ private val currency: JsonField = JsonMissing.of(),
+ @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(),
+ @JsonProperty("thresholds")
+ @ExcludeMissing
+ private val thresholds: JsonField> = JsonMissing.of(),
@JsonAnySetter
private val additionalProperties: Map = immutableEmptyMap(),
) {
/** The case sensitive currency or custom pricing unit to use for this alert. */
- @JsonProperty("currency") fun currency(): String = currency
+ fun currency(): String = currency.getRequired("currency")
+
+ /** The type of alert to create. This must be a valid alert type. */
+ fun type(): Type = type.getRequired("type")
+
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun thresholds(): Optional> =
+ Optional.ofNullable(thresholds.getNullable("thresholds"))
+
+ /** The case sensitive currency or custom pricing unit to use for this alert. */
+ @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency
/** The type of alert to create. This must be a valid alert type. */
- @JsonProperty("type") fun type(): Type = type
+ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type
/** The thresholds that define the values at which the alert will be triggered. */
@JsonProperty("thresholds")
- fun thresholds(): Optional> = Optional.ofNullable(thresholds)
+ @ExcludeMissing
+ fun _thresholds(): JsonField> = thresholds
@JsonAnyGetter
@ExcludeMissing
fun _additionalProperties(): Map = additionalProperties
+ private var validated: Boolean = false
+
+ fun validate(): AlertCreateForCustomerBody = apply {
+ if (!validated) {
+ currency()
+ type()
+ thresholds().map { it.forEach { it.validate() } }
+ validated = true
+ }
+ }
+
fun toBuilder() = Builder().from(this)
companion object {
@@ -91,38 +135,57 @@ constructor(
class Builder {
- private var currency: String? = null
- private var type: Type? = null
- private var thresholds: MutableList? = null
+ private var currency: JsonField? = null
+ private var type: JsonField? = null
+ private var thresholds: JsonField>? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
internal fun from(alertCreateForCustomerBody: AlertCreateForCustomerBody) = apply {
currency = alertCreateForCustomerBody.currency
type = alertCreateForCustomerBody.type
- thresholds = alertCreateForCustomerBody.thresholds?.toMutableList()
+ thresholds = alertCreateForCustomerBody.thresholds.map { it.toMutableList() }
additionalProperties =
alertCreateForCustomerBody.additionalProperties.toMutableMap()
}
/** The case sensitive currency or custom pricing unit to use for this alert. */
- fun currency(currency: String) = apply { this.currency = currency }
+ fun currency(currency: String) = currency(JsonField.of(currency))
+
+ /** The case sensitive currency or custom pricing unit to use for this alert. */
+ fun currency(currency: JsonField) = apply { this.currency = currency }
+
+ /** The type of alert to create. This must be a valid alert type. */
+ fun type(type: Type) = type(JsonField.of(type))
/** The type of alert to create. This must be a valid alert type. */
- fun type(type: Type) = apply { this.type = type }
+ fun type(type: JsonField) = apply { this.type = type }
/** The thresholds that define the values at which the alert will be triggered. */
- fun thresholds(thresholds: List?) = apply {
- this.thresholds = thresholds?.toMutableList()
- }
+ fun thresholds(thresholds: List?) =
+ thresholds(JsonField.ofNullable(thresholds))
/** The thresholds that define the values at which the alert will be triggered. */
fun thresholds(thresholds: Optional>) =
thresholds(thresholds.orElse(null))
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun thresholds(thresholds: JsonField>) = apply {
+ this.thresholds = thresholds.map { it.toMutableList() }
+ }
+
/** The thresholds that define the values at which the alert will be triggered. */
fun addThreshold(threshold: Threshold) = apply {
- thresholds = (thresholds ?: mutableListOf()).apply { add(threshold) }
+ thresholds =
+ (thresholds ?: JsonField.of(mutableListOf())).apply {
+ asKnown()
+ .orElseThrow {
+ IllegalStateException(
+ "Field was set to non-list type: ${javaClass.simpleName}"
+ )
+ }
+ .add(threshold)
+ }
}
fun additionalProperties(additionalProperties: Map) = apply {
@@ -148,7 +211,7 @@ constructor(
AlertCreateForCustomerBody(
checkNotNull(currency) { "`currency` is required but was not set" },
checkNotNull(type) { "`type` is required but was not set" },
- thresholds?.toImmutable(),
+ (thresholds ?: JsonMissing.of()).map { it.toImmutable() },
additionalProperties.toImmutable(),
)
}
@@ -199,18 +262,48 @@ constructor(
/** The case sensitive currency or custom pricing unit to use for this alert. */
fun currency(currency: String) = apply { body.currency(currency) }
+ /** The case sensitive currency or custom pricing unit to use for this alert. */
+ fun currency(currency: JsonField) = apply { body.currency(currency) }
+
/** The type of alert to create. This must be a valid alert type. */
fun type(type: Type) = apply { body.type(type) }
+ /** The type of alert to create. This must be a valid alert type. */
+ fun type(type: JsonField) = apply { body.type(type) }
+
/** The thresholds that define the values at which the alert will be triggered. */
fun thresholds(thresholds: List?) = apply { body.thresholds(thresholds) }
/** The thresholds that define the values at which the alert will be triggered. */
fun thresholds(thresholds: Optional>) = thresholds(thresholds.orElse(null))
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun thresholds(thresholds: JsonField>) = apply {
+ body.thresholds(thresholds)
+ }
+
/** The thresholds that define the values at which the alert will be triggered. */
fun addThreshold(threshold: Threshold) = apply { body.addThreshold(threshold) }
+ fun additionalBodyProperties(additionalBodyProperties: Map) = apply {
+ body.additionalProperties(additionalBodyProperties)
+ }
+
+ fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
+ body.putAdditionalProperty(key, value)
+ }
+
+ fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) =
+ apply {
+ body.putAllAdditionalProperties(additionalBodyProperties)
+ }
+
+ fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) }
+
+ fun removeAllAdditionalBodyProperties(keys: Set) = apply {
+ body.removeAllAdditionalProperties(keys)
+ }
+
fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
putAllAdditionalHeaders(additionalHeaders)
@@ -309,25 +402,6 @@ constructor(
additionalQueryParams.removeAll(keys)
}
- fun additionalBodyProperties(additionalBodyProperties: Map) = apply {
- body.additionalProperties(additionalBodyProperties)
- }
-
- fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
- body.putAdditionalProperty(key, value)
- }
-
- fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) =
- apply {
- body.putAllAdditionalProperties(additionalBodyProperties)
- }
-
- fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) }
-
- fun removeAllAdditionalBodyProperties(keys: Set) = apply {
- body.removeAllAdditionalProperties(keys)
- }
-
fun build(): AlertCreateForCustomerParams =
AlertCreateForCustomerParams(
checkNotNull(customerId) { "`customerId` is required but was not set" },
@@ -417,7 +491,9 @@ constructor(
class Threshold
@JsonCreator
private constructor(
- @JsonProperty("value") private val value: Double,
+ @JsonProperty("value")
+ @ExcludeMissing
+ private val value: JsonField = JsonMissing.of(),
@JsonAnySetter
private val additionalProperties: Map = immutableEmptyMap(),
) {
@@ -427,12 +503,28 @@ constructor(
* or below this value. For usage and cost alerts, the alert will fire at or above this
* value.
*/
- @JsonProperty("value") fun value(): Double = value
+ fun value(): Double = value.getRequired("value")
+
+ /**
+ * The value at which an alert will fire. For credit balance alerts, the alert will fire at
+ * or below this value. For usage and cost alerts, the alert will fire at or above this
+ * value.
+ */
+ @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value
@JsonAnyGetter
@ExcludeMissing
fun _additionalProperties(): Map = additionalProperties
+ private var validated: Boolean = false
+
+ fun validate(): Threshold = apply {
+ if (!validated) {
+ value()
+ validated = true
+ }
+ }
+
fun toBuilder() = Builder().from(this)
companion object {
@@ -442,7 +534,7 @@ constructor(
class Builder {
- private var value: Double? = null
+ private var value: JsonField? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
@@ -456,7 +548,14 @@ constructor(
* at or below this value. For usage and cost alerts, the alert will fire at or above
* this value.
*/
- fun value(value: Double) = apply { this.value = value }
+ fun value(value: Double) = value(JsonField.of(value))
+
+ /**
+ * The value at which an alert will fire. For credit balance alerts, the alert will fire
+ * at or below this value. For usage and cost alerts, the alert will fire at or above
+ * this value.
+ */
+ fun value(value: JsonField) = apply { this.value = value }
fun additionalProperties(additionalProperties: Map) = apply {
this.additionalProperties.clear()
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForExternalCustomerParams.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForExternalCustomerParams.kt
index 5c144763..37f68a25 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForExternalCustomerParams.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForExternalCustomerParams.kt
@@ -9,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.withorb.api.core.Enum
import com.withorb.api.core.ExcludeMissing
import com.withorb.api.core.JsonField
+import com.withorb.api.core.JsonMissing
import com.withorb.api.core.JsonValue
import com.withorb.api.core.NoAutoDetect
import com.withorb.api.core.http.Headers
@@ -19,6 +20,14 @@ import com.withorb.api.errors.OrbInvalidDataException
import java.util.Objects
import java.util.Optional
+/**
+ * This endpoint creates a new alert to monitor a customer's credit balance. There are three types
+ * of alerts that can be scoped to customers: `credit_balance_depleted`, `credit_balance_dropped`,
+ * and `credit_balance_recovered`. Customers can have a maximum of one of each type of alert per
+ * [credit balance currency](https://docs.withorb.com/guides/product-catalog/prepurchase).
+ * `credit_balance_dropped` alerts require a list of thresholds to be provided while
+ * `credit_balance_depleted` and `credit_balance_recovered` alerts do not require thresholds.
+ */
class AlertCreateForExternalCustomerParams
constructor(
private val externalCustomerId: String,
@@ -38,12 +47,21 @@ constructor(
/** The thresholds that define the values at which the alert will be triggered. */
fun thresholds(): Optional> = body.thresholds()
- fun _additionalHeaders(): Headers = additionalHeaders
+ /** The case sensitive currency or custom pricing unit to use for this alert. */
+ fun _currency(): JsonField = body._currency()
- fun _additionalQueryParams(): QueryParams = additionalQueryParams
+ /** The type of alert to create. This must be a valid alert type. */
+ fun _type(): JsonField = body._type()
+
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun _thresholds(): JsonField> = body._thresholds()
fun _additionalBodyProperties(): Map = body._additionalProperties()
+ fun _additionalHeaders(): Headers = additionalHeaders
+
+ fun _additionalQueryParams(): QueryParams = additionalQueryParams
+
@JvmSynthetic internal fun getBody(): AlertCreateForExternalCustomerBody = body
@JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders
@@ -61,27 +79,53 @@ constructor(
class AlertCreateForExternalCustomerBody
@JsonCreator
internal constructor(
- @JsonProperty("currency") private val currency: String,
- @JsonProperty("type") private val type: Type,
- @JsonProperty("thresholds") private val thresholds: List?,
+ @JsonProperty("currency")
+ @ExcludeMissing
+ private val currency: JsonField = JsonMissing.of(),
+ @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(),
+ @JsonProperty("thresholds")
+ @ExcludeMissing
+ private val thresholds: JsonField> = JsonMissing.of(),
@JsonAnySetter
private val additionalProperties: Map = immutableEmptyMap(),
) {
/** The case sensitive currency or custom pricing unit to use for this alert. */
- @JsonProperty("currency") fun currency(): String = currency
+ fun currency(): String = currency.getRequired("currency")
+
+ /** The type of alert to create. This must be a valid alert type. */
+ fun type(): Type = type.getRequired("type")
+
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun thresholds(): Optional> =
+ Optional.ofNullable(thresholds.getNullable("thresholds"))
+
+ /** The case sensitive currency or custom pricing unit to use for this alert. */
+ @JsonProperty("currency") @ExcludeMissing fun _currency(): JsonField = currency
/** The type of alert to create. This must be a valid alert type. */
- @JsonProperty("type") fun type(): Type = type
+ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type
/** The thresholds that define the values at which the alert will be triggered. */
@JsonProperty("thresholds")
- fun thresholds(): Optional> = Optional.ofNullable(thresholds)
+ @ExcludeMissing
+ fun _thresholds(): JsonField> = thresholds
@JsonAnyGetter
@ExcludeMissing
fun _additionalProperties(): Map = additionalProperties
+ private var validated: Boolean = false
+
+ fun validate(): AlertCreateForExternalCustomerBody = apply {
+ if (!validated) {
+ currency()
+ type()
+ thresholds().map { it.forEach { it.validate() } }
+ validated = true
+ }
+ }
+
fun toBuilder() = Builder().from(this)
companion object {
@@ -91,9 +135,9 @@ constructor(
class Builder {
- private var currency: String? = null
- private var type: Type? = null
- private var thresholds: MutableList? = null
+ private var currency: JsonField? = null
+ private var type: JsonField? = null
+ private var thresholds: JsonField>? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
@@ -102,29 +146,49 @@ constructor(
) = apply {
currency = alertCreateForExternalCustomerBody.currency
type = alertCreateForExternalCustomerBody.type
- thresholds = alertCreateForExternalCustomerBody.thresholds?.toMutableList()
+ thresholds =
+ alertCreateForExternalCustomerBody.thresholds.map { it.toMutableList() }
additionalProperties =
alertCreateForExternalCustomerBody.additionalProperties.toMutableMap()
}
/** The case sensitive currency or custom pricing unit to use for this alert. */
- fun currency(currency: String) = apply { this.currency = currency }
+ fun currency(currency: String) = currency(JsonField.of(currency))
+
+ /** The case sensitive currency or custom pricing unit to use for this alert. */
+ fun currency(currency: JsonField) = apply { this.currency = currency }
+
+ /** The type of alert to create. This must be a valid alert type. */
+ fun type(type: Type) = type(JsonField.of(type))
/** The type of alert to create. This must be a valid alert type. */
- fun type(type: Type) = apply { this.type = type }
+ fun type(type: JsonField) = apply { this.type = type }
/** The thresholds that define the values at which the alert will be triggered. */
- fun thresholds(thresholds: List?) = apply {
- this.thresholds = thresholds?.toMutableList()
- }
+ fun thresholds(thresholds: List?) =
+ thresholds(JsonField.ofNullable(thresholds))
/** The thresholds that define the values at which the alert will be triggered. */
fun thresholds(thresholds: Optional>) =
thresholds(thresholds.orElse(null))
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun thresholds(thresholds: JsonField>) = apply {
+ this.thresholds = thresholds.map { it.toMutableList() }
+ }
+
/** The thresholds that define the values at which the alert will be triggered. */
fun addThreshold(threshold: Threshold) = apply {
- thresholds = (thresholds ?: mutableListOf()).apply { add(threshold) }
+ thresholds =
+ (thresholds ?: JsonField.of(mutableListOf())).apply {
+ asKnown()
+ .orElseThrow {
+ IllegalStateException(
+ "Field was set to non-list type: ${javaClass.simpleName}"
+ )
+ }
+ .add(threshold)
+ }
}
fun additionalProperties(additionalProperties: Map) = apply {
@@ -150,7 +214,7 @@ constructor(
AlertCreateForExternalCustomerBody(
checkNotNull(currency) { "`currency` is required but was not set" },
checkNotNull(type) { "`type` is required but was not set" },
- thresholds?.toImmutable(),
+ (thresholds ?: JsonMissing.of()).map { it.toImmutable() },
additionalProperties.toImmutable(),
)
}
@@ -207,18 +271,48 @@ constructor(
/** The case sensitive currency or custom pricing unit to use for this alert. */
fun currency(currency: String) = apply { body.currency(currency) }
+ /** The case sensitive currency or custom pricing unit to use for this alert. */
+ fun currency(currency: JsonField) = apply { body.currency(currency) }
+
/** The type of alert to create. This must be a valid alert type. */
fun type(type: Type) = apply { body.type(type) }
+ /** The type of alert to create. This must be a valid alert type. */
+ fun type(type: JsonField) = apply { body.type(type) }
+
/** The thresholds that define the values at which the alert will be triggered. */
fun thresholds(thresholds: List?) = apply { body.thresholds(thresholds) }
/** The thresholds that define the values at which the alert will be triggered. */
fun thresholds(thresholds: Optional>) = thresholds(thresholds.orElse(null))
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun thresholds(thresholds: JsonField>) = apply {
+ body.thresholds(thresholds)
+ }
+
/** The thresholds that define the values at which the alert will be triggered. */
fun addThreshold(threshold: Threshold) = apply { body.addThreshold(threshold) }
+ fun additionalBodyProperties(additionalBodyProperties: Map) = apply {
+ body.additionalProperties(additionalBodyProperties)
+ }
+
+ fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
+ body.putAdditionalProperty(key, value)
+ }
+
+ fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) =
+ apply {
+ body.putAllAdditionalProperties(additionalBodyProperties)
+ }
+
+ fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) }
+
+ fun removeAllAdditionalBodyProperties(keys: Set) = apply {
+ body.removeAllAdditionalProperties(keys)
+ }
+
fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
putAllAdditionalHeaders(additionalHeaders)
@@ -317,25 +411,6 @@ constructor(
additionalQueryParams.removeAll(keys)
}
- fun additionalBodyProperties(additionalBodyProperties: Map) = apply {
- body.additionalProperties(additionalBodyProperties)
- }
-
- fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
- body.putAdditionalProperty(key, value)
- }
-
- fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) =
- apply {
- body.putAllAdditionalProperties(additionalBodyProperties)
- }
-
- fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) }
-
- fun removeAllAdditionalBodyProperties(keys: Set) = apply {
- body.removeAllAdditionalProperties(keys)
- }
-
fun build(): AlertCreateForExternalCustomerParams =
AlertCreateForExternalCustomerParams(
checkNotNull(externalCustomerId) {
@@ -427,7 +502,9 @@ constructor(
class Threshold
@JsonCreator
private constructor(
- @JsonProperty("value") private val value: Double,
+ @JsonProperty("value")
+ @ExcludeMissing
+ private val value: JsonField = JsonMissing.of(),
@JsonAnySetter
private val additionalProperties: Map = immutableEmptyMap(),
) {
@@ -437,12 +514,28 @@ constructor(
* or below this value. For usage and cost alerts, the alert will fire at or above this
* value.
*/
- @JsonProperty("value") fun value(): Double = value
+ fun value(): Double = value.getRequired("value")
+
+ /**
+ * The value at which an alert will fire. For credit balance alerts, the alert will fire at
+ * or below this value. For usage and cost alerts, the alert will fire at or above this
+ * value.
+ */
+ @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value
@JsonAnyGetter
@ExcludeMissing
fun _additionalProperties(): Map = additionalProperties
+ private var validated: Boolean = false
+
+ fun validate(): Threshold = apply {
+ if (!validated) {
+ value()
+ validated = true
+ }
+ }
+
fun toBuilder() = Builder().from(this)
companion object {
@@ -452,7 +545,7 @@ constructor(
class Builder {
- private var value: Double? = null
+ private var value: JsonField? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
@@ -466,7 +559,14 @@ constructor(
* at or below this value. For usage and cost alerts, the alert will fire at or above
* this value.
*/
- fun value(value: Double) = apply { this.value = value }
+ fun value(value: Double) = value(JsonField.of(value))
+
+ /**
+ * The value at which an alert will fire. For credit balance alerts, the alert will fire
+ * at or below this value. For usage and cost alerts, the alert will fire at or above
+ * this value.
+ */
+ fun value(value: JsonField) = apply { this.value = value }
fun additionalProperties(additionalProperties: Map) = apply {
this.additionalProperties.clear()
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForSubscriptionParams.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForSubscriptionParams.kt
index daa10ea4..373e5d47 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForSubscriptionParams.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForSubscriptionParams.kt
@@ -9,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.withorb.api.core.Enum
import com.withorb.api.core.ExcludeMissing
import com.withorb.api.core.JsonField
+import com.withorb.api.core.JsonMissing
import com.withorb.api.core.JsonValue
import com.withorb.api.core.NoAutoDetect
import com.withorb.api.core.http.Headers
@@ -19,6 +20,18 @@ import com.withorb.api.errors.OrbInvalidDataException
import java.util.Objects
import java.util.Optional
+/**
+ * This endpoint is used to create alerts at the subscription level.
+ *
+ * Subscription level alerts can be one of two types: `usage_exceeded` or `cost_exceeded`. A
+ * `usage_exceeded` alert is scoped to a particular metric and is triggered when the usage of that
+ * metric exceeds predefined thresholds during the current billing cycle. A `cost_exceeded` alert is
+ * triggered when the total amount due during the current billing cycle surpasses predefined
+ * thresholds. `cost_exceeded` alerts do not include burndown of pre-purchase credits. Each
+ * subscription can have one `cost_exceeded` alert and one `usage_exceeded` alert per metric that is
+ * a part of the subscription. Alerts are triggered based on usage or cost conditions met during the
+ * current billing cycle.
+ */
class AlertCreateForSubscriptionParams
constructor(
private val subscriptionId: String,
@@ -38,12 +51,21 @@ constructor(
/** The metric to track usage for. */
fun metricId(): Optional = body.metricId()
- fun _additionalHeaders(): Headers = additionalHeaders
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun _thresholds(): JsonField> = body._thresholds()
- fun _additionalQueryParams(): QueryParams = additionalQueryParams
+ /** The type of alert to create. This must be a valid alert type. */
+ fun _type(): JsonField = body._type()
+
+ /** The metric to track usage for. */
+ fun _metricId(): JsonField = body._metricId()
fun _additionalBodyProperties(): Map = body._additionalProperties()
+ fun _additionalHeaders(): Headers = additionalHeaders
+
+ fun _additionalQueryParams(): QueryParams = additionalQueryParams
+
@JvmSynthetic internal fun getBody(): AlertCreateForSubscriptionBody = body
@JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders
@@ -61,26 +83,52 @@ constructor(
class AlertCreateForSubscriptionBody
@JsonCreator
internal constructor(
- @JsonProperty("thresholds") private val thresholds: List,
- @JsonProperty("type") private val type: Type,
- @JsonProperty("metric_id") private val metricId: String?,
+ @JsonProperty("thresholds")
+ @ExcludeMissing
+ private val thresholds: JsonField> = JsonMissing.of(),
+ @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(),
+ @JsonProperty("metric_id")
+ @ExcludeMissing
+ private val metricId: JsonField = JsonMissing.of(),
@JsonAnySetter
private val additionalProperties: Map = immutableEmptyMap(),
) {
/** The thresholds that define the values at which the alert will be triggered. */
- @JsonProperty("thresholds") fun thresholds(): List = thresholds
+ fun thresholds(): List = thresholds.getRequired("thresholds")
/** The type of alert to create. This must be a valid alert type. */
- @JsonProperty("type") fun type(): Type = type
+ fun type(): Type = type.getRequired("type")
/** The metric to track usage for. */
- @JsonProperty("metric_id") fun metricId(): Optional = Optional.ofNullable(metricId)
+ fun metricId(): Optional = Optional.ofNullable(metricId.getNullable("metric_id"))
+
+ /** The thresholds that define the values at which the alert will be triggered. */
+ @JsonProperty("thresholds")
+ @ExcludeMissing
+ fun _thresholds(): JsonField> = thresholds
+
+ /** The type of alert to create. This must be a valid alert type. */
+ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type
+
+ /** The metric to track usage for. */
+ @JsonProperty("metric_id") @ExcludeMissing fun _metricId(): JsonField = metricId
@JsonAnyGetter
@ExcludeMissing
fun _additionalProperties(): Map = additionalProperties
+ private var validated: Boolean = false
+
+ fun validate(): AlertCreateForSubscriptionBody = apply {
+ if (!validated) {
+ thresholds().forEach { it.validate() }
+ type()
+ metricId()
+ validated = true
+ }
+ }
+
fun toBuilder() = Builder().from(this)
companion object {
@@ -90,15 +138,16 @@ constructor(
class Builder {
- private var thresholds: MutableList? = null
- private var type: Type? = null
- private var metricId: String? = null
+ private var thresholds: JsonField>? = null
+ private var type: JsonField? = null
+ private var metricId: JsonField = JsonMissing.of()
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
internal fun from(alertCreateForSubscriptionBody: AlertCreateForSubscriptionBody) =
apply {
- thresholds = alertCreateForSubscriptionBody.thresholds.toMutableList()
+ thresholds =
+ alertCreateForSubscriptionBody.thresholds.map { it.toMutableList() }
type = alertCreateForSubscriptionBody.type
metricId = alertCreateForSubscriptionBody.metricId
additionalProperties =
@@ -106,24 +155,42 @@ constructor(
}
/** The thresholds that define the values at which the alert will be triggered. */
- fun thresholds(thresholds: List) = apply {
- this.thresholds = thresholds.toMutableList()
+ fun thresholds(thresholds: List) = thresholds(JsonField.of(thresholds))
+
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun thresholds(thresholds: JsonField>) = apply {
+ this.thresholds = thresholds.map { it.toMutableList() }
}
/** The thresholds that define the values at which the alert will be triggered. */
fun addThreshold(threshold: Threshold) = apply {
- thresholds = (thresholds ?: mutableListOf()).apply { add(threshold) }
+ thresholds =
+ (thresholds ?: JsonField.of(mutableListOf())).apply {
+ asKnown()
+ .orElseThrow {
+ IllegalStateException(
+ "Field was set to non-list type: ${javaClass.simpleName}"
+ )
+ }
+ .add(threshold)
+ }
}
/** The type of alert to create. This must be a valid alert type. */
- fun type(type: Type) = apply { this.type = type }
+ fun type(type: Type) = type(JsonField.of(type))
+
+ /** The type of alert to create. This must be a valid alert type. */
+ fun type(type: JsonField) = apply { this.type = type }
/** The metric to track usage for. */
- fun metricId(metricId: String?) = apply { this.metricId = metricId }
+ fun metricId(metricId: String?) = metricId(JsonField.ofNullable(metricId))
/** The metric to track usage for. */
fun metricId(metricId: Optional) = metricId(metricId.orElse(null))
+ /** The metric to track usage for. */
+ fun metricId(metricId: JsonField) = apply { this.metricId = metricId }
+
fun additionalProperties(additionalProperties: Map) = apply {
this.additionalProperties.clear()
putAllAdditionalProperties(additionalProperties)
@@ -146,7 +213,7 @@ constructor(
fun build(): AlertCreateForSubscriptionBody =
AlertCreateForSubscriptionBody(
checkNotNull(thresholds) { "`thresholds` is required but was not set" }
- .toImmutable(),
+ .map { it.toImmutable() },
checkNotNull(type) { "`type` is required but was not set" },
metricId,
additionalProperties.toImmutable(),
@@ -202,18 +269,48 @@ constructor(
/** The thresholds that define the values at which the alert will be triggered. */
fun thresholds(thresholds: List) = apply { body.thresholds(thresholds) }
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun thresholds(thresholds: JsonField>) = apply {
+ body.thresholds(thresholds)
+ }
+
/** The thresholds that define the values at which the alert will be triggered. */
fun addThreshold(threshold: Threshold) = apply { body.addThreshold(threshold) }
/** The type of alert to create. This must be a valid alert type. */
fun type(type: Type) = apply { body.type(type) }
+ /** The type of alert to create. This must be a valid alert type. */
+ fun type(type: JsonField) = apply { body.type(type) }
+
/** The metric to track usage for. */
fun metricId(metricId: String?) = apply { body.metricId(metricId) }
/** The metric to track usage for. */
fun metricId(metricId: Optional) = metricId(metricId.orElse(null))
+ /** The metric to track usage for. */
+ fun metricId(metricId: JsonField) = apply { body.metricId(metricId) }
+
+ fun additionalBodyProperties(additionalBodyProperties: Map) = apply {
+ body.additionalProperties(additionalBodyProperties)
+ }
+
+ fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
+ body.putAdditionalProperty(key, value)
+ }
+
+ fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) =
+ apply {
+ body.putAllAdditionalProperties(additionalBodyProperties)
+ }
+
+ fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) }
+
+ fun removeAllAdditionalBodyProperties(keys: Set) = apply {
+ body.removeAllAdditionalProperties(keys)
+ }
+
fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
putAllAdditionalHeaders(additionalHeaders)
@@ -312,25 +409,6 @@ constructor(
additionalQueryParams.removeAll(keys)
}
- fun additionalBodyProperties(additionalBodyProperties: Map) = apply {
- body.additionalProperties(additionalBodyProperties)
- }
-
- fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
- body.putAdditionalProperty(key, value)
- }
-
- fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) =
- apply {
- body.putAllAdditionalProperties(additionalBodyProperties)
- }
-
- fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) }
-
- fun removeAllAdditionalBodyProperties(keys: Set) = apply {
- body.removeAllAdditionalProperties(keys)
- }
-
fun build(): AlertCreateForSubscriptionParams =
AlertCreateForSubscriptionParams(
checkNotNull(subscriptionId) { "`subscriptionId` is required but was not set" },
@@ -345,7 +423,9 @@ constructor(
class Threshold
@JsonCreator
private constructor(
- @JsonProperty("value") private val value: Double,
+ @JsonProperty("value")
+ @ExcludeMissing
+ private val value: JsonField = JsonMissing.of(),
@JsonAnySetter
private val additionalProperties: Map = immutableEmptyMap(),
) {
@@ -355,12 +435,28 @@ constructor(
* or below this value. For usage and cost alerts, the alert will fire at or above this
* value.
*/
- @JsonProperty("value") fun value(): Double = value
+ fun value(): Double = value.getRequired("value")
+
+ /**
+ * The value at which an alert will fire. For credit balance alerts, the alert will fire at
+ * or below this value. For usage and cost alerts, the alert will fire at or above this
+ * value.
+ */
+ @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value
@JsonAnyGetter
@ExcludeMissing
fun _additionalProperties(): Map = additionalProperties
+ private var validated: Boolean = false
+
+ fun validate(): Threshold = apply {
+ if (!validated) {
+ value()
+ validated = true
+ }
+ }
+
fun toBuilder() = Builder().from(this)
companion object {
@@ -370,7 +466,7 @@ constructor(
class Builder {
- private var value: Double? = null
+ private var value: JsonField? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
@@ -384,7 +480,14 @@ constructor(
* at or below this value. For usage and cost alerts, the alert will fire at or above
* this value.
*/
- fun value(value: Double) = apply { this.value = value }
+ fun value(value: Double) = value(JsonField.of(value))
+
+ /**
+ * The value at which an alert will fire. For credit balance alerts, the alert will fire
+ * at or below this value. For usage and cost alerts, the alert will fire at or above
+ * this value.
+ */
+ fun value(value: JsonField) = apply { this.value = value }
fun additionalProperties(additionalProperties: Map) = apply {
this.additionalProperties.clear()
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertDisableParams.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertDisableParams.kt
index bbe95c43..80085dd8 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertDisableParams.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertDisableParams.kt
@@ -10,6 +10,11 @@ import com.withorb.api.core.toImmutable
import java.util.Objects
import java.util.Optional
+/**
+ * This endpoint allows you to disable an alert. To disable a plan-level alert for a specific
+ * subscription, you must include the `subscription_id`. The `subscription_id` is not required for
+ * customer or subscription level alerts.
+ */
class AlertDisableParams
constructor(
private val alertConfigurationId: String,
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertEnableParams.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertEnableParams.kt
index 2a91ab5b..fa7e1205 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertEnableParams.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertEnableParams.kt
@@ -10,6 +10,11 @@ import com.withorb.api.core.toImmutable
import java.util.Objects
import java.util.Optional
+/**
+ * This endpoint allows you to enable an alert. To enable a plan-level alert for a specific
+ * subscription, you must include the `subscription_id`. The `subscription_id` is not required for
+ * customer or subscription level alerts.
+ */
class AlertEnableParams
constructor(
private val alertConfigurationId: String,
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListParams.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListParams.kt
index 19de6751..2d10e511 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListParams.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListParams.kt
@@ -10,6 +10,17 @@ import java.time.format.DateTimeFormatter
import java.util.Objects
import java.util.Optional
+/**
+ * This endpoint returns a list of alerts within Orb.
+ *
+ * The request must specify one of `customer_id`, `external_customer_id`, or `subscription_id`.
+ *
+ * If querying by subscripion_id, the endpoint will return the subscription level alerts as well as
+ * the plan level alerts associated with the subscription.
+ *
+ * The list of alerts is ordered starting from the most recently created alert. This endpoint
+ * follows Orb's [standardized pagination format](../reference/pagination).
+ */
class AlertListParams
constructor(
private val createdAtGt: OffsetDateTime?,
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertRetrieveParams.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertRetrieveParams.kt
index 24bbd18a..f81abfaf 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertRetrieveParams.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertRetrieveParams.kt
@@ -7,6 +7,7 @@ import com.withorb.api.core.http.Headers
import com.withorb.api.core.http.QueryParams
import java.util.Objects
+/** This endpoint retrieves an alert by its ID. */
class AlertRetrieveParams
constructor(
private val alertId: String,
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertUpdateParams.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertUpdateParams.kt
index 4ae8de06..cf14aeed 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertUpdateParams.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertUpdateParams.kt
@@ -7,6 +7,8 @@ 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.NoAutoDetect
import com.withorb.api.core.http.Headers
@@ -15,6 +17,7 @@ import com.withorb.api.core.immutableEmptyMap
import com.withorb.api.core.toImmutable
import java.util.Objects
+/** This endpoint updates the thresholds of an alert. */
class AlertUpdateParams
constructor(
private val alertConfigurationId: String,
@@ -28,12 +31,15 @@ constructor(
/** The thresholds that define the values at which the alert will be triggered. */
fun thresholds(): List = body.thresholds()
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun _thresholds(): JsonField> = body._thresholds()
+
+ fun _additionalBodyProperties(): Map = body._additionalProperties()
+
fun _additionalHeaders(): Headers = additionalHeaders
fun _additionalQueryParams(): QueryParams = additionalQueryParams
- fun _additionalBodyProperties(): Map = body._additionalProperties()
-
@JvmSynthetic internal fun getBody(): AlertUpdateBody = body
@JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders
@@ -51,18 +57,34 @@ constructor(
class AlertUpdateBody
@JsonCreator
internal constructor(
- @JsonProperty("thresholds") private val thresholds: List,
+ @JsonProperty("thresholds")
+ @ExcludeMissing
+ private val thresholds: JsonField> = JsonMissing.of(),
@JsonAnySetter
private val additionalProperties: Map = immutableEmptyMap(),
) {
/** The thresholds that define the values at which the alert will be triggered. */
- @JsonProperty("thresholds") fun thresholds(): List = thresholds
+ fun thresholds(): List = thresholds.getRequired("thresholds")
+
+ /** The thresholds that define the values at which the alert will be triggered. */
+ @JsonProperty("thresholds")
+ @ExcludeMissing
+ fun _thresholds(): JsonField> = thresholds
@JsonAnyGetter
@ExcludeMissing
fun _additionalProperties(): Map = additionalProperties
+ private var validated: Boolean = false
+
+ fun validate(): AlertUpdateBody = apply {
+ if (!validated) {
+ thresholds().forEach { it.validate() }
+ validated = true
+ }
+ }
+
fun toBuilder() = Builder().from(this)
companion object {
@@ -72,23 +94,35 @@ constructor(
class Builder {
- private var thresholds: MutableList? = null
+ private var thresholds: JsonField>? = null
private var additionalProperties: MutableMap = mutableMapOf()
@JvmSynthetic
internal fun from(alertUpdateBody: AlertUpdateBody) = apply {
- thresholds = alertUpdateBody.thresholds.toMutableList()
+ thresholds = alertUpdateBody.thresholds.map { it.toMutableList() }
additionalProperties = alertUpdateBody.additionalProperties.toMutableMap()
}
/** The thresholds that define the values at which the alert will be triggered. */
- fun thresholds(thresholds: List) = apply {
- this.thresholds = thresholds.toMutableList()
+ fun thresholds(thresholds: List) = thresholds(JsonField.of(thresholds))
+
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun thresholds(thresholds: JsonField>) = apply {
+ this.thresholds = thresholds.map { it.toMutableList() }
}
/** The thresholds that define the values at which the alert will be triggered. */
fun addThreshold(threshold: Threshold) = apply {
- thresholds = (thresholds ?: mutableListOf()).apply { add(threshold) }
+ thresholds =
+ (thresholds ?: JsonField.of(mutableListOf())).apply {
+ asKnown()
+ .orElseThrow {
+ IllegalStateException(
+ "Field was set to non-list type: ${javaClass.simpleName}"
+ )
+ }
+ .add(threshold)
+ }
}
fun additionalProperties(additionalProperties: Map) = apply {
@@ -113,7 +147,7 @@ constructor(
fun build(): AlertUpdateBody =
AlertUpdateBody(
checkNotNull(thresholds) { "`thresholds` is required but was not set" }
- .toImmutable(),
+ .map { it.toImmutable() },
additionalProperties.toImmutable()
)
}
@@ -166,9 +200,33 @@ constructor(
/** The thresholds that define the values at which the alert will be triggered. */
fun thresholds(thresholds: List) = apply { body.thresholds(thresholds) }
+ /** The thresholds that define the values at which the alert will be triggered. */
+ fun thresholds(thresholds: JsonField>) = apply {
+ body.thresholds(thresholds)
+ }
+
/** The thresholds that define the values at which the alert will be triggered. */
fun addThreshold(threshold: Threshold) = apply { body.addThreshold(threshold) }
+ fun additionalBodyProperties(additionalBodyProperties: Map