Skip to content

Commit 7ddd872

Browse files
feat(client): allow providing some params positionally
1 parent 9df208b commit 7ddd872

File tree

214 files changed

+9897
-2089
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+9897
-2089
lines changed

orb-java-core/src/main/kotlin/com/withorb/api/core/Check.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ package com.withorb.api.core
55
import com.fasterxml.jackson.core.Version
66
import com.fasterxml.jackson.core.util.VersionUtil
77

8+
fun checkRequired(name: String, condition: Boolean) =
9+
check(condition) { "`$name` is required, but was not set" }
10+
811
fun <T : Any> checkRequired(name: String, value: T?): T =
912
checkNotNull(value) { "`$name` is required, but was not set" }
1013

orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForCustomerParams.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ import kotlin.jvm.optionals.getOrNull
3333
*/
3434
class AlertCreateForCustomerParams
3535
private constructor(
36-
private val customerId: String,
36+
private val customerId: String?,
3737
private val body: Body,
3838
private val additionalHeaders: Headers,
3939
private val additionalQueryParams: QueryParams,
4040
) : Params {
4141

42-
fun customerId(): String = customerId
42+
fun customerId(): Optional<String> = Optional.ofNullable(customerId)
4343

4444
/**
4545
* The case sensitive currency or custom pricing unit to use for this alert.
@@ -101,7 +101,6 @@ private constructor(
101101
*
102102
* The following fields are required:
103103
* ```java
104-
* .customerId()
105104
* .currency()
106105
* .type()
107106
* ```
@@ -125,7 +124,10 @@ private constructor(
125124
additionalQueryParams = alertCreateForCustomerParams.additionalQueryParams.toBuilder()
126125
}
127126

128-
fun customerId(customerId: String) = apply { this.customerId = customerId }
127+
fun customerId(customerId: String?) = apply { this.customerId = customerId }
128+
129+
/** Alias for calling [Builder.customerId] with `customerId.orElse(null)`. */
130+
fun customerId(customerId: Optional<String>) = customerId(customerId.getOrNull())
129131

130132
/**
131133
* Sets the entire request body.
@@ -308,7 +310,6 @@ private constructor(
308310
*
309311
* The following fields are required:
310312
* ```java
311-
* .customerId()
312313
* .currency()
313314
* .type()
314315
* ```
@@ -317,7 +318,7 @@ private constructor(
317318
*/
318319
fun build(): AlertCreateForCustomerParams =
319320
AlertCreateForCustomerParams(
320-
checkRequired("customerId", customerId),
321+
customerId,
321322
body.build(),
322323
additionalHeaders.build(),
323324
additionalQueryParams.build(),
@@ -328,7 +329,7 @@ private constructor(
328329

329330
fun _pathParam(index: Int): String =
330331
when (index) {
331-
0 -> customerId
332+
0 -> customerId ?: ""
332333
else -> ""
333334
}
334335

orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForExternalCustomerParams.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ import kotlin.jvm.optionals.getOrNull
3333
*/
3434
class AlertCreateForExternalCustomerParams
3535
private constructor(
36-
private val externalCustomerId: String,
36+
private val externalCustomerId: String?,
3737
private val body: Body,
3838
private val additionalHeaders: Headers,
3939
private val additionalQueryParams: QueryParams,
4040
) : Params {
4141

42-
fun externalCustomerId(): String = externalCustomerId
42+
fun externalCustomerId(): Optional<String> = Optional.ofNullable(externalCustomerId)
4343

4444
/**
4545
* The case sensitive currency or custom pricing unit to use for this alert.
@@ -102,7 +102,6 @@ private constructor(
102102
*
103103
* The following fields are required:
104104
* ```java
105-
* .externalCustomerId()
106105
* .currency()
107106
* .type()
108107
* ```
@@ -129,10 +128,16 @@ private constructor(
129128
alertCreateForExternalCustomerParams.additionalQueryParams.toBuilder()
130129
}
131130

132-
fun externalCustomerId(externalCustomerId: String) = apply {
131+
fun externalCustomerId(externalCustomerId: String?) = apply {
133132
this.externalCustomerId = externalCustomerId
134133
}
135134

135+
/**
136+
* Alias for calling [Builder.externalCustomerId] with `externalCustomerId.orElse(null)`.
137+
*/
138+
fun externalCustomerId(externalCustomerId: Optional<String>) =
139+
externalCustomerId(externalCustomerId.getOrNull())
140+
136141
/**
137142
* Sets the entire request body.
138143
*
@@ -314,7 +319,6 @@ private constructor(
314319
*
315320
* The following fields are required:
316321
* ```java
317-
* .externalCustomerId()
318322
* .currency()
319323
* .type()
320324
* ```
@@ -323,7 +327,7 @@ private constructor(
323327
*/
324328
fun build(): AlertCreateForExternalCustomerParams =
325329
AlertCreateForExternalCustomerParams(
326-
checkRequired("externalCustomerId", externalCustomerId),
330+
externalCustomerId,
327331
body.build(),
328332
additionalHeaders.build(),
329333
additionalQueryParams.build(),
@@ -334,7 +338,7 @@ private constructor(
334338

335339
fun _pathParam(index: Int): String =
336340
when (index) {
337-
0 -> externalCustomerId
341+
0 -> externalCustomerId ?: ""
338342
else -> ""
339343
}
340344

orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForSubscriptionParams.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ import kotlin.jvm.optionals.getOrNull
3737
*/
3838
class AlertCreateForSubscriptionParams
3939
private constructor(
40-
private val subscriptionId: String,
40+
private val subscriptionId: String?,
4141
private val body: Body,
4242
private val additionalHeaders: Headers,
4343
private val additionalQueryParams: QueryParams,
4444
) : Params {
4545

46-
fun subscriptionId(): String = subscriptionId
46+
fun subscriptionId(): Optional<String> = Optional.ofNullable(subscriptionId)
4747

4848
/**
4949
* The thresholds that define the values at which the alert will be triggered.
@@ -106,7 +106,6 @@ private constructor(
106106
*
107107
* The following fields are required:
108108
* ```java
109-
* .subscriptionId()
110109
* .thresholds()
111110
* .type()
112111
* ```
@@ -132,7 +131,11 @@ private constructor(
132131
alertCreateForSubscriptionParams.additionalQueryParams.toBuilder()
133132
}
134133

135-
fun subscriptionId(subscriptionId: String) = apply { this.subscriptionId = subscriptionId }
134+
fun subscriptionId(subscriptionId: String?) = apply { this.subscriptionId = subscriptionId }
135+
136+
/** Alias for calling [Builder.subscriptionId] with `subscriptionId.orElse(null)`. */
137+
fun subscriptionId(subscriptionId: Optional<String>) =
138+
subscriptionId(subscriptionId.getOrNull())
136139

137140
/**
138141
* Sets the entire request body.
@@ -315,7 +318,6 @@ private constructor(
315318
*
316319
* The following fields are required:
317320
* ```java
318-
* .subscriptionId()
319321
* .thresholds()
320322
* .type()
321323
* ```
@@ -324,7 +326,7 @@ private constructor(
324326
*/
325327
fun build(): AlertCreateForSubscriptionParams =
326328
AlertCreateForSubscriptionParams(
327-
checkRequired("subscriptionId", subscriptionId),
329+
subscriptionId,
328330
body.build(),
329331
additionalHeaders.build(),
330332
additionalQueryParams.build(),
@@ -335,7 +337,7 @@ private constructor(
335337

336338
fun _pathParam(index: Int): String =
337339
when (index) {
338-
0 -> subscriptionId
340+
0 -> subscriptionId ?: ""
339341
else -> ""
340342
}
341343

orb-java-core/src/main/kotlin/com/withorb/api/models/AlertDisableParams.kt

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package com.withorb.api.models
44

55
import com.withorb.api.core.JsonValue
66
import com.withorb.api.core.Params
7-
import com.withorb.api.core.checkRequired
87
import com.withorb.api.core.http.Headers
98
import com.withorb.api.core.http.QueryParams
109
import com.withorb.api.core.toImmutable
@@ -19,14 +18,14 @@ import kotlin.jvm.optionals.getOrNull
1918
*/
2019
class AlertDisableParams
2120
private constructor(
22-
private val alertConfigurationId: String,
21+
private val alertConfigurationId: String?,
2322
private val subscriptionId: String?,
2423
private val additionalHeaders: Headers,
2524
private val additionalQueryParams: QueryParams,
2625
private val additionalBodyProperties: Map<String, JsonValue>,
2726
) : Params {
2827

29-
fun alertConfigurationId(): String = alertConfigurationId
28+
fun alertConfigurationId(): Optional<String> = Optional.ofNullable(alertConfigurationId)
3029

3130
/** Used to update the status of a plan alert scoped to this subscription_id */
3231
fun subscriptionId(): Optional<String> = Optional.ofNullable(subscriptionId)
@@ -41,14 +40,9 @@ private constructor(
4140

4241
companion object {
4342

44-
/**
45-
* Returns a mutable builder for constructing an instance of [AlertDisableParams].
46-
*
47-
* The following fields are required:
48-
* ```java
49-
* .alertConfigurationId()
50-
* ```
51-
*/
43+
@JvmStatic fun none(): AlertDisableParams = builder().build()
44+
45+
/** Returns a mutable builder for constructing an instance of [AlertDisableParams]. */
5246
@JvmStatic fun builder() = Builder()
5347
}
5448

@@ -70,10 +64,17 @@ private constructor(
7064
additionalBodyProperties = alertDisableParams.additionalBodyProperties.toMutableMap()
7165
}
7266

73-
fun alertConfigurationId(alertConfigurationId: String) = apply {
67+
fun alertConfigurationId(alertConfigurationId: String?) = apply {
7468
this.alertConfigurationId = alertConfigurationId
7569
}
7670

71+
/**
72+
* Alias for calling [Builder.alertConfigurationId] with
73+
* `alertConfigurationId.orElse(null)`.
74+
*/
75+
fun alertConfigurationId(alertConfigurationId: Optional<String>) =
76+
alertConfigurationId(alertConfigurationId.getOrNull())
77+
7778
/** Used to update the status of a plan alert scoped to this subscription_id */
7879
fun subscriptionId(subscriptionId: String?) = apply { this.subscriptionId = subscriptionId }
7980

@@ -205,17 +206,10 @@ private constructor(
205206
* Returns an immutable instance of [AlertDisableParams].
206207
*
207208
* Further updates to this [Builder] will not mutate the returned instance.
208-
*
209-
* The following fields are required:
210-
* ```java
211-
* .alertConfigurationId()
212-
* ```
213-
*
214-
* @throws IllegalStateException if any required field is unset.
215209
*/
216210
fun build(): AlertDisableParams =
217211
AlertDisableParams(
218-
checkRequired("alertConfigurationId", alertConfigurationId),
212+
alertConfigurationId,
219213
subscriptionId,
220214
additionalHeaders.build(),
221215
additionalQueryParams.build(),
@@ -228,7 +222,7 @@ private constructor(
228222

229223
fun _pathParam(index: Int): String =
230224
when (index) {
231-
0 -> alertConfigurationId
225+
0 -> alertConfigurationId ?: ""
232226
else -> ""
233227
}
234228

orb-java-core/src/main/kotlin/com/withorb/api/models/AlertEnableParams.kt

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package com.withorb.api.models
44

55
import com.withorb.api.core.JsonValue
66
import com.withorb.api.core.Params
7-
import com.withorb.api.core.checkRequired
87
import com.withorb.api.core.http.Headers
98
import com.withorb.api.core.http.QueryParams
109
import com.withorb.api.core.toImmutable
@@ -19,14 +18,14 @@ import kotlin.jvm.optionals.getOrNull
1918
*/
2019
class AlertEnableParams
2120
private constructor(
22-
private val alertConfigurationId: String,
21+
private val alertConfigurationId: String?,
2322
private val subscriptionId: String?,
2423
private val additionalHeaders: Headers,
2524
private val additionalQueryParams: QueryParams,
2625
private val additionalBodyProperties: Map<String, JsonValue>,
2726
) : Params {
2827

29-
fun alertConfigurationId(): String = alertConfigurationId
28+
fun alertConfigurationId(): Optional<String> = Optional.ofNullable(alertConfigurationId)
3029

3130
/** Used to update the status of a plan alert scoped to this subscription_id */
3231
fun subscriptionId(): Optional<String> = Optional.ofNullable(subscriptionId)
@@ -41,14 +40,9 @@ private constructor(
4140

4241
companion object {
4342

44-
/**
45-
* Returns a mutable builder for constructing an instance of [AlertEnableParams].
46-
*
47-
* The following fields are required:
48-
* ```java
49-
* .alertConfigurationId()
50-
* ```
51-
*/
43+
@JvmStatic fun none(): AlertEnableParams = builder().build()
44+
45+
/** Returns a mutable builder for constructing an instance of [AlertEnableParams]. */
5246
@JvmStatic fun builder() = Builder()
5347
}
5448

@@ -70,10 +64,17 @@ private constructor(
7064
additionalBodyProperties = alertEnableParams.additionalBodyProperties.toMutableMap()
7165
}
7266

73-
fun alertConfigurationId(alertConfigurationId: String) = apply {
67+
fun alertConfigurationId(alertConfigurationId: String?) = apply {
7468
this.alertConfigurationId = alertConfigurationId
7569
}
7670

71+
/**
72+
* Alias for calling [Builder.alertConfigurationId] with
73+
* `alertConfigurationId.orElse(null)`.
74+
*/
75+
fun alertConfigurationId(alertConfigurationId: Optional<String>) =
76+
alertConfigurationId(alertConfigurationId.getOrNull())
77+
7778
/** Used to update the status of a plan alert scoped to this subscription_id */
7879
fun subscriptionId(subscriptionId: String?) = apply { this.subscriptionId = subscriptionId }
7980

@@ -205,17 +206,10 @@ private constructor(
205206
* Returns an immutable instance of [AlertEnableParams].
206207
*
207208
* Further updates to this [Builder] will not mutate the returned instance.
208-
*
209-
* The following fields are required:
210-
* ```java
211-
* .alertConfigurationId()
212-
* ```
213-
*
214-
* @throws IllegalStateException if any required field is unset.
215209
*/
216210
fun build(): AlertEnableParams =
217211
AlertEnableParams(
218-
checkRequired("alertConfigurationId", alertConfigurationId),
212+
alertConfigurationId,
219213
subscriptionId,
220214
additionalHeaders.build(),
221215
additionalQueryParams.build(),
@@ -228,7 +222,7 @@ private constructor(
228222

229223
fun _pathParam(index: Int): String =
230224
when (index) {
231-
0 -> alertConfigurationId
225+
0 -> alertConfigurationId ?: ""
232226
else -> ""
233227
}
234228

0 commit comments

Comments
 (0)