Skip to content

Commit 32b3512

Browse files
feat(api)!: define shared model ConversionRateConfig
`ConversionRateConfig` is defined in lots of places in the SDK. This commit extracts it to a shared model to reduce code duplication. Its new location is `orb-java-core/src/main/kotlin/com/withorb/api/models/ConversionRateConfig.kt`
1 parent d06f656 commit 32b3512

File tree

173 files changed

+788
-20571
lines changed

Some content is hidden

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

173 files changed

+788
-20571
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 118
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-4f31d46f5ba187fc4d702c9f9f1573dacb891edbd086f935707578d7c4f5fed8.yml
33
openapi_spec_hash: 25b1019f20a47b8af665aae5f8fd0025
4-
config_hash: d8a0d696f3250ab096fac87b6b0eab53
4+
config_hash: be9350529b910ec14bff0a30cd74a185
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
// File generated from our OpenAPI spec by Stainless.
2+
3+
package com.withorb.api.models
4+
5+
import com.fasterxml.jackson.core.JsonGenerator
6+
import com.fasterxml.jackson.core.ObjectCodec
7+
import com.fasterxml.jackson.databind.JsonNode
8+
import com.fasterxml.jackson.databind.SerializerProvider
9+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
10+
import com.fasterxml.jackson.databind.annotation.JsonSerialize
11+
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
12+
import com.withorb.api.core.BaseDeserializer
13+
import com.withorb.api.core.BaseSerializer
14+
import com.withorb.api.core.JsonValue
15+
import com.withorb.api.core.getOrThrow
16+
import com.withorb.api.errors.OrbInvalidDataException
17+
import java.util.Objects
18+
19+
@JsonDeserialize(using = ConversionRateConfig.Deserializer::class)
20+
@JsonSerialize(using = ConversionRateConfig.Serializer::class)
21+
class ConversionRateConfig
22+
private constructor(
23+
private val unit: UnitConversionRateConfig? = null,
24+
private val tiered: TieredConversionRateConfig? = null,
25+
private val _json: JsonValue? = null,
26+
) {
27+
28+
fun unit(): UnitConversionRateConfig? = unit
29+
30+
fun tiered(): TieredConversionRateConfig? = tiered
31+
32+
fun isUnit(): Boolean = unit != null
33+
34+
fun isTiered(): Boolean = tiered != null
35+
36+
fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit")
37+
38+
fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered")
39+
40+
fun _json(): JsonValue? = _json
41+
42+
fun <T> accept(visitor: Visitor<T>): T =
43+
when {
44+
unit != null -> visitor.visitUnit(unit)
45+
tiered != null -> visitor.visitTiered(tiered)
46+
else -> visitor.unknown(_json)
47+
}
48+
49+
private var validated: Boolean = false
50+
51+
fun validate(): ConversionRateConfig = apply {
52+
if (validated) {
53+
return@apply
54+
}
55+
56+
accept(
57+
object : Visitor<Unit> {
58+
override fun visitUnit(unit: UnitConversionRateConfig) {
59+
unit.validate()
60+
}
61+
62+
override fun visitTiered(tiered: TieredConversionRateConfig) {
63+
tiered.validate()
64+
}
65+
}
66+
)
67+
validated = true
68+
}
69+
70+
fun isValid(): Boolean =
71+
try {
72+
validate()
73+
true
74+
} catch (e: OrbInvalidDataException) {
75+
false
76+
}
77+
78+
/**
79+
* Returns a score indicating how many valid values are contained in this object recursively.
80+
*
81+
* Used for best match union deserialization.
82+
*/
83+
internal fun validity(): Int =
84+
accept(
85+
object : Visitor<Int> {
86+
override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity()
87+
88+
override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity()
89+
90+
override fun unknown(json: JsonValue?) = 0
91+
}
92+
)
93+
94+
override fun equals(other: Any?): Boolean {
95+
if (this === other) {
96+
return true
97+
}
98+
99+
return other is ConversionRateConfig && unit == other.unit && tiered == other.tiered
100+
}
101+
102+
override fun hashCode(): Int = Objects.hash(unit, tiered)
103+
104+
override fun toString(): String =
105+
when {
106+
unit != null -> "ConversionRateConfig{unit=$unit}"
107+
tiered != null -> "ConversionRateConfig{tiered=$tiered}"
108+
_json != null -> "ConversionRateConfig{_unknown=$_json}"
109+
else -> throw IllegalStateException("Invalid ConversionRateConfig")
110+
}
111+
112+
companion object {
113+
114+
fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit)
115+
116+
fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered)
117+
}
118+
119+
/**
120+
* An interface that defines how to map each variant of [ConversionRateConfig] to a value of
121+
* type [T].
122+
*/
123+
interface Visitor<out T> {
124+
125+
fun visitUnit(unit: UnitConversionRateConfig): T
126+
127+
fun visitTiered(tiered: TieredConversionRateConfig): T
128+
129+
/**
130+
* Maps an unknown variant of [ConversionRateConfig] to a value of type [T].
131+
*
132+
* An instance of [ConversionRateConfig] can contain an unknown variant if it was
133+
* deserialized from data that doesn't match any known variant. For example, if the SDK is
134+
* on an older version than the API, then the API may respond with new variants that the SDK
135+
* is unaware of.
136+
*
137+
* @throws OrbInvalidDataException in the default implementation.
138+
*/
139+
fun unknown(json: JsonValue?): T {
140+
throw OrbInvalidDataException("Unknown ConversionRateConfig: $json")
141+
}
142+
}
143+
144+
internal class Deserializer :
145+
BaseDeserializer<ConversionRateConfig>(ConversionRateConfig::class) {
146+
147+
override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig {
148+
val json = JsonValue.fromJsonNode(node)
149+
val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString()
150+
151+
when (conversionRateType) {
152+
"unit" -> {
153+
return tryDeserialize(node, jacksonTypeRef<UnitConversionRateConfig>())?.let {
154+
ConversionRateConfig(unit = it, _json = json)
155+
} ?: ConversionRateConfig(_json = json)
156+
}
157+
"tiered" -> {
158+
return tryDeserialize(node, jacksonTypeRef<TieredConversionRateConfig>())?.let {
159+
ConversionRateConfig(tiered = it, _json = json)
160+
} ?: ConversionRateConfig(_json = json)
161+
}
162+
}
163+
164+
return ConversionRateConfig(_json = json)
165+
}
166+
}
167+
168+
internal class Serializer : BaseSerializer<ConversionRateConfig>(ConversionRateConfig::class) {
169+
170+
override fun serialize(
171+
value: ConversionRateConfig,
172+
generator: JsonGenerator,
173+
provider: SerializerProvider,
174+
) {
175+
when {
176+
value.unit != null -> generator.writeObject(value.unit)
177+
value.tiered != null -> generator.writeObject(value.tiered)
178+
value._json != null -> generator.writeObject(value._json)
179+
else -> throw IllegalStateException("Invalid ConversionRateConfig")
180+
}
181+
}
182+
}
183+
}

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

