Skip to content

Commit df70a48

Browse files
feat(api): api update
1 parent 7d720b4 commit df70a48

13 files changed

Lines changed: 227 additions & 60 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 139
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb/orb-cbb433962c75b95b0c00c453c3a2e39a88f4291a92c093f27a3f52d1b52785a2.yml
3-
openapi_spec_hash: 46b3934a43850209dad40e883aa5d1bd
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb/orb-8b0ad117378120e92c83db4289345b202e96ee8cdd187e25eadd49f8220fd2c2.yml
3+
openapi_spec_hash: c54dfea4283acbda4f01e8da6ac0e651
44
config_hash: c01c1191b1cd696c7ca855ff6d28a8df

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

Lines changed: 150 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter
66
import com.fasterxml.jackson.annotation.JsonAnySetter
77
import com.fasterxml.jackson.annotation.JsonCreator
88
import com.fasterxml.jackson.annotation.JsonProperty
9+
import com.withorb.api.core.Enum
910
import com.withorb.api.core.ExcludeMissing
1011
import com.withorb.api.core.JsonField
1112
import com.withorb.api.core.JsonMissing
@@ -14,12 +15,13 @@ import com.withorb.api.core.checkRequired
1415
import com.withorb.api.errors.OrbInvalidDataException
1516
import java.util.Collections
1617
import java.util.Objects
18+
import kotlin.jvm.optionals.getOrNull
1719

