Skip to content

Commit

Permalink
fix(client): error class toBuilder not copying fields (#373)
Browse files Browse the repository at this point in the history
feat(client): additional builder setters for error class
  • Loading branch information
stainless-app[bot] authored Nov 7, 2024
1 parent 8ee1ea1 commit 0e57fab
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ import java.util.Objects
@JsonDeserialize(builder = LithicError.Builder::class)
@NoAutoDetect
class LithicError
constructor(
private val additionalProperties: Map<String, JsonValue>,
private constructor(
@JsonAnyGetter val additionalProperties: Map<String, JsonValue>,
) {

@JsonAnyGetter fun additionalProperties(): Map<String, JsonValue> = additionalProperties

fun toBuilder() = Builder()

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
Expand All @@ -35,6 +31,8 @@ constructor(

override fun toString() = "LithicError{additionalProperties=$additionalProperties}"

fun toBuilder() = Builder().from(this)

companion object {

fun builder() = Builder()
Expand All @@ -44,22 +42,30 @@ constructor(

private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

fun from(error: LithicError) = apply { additionalProperties(error.additionalProperties) }
internal fun from(lithicError: LithicError) = apply {
additionalProperties = lithicError.additionalProperties.toMutableMap()
}

fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
this.additionalProperties.clear()
this.additionalProperties.putAll(additionalProperties)
putAllAdditionalProperties(additionalProperties)
}

@JsonAnySetter
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
this.additionalProperties.put(key, value)
additionalProperties.put(key, value)
}

fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
this.additionalProperties.putAll(additionalProperties)
}

fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }

fun removeAllAdditionalProperties(keys: Set<String>) = apply {
keys.forEach(::removeAdditionalProperty)
}

fun build(): LithicError = LithicError(additionalProperties.toImmutable())
}
}

0 comments on commit 0e57fab

Please sign in to comment.