Lines changed: 0 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,12 @@ 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.fasterxml.jackson.core.JsonGenerator
10-
import com.fasterxml.jackson.core.ObjectCodec
11-
import com.fasterxml.jackson.databind.JsonNode
12-
import com.fasterxml.jackson.databind.SerializerProvider
13-
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
14-
import com.fasterxml.jackson.databind.annotation.JsonSerialize
15-
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
16-
import com.withorb.api.core.BaseDeserializer
17-
import com.withorb.api.core.BaseSerializer
189
import com.withorb.api.core.Enum
1910
import com.withorb.api.core.ExcludeMissing
2011
import com.withorb.api.core.JsonField
2112
import com.withorb.api.core.JsonMissing
2213
import com.withorb.api.core.JsonValue
2314
import com.withorb.api.core.checkRequired
24-
import com.withorb.api.core.getOrThrow
2515
import com.withorb.api.core.toImmutable
2616
import com.withorb.api.errors.OrbInvalidDataException
2717
import java.util.Collections
@@ -1172,175 +1162,6 @@ private constructor(
11721162
override fun toString() = value.toString()
11731163
}
11741164

1175-
/** The configuration for the rate of the price currency to the invoicing currency. */
1176-
@JsonDeserialize(using = ConversionRateConfig.Deserializer::class)
1177-
@JsonSerialize(using = ConversionRateConfig.Serializer::class)
1178-
class ConversionRateConfig
1179-
private constructor(
1180-
private val unit: UnitConversionRateConfig? = null,
1181-
private val tiered: TieredConversionRateConfig? = null,
1182-
private val _json: JsonValue? = null,
1183-
) {
1184-
1185-
fun unit(): UnitConversionRateConfig? = unit
1186-
1187-
fun tiered(): TieredConversionRateConfig? = tiered
1188-
1189-
fun isUnit(): Boolean = unit != null
1190-
1191-
fun isTiered(): Boolean = tiered != null
1192-
1193-
fun asUnit(): UnitConversionRateConfig = unit.getOrThrow("unit")
1194-
1195-
fun asTiered(): TieredConversionRateConfig = tiered.getOrThrow("tiered")
1196-
1197-
fun _json(): JsonValue? = _json
1198-
1199-
fun <T> accept(visitor: Visitor<T>): T =
1200-
when {
1201-
unit != null -> visitor.visitUnit(unit)
1202-
tiered != null -> visitor.visitTiered(tiered)
1203-
else -> visitor.unknown(_json)
1204-
}
1205-
1206-
private var validated: Boolean = false
1207-
1208-
fun validate(): ConversionRateConfig = apply {
1209-
if (validated) {
1210-
return@apply
1211-
}
1212-
1213-
accept(
1214-
object : Visitor<Unit> {
1215-
override fun visitUnit(unit: UnitConversionRateConfig) {
1216-
unit.validate()
1217-
}
1218-
1219-
override fun visitTiered(tiered: TieredConversionRateConfig) {
1220-
tiered.validate()
1221-
}
1222-
}
1223-
)
1224-
validated = true
1225-
}
1226-
1227-
fun isValid(): Boolean =
1228-
try {
1229-
validate()
1230-
true
1231-
} catch (e: OrbInvalidDataException) {
1232-
false
1233-
}
1234-
1235-
/**
1236-
* Returns a score indicating how many valid values are contained in this object
1237-
* recursively.
1238-
*
1239-
* Used for best match union deserialization.
1240-
*/
1241-
internal fun validity(): Int =
1242-
accept(
1243-
object : Visitor<Int> {
1244-
override fun visitUnit(unit: UnitConversionRateConfig) = unit.validity()
1245-
1246-
override fun visitTiered(tiered: TieredConversionRateConfig) = tiered.validity()
1247-
1248-
override fun unknown(json: JsonValue?) = 0
1249-
}
1250-
)
1251-
1252-
override fun equals(other: Any?): Boolean {
1253-
if (this === other) {
1254-
return true
1255-
}
1256-
1257-
return other is ConversionRateConfig && unit == other.unit && tiered == other.tiered
1258-
}
1259-
1260-
override fun hashCode(): Int = Objects.hash(unit, tiered)
1261-
1262-
override fun toString(): String =
1263-
when {
1264-
unit != null -> "ConversionRateConfig{unit=$unit}"
1265-
tiered != null -> "ConversionRateConfig{tiered=$tiered}"
1266-
_json != null -> "ConversionRateConfig{_unknown=$_json}"
1267-
else -> throw IllegalStateException("Invalid ConversionRateConfig")
1268-
}
1269-
1270-
companion object {
1271-
1272-
fun ofUnit(unit: UnitConversionRateConfig) = ConversionRateConfig(unit = unit)
1273-
1274-
fun ofTiered(tiered: TieredConversionRateConfig) = ConversionRateConfig(tiered = tiered)
1275-
}
1276-
1277-
/**
1278-
* An interface that defines how to map each variant of [ConversionRateConfig] to a value of
1279-
* type [T].
1280-
*/
1281-
interface Visitor<out T> {
1282-
1283-
fun visitUnit(unit: UnitConversionRateConfig): T
1284-
1285-
fun visitTiered(tiered: TieredConversionRateConfig): T
1286-
1287-
/**
1288-
* Maps an unknown variant of [ConversionRateConfig] to a value of type [T].
1289-
*
1290-
* An instance of [ConversionRateConfig] can contain an unknown variant if it was
1291-
* deserialized from data that doesn't match any known variant. For example, if the SDK
1292-
* is on an older version than the API, then the API may respond with new variants that
1293-
* the SDK is unaware of.
1294-
*
1295-
* @throws OrbInvalidDataException in the default implementation.
1296-
*/
1297-
fun unknown(json: JsonValue?): T {
1298-
throw OrbInvalidDataException("Unknown ConversionRateConfig: $json")
1299-
}
1300-
}
1301-
1302-
internal class Deserializer :
1303-
BaseDeserializer<ConversionRateConfig>(ConversionRateConfig::class) {
1304-
1305-
override fun ObjectCodec.deserialize(node: JsonNode): ConversionRateConfig {
1306-
val json = JsonValue.fromJsonNode(node)
1307-
val conversionRateType = json.asObject()?.get("conversion_rate_type")?.asString()
1308-
1309-
when (conversionRateType) {
1310-
"unit" -> {
1311-
return tryDeserialize(node, jacksonTypeRef<UnitConversionRateConfig>())
1312-
?.let { ConversionRateConfig(unit = it, _json = json) }
1313-
?: ConversionRateConfig(_json = json)
1314-
}
1315-
"tiered" -> {
1316-
return tryDeserialize(node, jacksonTypeRef<TieredConversionRateConfig>())
1317-
?.let { ConversionRateConfig(tiered = it, _json = json) }
1318-
?: ConversionRateConfig(_json = json)
1319-
}
1320-
}
1321-
1322-
return ConversionRateConfig(_json = json)
1323-
}
1324-
}
1325-
1326-
internal class Serializer :
1327-
BaseSerializer<ConversionRateConfig>(ConversionRateConfig::class) {
1328-
1329-
override fun serialize(
1330-
value: ConversionRateConfig,
1331-
generator: JsonGenerator,
1332-
provider: SerializerProvider,
1333-
) {
1334-
when {
1335-
value.unit != null -> generator.writeObject(value.unit)
1336-
value.tiered != null -> generator.writeObject(value.tiered)
1337-
value._json != null -> generator.writeObject(value._json)
1338-
else -> throw IllegalStateException("Invalid ConversionRateConfig")
1339-
}
1340-
}
1341-
}
1342-
}
1343-
13441165
/**
13451166
* User-specified key/value pairs for the resource. Individual keys can be removed by setting
13461167
* the value to `null`, and the entire metadata mapping can be cleared by setting `metadata` to

0 commit comments

Comments
 (0)