1820
class AccountingProviderConfig
1921
@JsonCreator(mode = JsonCreator.Mode.DISABLED)
2022
private constructor(
2123
private val externalProviderId: JsonField<String>,
22-
private val providerType: JsonField<String>,
24+
private val providerType: JsonField<ProviderType>,
2325
private val additionalProperties: MutableMap<String, JsonValue>,
2426
) {
2527

@@ -30,7 +32,7 @@ private constructor(
3032
externalProviderId: JsonField<String> = JsonMissing.of(),
3133
@JsonProperty("provider_type")
3234
@ExcludeMissing
33-
providerType: JsonField<String> = JsonMissing.of(),
35+
providerType: JsonField<ProviderType> = JsonMissing.of(),
3436
) : this(externalProviderId, providerType, mutableMapOf())
3537

3638
/**
@@ -43,7 +45,7 @@ private constructor(
4345
* @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly
4446
* missing or null (e.g. if the server responded with an unexpected value).
4547
*/
46-
fun providerType(): String = providerType.getRequired("provider_type")
48+
fun providerType(): ProviderType = providerType.getRequired("provider_type")
4749

4850
/**
4951
* Returns the raw JSON value of [externalProviderId].
@@ -62,7 +64,7 @@ private constructor(
6264
*/
6365
@JsonProperty("provider_type")
6466
@ExcludeMissing
65-
fun _providerType(): JsonField<String> = providerType
67+
fun _providerType(): JsonField<ProviderType> = providerType
6668

6769
@JsonAnySetter
6870
private fun putAdditionalProperty(key: String, value: JsonValue) {
@@ -94,7 +96,7 @@ private constructor(
9496
class Builder internal constructor() {
9597

9698
private var externalProviderId: JsonField<String>? = null
97-
private var providerType: JsonField<String>? = null
99+
private var providerType: JsonField<ProviderType>? = null
98100
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
99101

100102
@JvmSynthetic
@@ -118,16 +120,16 @@ private constructor(
118120
this.externalProviderId = externalProviderId
119121
}
120122

121-
fun providerType(providerType: String) = providerType(JsonField.of(providerType))
123+
fun providerType(providerType: ProviderType) = providerType(JsonField.of(providerType))
122124

123125
/**
124126
* Sets [Builder.providerType] to an arbitrary JSON value.
125127
*
126-
* You should usually call [Builder.providerType] with a well-typed [String] value instead.
127-
* This method is primarily for setting the field to an undocumented or not yet supported
128-
* value.
128+
* You should usually call [Builder.providerType] with a well-typed [ProviderType] value
129+
* instead. This method is primarily for setting the field to an undocumented or not yet
130+
* supported value.
129131
*/
130-
fun providerType(providerType: JsonField<String>) = apply {
132+
fun providerType(providerType: JsonField<ProviderType>) = apply {
131133
this.providerType = providerType
132134
}
133135

@@ -187,7 +189,7 @@ private constructor(
187189
}
188190

189191
externalProviderId()
190-
providerType()
192+
providerType().validate()
191193
validated = true
192194
}
193195

@@ -207,7 +209,143 @@ private constructor(
207209
@JvmSynthetic
208210
internal fun validity(): Int =
209211
(if (externalProviderId.asKnown().isPresent) 1 else 0) +
210-
(if (providerType.asKnown().isPresent) 1 else 0)
212+
(providerType.asKnown().getOrNull()?.validity() ?: 0)
213+
214+
class ProviderType @JsonCreator private constructor(private val value: JsonField<String>) :
215+
Enum {
216+
217+
/**
218+
* Returns this class instance's raw value.
219+
*
220+
* This is usually only useful if this instance was deserialized from data that doesn't
221+
* match any known member, and you want to know that value. For example, if the SDK is on an
222+
* older version than the API, then the API may respond with new members that the SDK is
223+
* unaware of.
224+
*/
225+
@com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value
226+
227+
companion object {
228+
229+
@JvmField val QUICKBOOKS = of("quickbooks")
230+
231+
@JvmField val NETSUITE = of("netsuite")
232+
233+
@JvmStatic fun of(value: String) = ProviderType(JsonField.of(value))
234+
}
235+
236+
/** An enum containing [ProviderType]'s known values. */
237+
enum class Known {
238+
QUICKBOOKS,
239+
NETSUITE,
240+
}
241+
242+
/**
243+
* An enum containing [ProviderType]'s known values, as well as an [_UNKNOWN] member.
244+
*
245+
* An instance of [ProviderType] can contain an unknown value in a couple of cases:
246+
* - It was deserialized from data that doesn't match any known member. For example, if the
247+
* SDK is on an older version than the API, then the API may respond with new members that
248+
* the SDK is unaware of.
249+
* - It was constructed with an arbitrary value using the [of] method.
250+
*/
251+
enum class Value {
252+
QUICKBOOKS,
253+
NETSUITE,
254+
/**
255+
* An enum member indicating that [ProviderType] was instantiated with an unknown value.
256+
*/
257+
_UNKNOWN,
258+
}
259+
260+
/**
261+
* Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
262+
* if the class was instantiated with an unknown value.
263+
*
264+
* Use the [known] method instead if you're certain the value is always known or if you want
265+
* to throw for the unknown case.
266+
*/
267+
fun value(): Value =
268+
when (this) {
269+
QUICKBOOKS -> Value.QUICKBOOKS
270+
NETSUITE -> Value.NETSUITE
271+
else -> Value._UNKNOWN
272+
}
273+
274+
/**
275+
* Returns an enum member corresponding to this class instance's value.
276+
*
277+
* Use the [value] method instead if you're uncertain the value is always known and don't
278+
* want to throw for the unknown case.
279+
*
280+
* @throws OrbInvalidDataException if this class instance's value is a not a known member.
281+
*/
282+
fun known(): Known =
283+
when (this) {
284+
QUICKBOOKS -> Known.QUICKBOOKS
285+
NETSUITE -> Known.NETSUITE
286+
else -> throw OrbInvalidDataException("Unknown ProviderType: $value")
287+
}
288+
289+
/**
290+
* Returns this class instance's primitive wire representation.
291+
*
292+
* This differs from the [toString] method because that method is primarily for debugging
293+
* and generally doesn't throw.
294+
*
295+
* @throws OrbInvalidDataException if this class instance's value does not have the expected
296+
* primitive type.
297+
*/
298+
fun asString(): String =
299+
_value().asString().orElseThrow { OrbInvalidDataException("Value is not a String") }
300+
301+
private var validated: Boolean = false
302+
303+
/**
304+
* Validates that the types of all values in this object match their expected types
305+
* recursively.
306+
*
307+
* This method is _not_ forwards compatible with new types from the API for existing fields.
308+
*
309+
* @throws OrbInvalidDataException if any value type in this object doesn't match its
310+
* expected type.
311+
*/
312+
fun validate(): ProviderType = apply {
313+
if (validated) {
314+
return@apply
315+
}
316+
317+
known()
318+
validated = true
319+
}
320+
321+
fun isValid(): Boolean =
322+
try {
323+
validate()
324+
true
325+
} catch (e: OrbInvalidDataException) {
326+
false
327+
}
328+
329+
/**
330+
* Returns a score indicating how many valid values are contained in this object
331+
* recursively.
332+
*
333+
* Used for best match union deserialization.
334+
*/
335+
@JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
336+
337+
override fun equals(other: Any?): Boolean {
338+
if (this === other) {
339+
return true
340+
}
341+
342+
return other is ProviderType && value == other.value
343+
}
344+
345+
override fun hashCode() = value.hashCode()
346+
347+
override fun toString() = value.toString()
348+
}
211349

212350
override fun equals(other: Any?): Boolean {
213351
if (this === other) {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,16 +2530,13 @@ private constructor(
25302530

25312531
@JvmField val NETSUITE = of("netsuite")
25322532

2533-
@JvmField val NETSUITE_AMPERSAND = of("netsuite_ampersand")
2534-
25352533
@JvmStatic fun of(value: String) = ProviderType(JsonField.of(value))
25362534
}
25372535

25382536
/** An enum containing [ProviderType]'s known values. */
25392537
enum class Known {
25402538
QUICKBOOKS,
25412539
NETSUITE,
2542-
NETSUITE_AMPERSAND,
25432540
}
25442541

25452542
/**
@@ -2555,7 +2552,6 @@ private constructor(
25552552
enum class Value {
25562553
QUICKBOOKS,
25572554
NETSUITE,
2558-
NETSUITE_AMPERSAND,
25592555
/**
25602556
* An enum member indicating that [ProviderType] was instantiated with an
25612557
* unknown value.
@@ -2574,7 +2570,6 @@ private constructor(
25742570
when (this) {
25752571
QUICKBOOKS -> Value.QUICKBOOKS
25762572
NETSUITE -> Value.NETSUITE
2577-
NETSUITE_AMPERSAND -> Value.NETSUITE_AMPERSAND
25782573
else -> Value._UNKNOWN
25792574
}
25802575

@@ -2591,7 +2586,6 @@ private constructor(
25912586
when (this) {
25922587
QUICKBOOKS -> Known.QUICKBOOKS
25932588
NETSUITE -> Known.NETSUITE
2594-
NETSUITE_AMPERSAND -> Known.NETSUITE_AMPERSAND
25952589
else -> throw OrbInvalidDataException("Unknown ProviderType: $value")
25962590
}
25972591

orb-java-core/src/test/kotlin/com/withorb/api/models/AccountingProviderConfigTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ internal class AccountingProviderConfigTest {
1414
val accountingProviderConfig =
1515
AccountingProviderConfig.builder()
1616
.externalProviderId("external_provider_id")
17-
.providerType("provider_type")
17+
.providerType(AccountingProviderConfig.ProviderType.QUICKBOOKS)
1818
.build()
1919

2020
assertThat(accountingProviderConfig.externalProviderId()).isEqualTo("external_provider_id")
21-
assertThat(accountingProviderConfig.providerType()).isEqualTo("provider_type")
21+
assertThat(accountingProviderConfig.providerType())
22+
.isEqualTo(AccountingProviderConfig.ProviderType.QUICKBOOKS)
2223
}
2324

2425
@Test
@@ -27,7 +28,7 @@ internal class AccountingProviderConfigTest {
2728
val accountingProviderConfig =
2829
AccountingProviderConfig.builder()
2930
.externalProviderId("external_provider_id")
30-
.providerType("provider_type")
31+
.providerType(AccountingProviderConfig.ProviderType.QUICKBOOKS)
3132
.build()
3233

3334
val roundtrippedAccountingProviderConfig =

orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerCreateParamsTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class CustomerCreateParamsTest {
1919
.addAccountingProvider(
2020
AccountingProviderConfig.builder()
2121
.externalProviderId("external_provider_id")
22-
.providerType("provider_type")
22+
.providerType(AccountingProviderConfig.ProviderType.QUICKBOOKS)
2323
.build()
2424
)
2525
.excluded(true)
@@ -110,7 +110,7 @@ internal class CustomerCreateParamsTest {
110110
.addAccountingProvider(
111111
AccountingProviderConfig.builder()
112112
.externalProviderId("external_provider_id")
113-
.providerType("provider_type")
113+
.providerType(AccountingProviderConfig.ProviderType.QUICKBOOKS)
114114
.build()
115115
)
116116
.excluded(true)
@@ -199,7 +199,7 @@ internal class CustomerCreateParamsTest {
199199
.addAccountingProvider(
200200
AccountingProviderConfig.builder()
201201
.externalProviderId("external_provider_id")
202-
.providerType("provider_type")
202+
.providerType(AccountingProviderConfig.ProviderType.QUICKBOOKS)
203203
.build()
204204
)
205205
.excluded(true)

orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerUpdateByExternalIdParamsTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal class CustomerUpdateByExternalIdParamsTest {
1818
.addAccountingProvider(
1919
AccountingProviderConfig.builder()
2020
.externalProviderId("external_provider_id")
21-
.providerType("provider_type")
21+
.providerType(AccountingProviderConfig.ProviderType.QUICKBOOKS)
2222
.build()
2323
)
2424
.excluded(true)
@@ -120,7 +120,7 @@ internal class CustomerUpdateByExternalIdParamsTest {
120120
.addAccountingProvider(
121121
AccountingProviderConfig.builder()
122122
.externalProviderId("external_provider_id")
123-
.providerType("provider_type")
123+
.providerType(AccountingProviderConfig.ProviderType.QUICKBOOKS)
124124
.build()
125125
)
126126
.excluded(true)
@@ -210,7 +210,7 @@ internal class CustomerUpdateByExternalIdParamsTest {
210210
.addAccountingProvider(
211211
AccountingProviderConfig.builder()
212212
.externalProviderId("external_provider_id")
213-
.providerType("provider_type")
213+
.providerType(AccountingProviderConfig.ProviderType.QUICKBOOKS)
214214
.build()
215215
)
216216
.excluded(true)

orb-java-core/src/test/kotlin/com/withorb/api/models/CustomerUpdateParamsTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal class CustomerUpdateParamsTest {
1818
.addAccountingProvider(
1919
AccountingProviderConfig.builder()
2020
.externalProviderId("external_provider_id")
21-
.providerType("provider_type")
21+
.providerType(AccountingProviderConfig.ProviderType.QUICKBOOKS)
2222
.build()
2323
)
2424
.excluded(true)
@@ -118,7 +118,7 @@ internal class CustomerUpdateParamsTest {
118118
.addAccountingProvider(
119119
AccountingProviderConfig.builder()
120120
.externalProviderId("external_provider_id")
121-
.providerType("provider_type")
121+
.providerType(AccountingProviderConfig.ProviderType.QUICKBOOKS)
122122
.build()
123123
)
124124
.excluded(true)
@@ -206,7 +206,7 @@ internal class CustomerUpdateParamsTest {
206206
.addAccountingProvider(
207207
AccountingProviderConfig.builder()
208208
.externalProviderId("external_provider_id")
209-
.providerType("provider_type")
209+
.providerType(AccountingProviderConfig.ProviderType.QUICKBOOKS)
210210
.build()
211211
)
212212
.excluded(true)

0 commit comments

Comments
 (0)