Skip to content

Commit

Permalink
style(client)!: rename some union classes (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and Stainless Bot committed Nov 1, 2024
1 parent 0f6a69b commit ee5d02e
Show file tree
Hide file tree
Showing 19 changed files with 1,265 additions and 1,393 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ import java.util.Objects
class AuthRuleV2DraftParams
constructor(
private val authRuleToken: String,
private val parameters: AuthRuleParameters?,
private val parameters: Parameters?,
private val additionalQueryParams: Map<String, List<String>>,
private val additionalHeaders: Map<String, List<String>>,
private val additionalBodyProperties: Map<String, JsonValue>,
) {

fun authRuleToken(): String = authRuleToken

fun parameters(): AuthRuleParameters? = parameters
fun parameters(): Parameters? = parameters

internal fun getBody(): AuthRuleV2DraftBody {
return AuthRuleV2DraftBody(parameters, additionalBodyProperties)
Expand All @@ -59,12 +59,12 @@ constructor(
@NoAutoDetect
class AuthRuleV2DraftBody
internal constructor(
private val parameters: AuthRuleParameters?,
private val parameters: Parameters?,
private val additionalProperties: Map<String, JsonValue>,
) {

/** Parameters for the current version of the Auth Rule */
@JsonProperty("parameters") fun parameters(): AuthRuleParameters? = parameters
@JsonProperty("parameters") fun parameters(): Parameters? = parameters

@JsonAnyGetter
@ExcludeMissing
Expand All @@ -79,7 +79,7 @@ constructor(

class Builder {

private var parameters: AuthRuleParameters? = null
private var parameters: Parameters? = null
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

internal fun from(authRuleV2DraftBody: AuthRuleV2DraftBody) = apply {
Expand All @@ -89,7 +89,7 @@ constructor(

/** Parameters for the current version of the Auth Rule */
@JsonProperty("parameters")
fun parameters(parameters: AuthRuleParameters) = apply { this.parameters = parameters }
fun parameters(parameters: Parameters) = apply { this.parameters = parameters }

fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
this.additionalProperties.clear()
Expand Down Expand Up @@ -162,7 +162,7 @@ constructor(
class Builder {

private var authRuleToken: String? = null
private var parameters: AuthRuleParameters? = null
private var parameters: Parameters? = null
private var additionalQueryParams: MutableMap<String, MutableList<String>> = mutableMapOf()
private var additionalHeaders: MutableMap<String, MutableList<String>> = mutableMapOf()
private var additionalBodyProperties: MutableMap<String, JsonValue> = mutableMapOf()
Expand All @@ -178,18 +178,16 @@ constructor(
fun authRuleToken(authRuleToken: String) = apply { this.authRuleToken = authRuleToken }

/** Parameters for the current version of the Auth Rule */
fun parameters(parameters: AuthRuleParameters) = apply { this.parameters = parameters }
fun parameters(parameters: Parameters) = apply { this.parameters = parameters }

/** Parameters for the current version of the Auth Rule */
fun parameters(conditionalBlockParameters: AuthRuleParameters.ConditionalBlockParameters) =
apply {
this.parameters =
AuthRuleParameters.ofConditionalBlockParameters(conditionalBlockParameters)
}
fun parameters(conditionalBlockParameters: Parameters.ConditionalBlockParameters) = apply {
this.parameters = Parameters.ofConditionalBlockParameters(conditionalBlockParameters)
}

/** Parameters for the current version of the Auth Rule */
fun parameters(velocityLimitParams: VelocityLimitParams) = apply {
this.parameters = AuthRuleParameters.ofVelocityLimitParams(velocityLimitParams)
this.parameters = Parameters.ofVelocityLimitParams(velocityLimitParams)
}

fun additionalQueryParams(additionalQueryParams: Map<String, List<String>>) = apply {
Expand Down Expand Up @@ -256,9 +254,9 @@ constructor(
)
}

@JsonDeserialize(using = AuthRuleParameters.Deserializer::class)
@JsonSerialize(using = AuthRuleParameters.Serializer::class)
class AuthRuleParameters
@JsonDeserialize(using = Parameters.Deserializer::class)
@JsonSerialize(using = Parameters.Serializer::class)
class Parameters
private constructor(
private val conditionalBlockParameters: ConditionalBlockParameters? = null,
private val velocityLimitParams: VelocityLimitParams? = null,
Expand Down Expand Up @@ -292,10 +290,10 @@ constructor(
}
}

fun validate(): AuthRuleParameters = apply {
fun validate(): Parameters = apply {
if (!validated) {
if (conditionalBlockParameters == null && velocityLimitParams == null) {
throw LithicInvalidDataException("Unknown AuthRuleParameters: $_json")
throw LithicInvalidDataException("Unknown Parameters: $_json")
}
conditionalBlockParameters?.validate()
velocityLimitParams?.validate()
Expand All @@ -308,7 +306,7 @@ constructor(
return true
}

return /* spotless:off */ other is AuthRuleParameters && this.conditionalBlockParameters == other.conditionalBlockParameters && this.velocityLimitParams == other.velocityLimitParams /* spotless:on */
return /* spotless:off */ other is Parameters && this.conditionalBlockParameters == other.conditionalBlockParameters && this.velocityLimitParams == other.velocityLimitParams /* spotless:on */
}

override fun hashCode(): Int {
Expand All @@ -318,22 +316,22 @@ constructor(
override fun toString(): String {
return when {
conditionalBlockParameters != null ->
"AuthRuleParameters{conditionalBlockParameters=$conditionalBlockParameters}"
"Parameters{conditionalBlockParameters=$conditionalBlockParameters}"
velocityLimitParams != null ->
"AuthRuleParameters{velocityLimitParams=$velocityLimitParams}"
_json != null -> "AuthRuleParameters{_unknown=$_json}"
else -> throw IllegalStateException("Invalid AuthRuleParameters")
"Parameters{velocityLimitParams=$velocityLimitParams}"
_json != null -> "Parameters{_unknown=$_json}"
else -> throw IllegalStateException("Invalid Parameters")
}
}

companion object {

fun ofConditionalBlockParameters(
conditionalBlockParameters: ConditionalBlockParameters
) = AuthRuleParameters(conditionalBlockParameters = conditionalBlockParameters)
) = Parameters(conditionalBlockParameters = conditionalBlockParameters)

fun ofVelocityLimitParams(velocityLimitParams: VelocityLimitParams) =
AuthRuleParameters(velocityLimitParams = velocityLimitParams)
Parameters(velocityLimitParams = velocityLimitParams)
}

interface Visitor<out T> {
Expand All @@ -345,32 +343,32 @@ constructor(
fun visitVelocityLimitParams(velocityLimitParams: VelocityLimitParams): T

fun unknown(json: JsonValue?): T {
throw LithicInvalidDataException("Unknown AuthRuleParameters: $json")
throw LithicInvalidDataException("Unknown Parameters: $json")
}
}

class Deserializer : BaseDeserializer<AuthRuleParameters>(AuthRuleParameters::class) {
class Deserializer : BaseDeserializer<Parameters>(Parameters::class) {

override fun ObjectCodec.deserialize(node: JsonNode): AuthRuleParameters {
override fun ObjectCodec.deserialize(node: JsonNode): Parameters {
val json = JsonValue.fromJsonNode(node)

tryDeserialize(node, jacksonTypeRef<ConditionalBlockParameters>()) { it.validate() }
?.let {
return AuthRuleParameters(conditionalBlockParameters = it, _json = json)
return Parameters(conditionalBlockParameters = it, _json = json)
}
tryDeserialize(node, jacksonTypeRef<VelocityLimitParams>()) { it.validate() }
?.let {
return AuthRuleParameters(velocityLimitParams = it, _json = json)
return Parameters(velocityLimitParams = it, _json = json)
}

return AuthRuleParameters(_json = json)
return Parameters(_json = json)
}
}

class Serializer : BaseSerializer<AuthRuleParameters>(AuthRuleParameters::class) {
class Serializer : BaseSerializer<Parameters>(Parameters::class) {

override fun serialize(
value: AuthRuleParameters,
value: Parameters,
generator: JsonGenerator,
provider: SerializerProvider
) {
Expand All @@ -380,7 +378,7 @@ constructor(
value.velocityLimitParams != null ->
generator.writeObject(value.velocityLimitParams)
value._json != null -> generator.writeObject(value._json)
else -> throw IllegalStateException("Invalid AuthRuleParameters")
else -> throw IllegalStateException("Invalid Parameters")
}
}
}
Expand Down
Loading

0 comments on commit ee5d02e

Please sign in to comment.