diff --git a/courier-java-core/src/main/kotlin/com/courier/models/AwsSns.kt b/courier-java-core/src/main/kotlin/com/courier/models/AwsSns.kt new file mode 100644 index 0000000..b7bfd08 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/AwsSns.kt @@ -0,0 +1,183 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkRequired +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects + +/** + * Routes a push notification through the AWS SNS provider. The target ARN must be nested under + * `aws_sns` — a top-level `target_arn` on the profile is ignored by the provider. + */ +class AwsSns +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val targetArn: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("target_arn") @ExcludeMissing targetArn: JsonField = JsonMissing.of() + ) : this(targetArn, mutableMapOf()) + + /** + * The ARN of the SNS platform endpoint, topic, or application to publish to. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun targetArn(): String = targetArn.getRequired("target_arn") + + /** + * Returns the raw JSON value of [targetArn]. + * + * Unlike [targetArn], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("target_arn") @ExcludeMissing fun _targetArn(): JsonField = targetArn + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [AwsSns]. + * + * The following fields are required: + * ```java + * .targetArn() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AwsSns]. */ + class Builder internal constructor() { + + private var targetArn: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(awsSns: AwsSns) = apply { + targetArn = awsSns.targetArn + additionalProperties = awsSns.additionalProperties.toMutableMap() + } + + /** The ARN of the SNS platform endpoint, topic, or application to publish to. */ + fun targetArn(targetArn: String) = targetArn(JsonField.of(targetArn)) + + /** + * Sets [Builder.targetArn] to an arbitrary JSON value. + * + * You should usually call [Builder.targetArn] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun targetArn(targetArn: JsonField) = apply { this.targetArn = targetArn } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [AwsSns]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .targetArn() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AwsSns = + AwsSns(checkRequired("targetArn", targetArn), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): AwsSns = apply { + if (validated) { + return@apply + } + + targetArn() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (targetArn.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AwsSns && + targetArn == other.targetArn && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(targetArn, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AwsSns{targetArn=$targetArn, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/UserProfile.kt b/courier-java-core/src/main/kotlin/com/courier/models/UserProfile.kt index 77186da..c7f496e 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/UserProfile.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/UserProfile.kt @@ -24,6 +24,7 @@ private constructor( private val address: JsonField
, private val airship: JsonField, private val apn: JsonField, + private val awsSns: JsonField, private val birthdate: JsonField, private val custom: JsonField, private val discord: JsonField, @@ -48,7 +49,6 @@ private constructor( private val profile: JsonField, private val slack: JsonField, private val sub: JsonField, - private val targetArn: JsonField, private val updatedAt: JsonField, private val website: JsonField, private val zoneinfo: JsonField, @@ -62,6 +62,7 @@ private constructor( @ExcludeMissing airship: JsonField = JsonMissing.of(), @JsonProperty("apn") @ExcludeMissing apn: JsonField = JsonMissing.of(), + @JsonProperty("aws_sns") @ExcludeMissing awsSns: JsonField = JsonMissing.of(), @JsonProperty("birthdate") @ExcludeMissing birthdate: JsonField = JsonMissing.of(), @JsonProperty("custom") @ExcludeMissing custom: JsonField = JsonMissing.of(), @JsonProperty("discord") @ExcludeMissing discord: JsonField = JsonMissing.of(), @@ -102,7 +103,6 @@ private constructor( @JsonProperty("profile") @ExcludeMissing profile: JsonField = JsonMissing.of(), @JsonProperty("slack") @ExcludeMissing slack: JsonField = JsonMissing.of(), @JsonProperty("sub") @ExcludeMissing sub: JsonField = JsonMissing.of(), - @JsonProperty("target_arn") @ExcludeMissing targetArn: JsonField = JsonMissing.of(), @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), @JsonProperty("website") @ExcludeMissing website: JsonField = JsonMissing.of(), @JsonProperty("zoneinfo") @ExcludeMissing zoneinfo: JsonField = JsonMissing.of(), @@ -110,6 +110,7 @@ private constructor( address, airship, apn, + awsSns, birthdate, custom, discord, @@ -134,7 +135,6 @@ private constructor( profile, slack, sub, - targetArn, updatedAt, website, zoneinfo, @@ -159,6 +159,15 @@ private constructor( */ fun apn(): Optional = apn.getOptional("apn") + /** + * Routes a push notification through the AWS SNS provider. The target ARN must be nested under + * `aws_sns` — a top-level `target_arn` on the profile is ignored by the provider. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun awsSns(): Optional = awsSns.getOptional("aws_sns") + /** * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -308,12 +317,6 @@ private constructor( */ fun sub(): Optional = sub.getOptional("sub") - /** - * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun targetArn(): Optional = targetArn.getOptional("target_arn") - /** * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -353,6 +356,13 @@ private constructor( */ @JsonProperty("apn") @ExcludeMissing fun _apn(): JsonField = apn + /** + * Returns the raw JSON value of [awsSns]. + * + * Unlike [awsSns], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("aws_sns") @ExcludeMissing fun _awsSns(): JsonField = awsSns + /** * Returns the raw JSON value of [birthdate]. * @@ -534,13 +544,6 @@ private constructor( */ @JsonProperty("sub") @ExcludeMissing fun _sub(): JsonField = sub - /** - * Returns the raw JSON value of [targetArn]. - * - * Unlike [targetArn], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("target_arn") @ExcludeMissing fun _targetArn(): JsonField = targetArn - /** * Returns the raw JSON value of [updatedAt]. * @@ -586,6 +589,7 @@ private constructor( private var address: JsonField
= JsonMissing.of() private var airship: JsonField = JsonMissing.of() private var apn: JsonField = JsonMissing.of() + private var awsSns: JsonField = JsonMissing.of() private var birthdate: JsonField = JsonMissing.of() private var custom: JsonField = JsonMissing.of() private var discord: JsonField = JsonMissing.of() @@ -610,7 +614,6 @@ private constructor( private var profile: JsonField = JsonMissing.of() private var slack: JsonField = JsonMissing.of() private var sub: JsonField = JsonMissing.of() - private var targetArn: JsonField = JsonMissing.of() private var updatedAt: JsonField = JsonMissing.of() private var website: JsonField = JsonMissing.of() private var zoneinfo: JsonField = JsonMissing.of() @@ -621,6 +624,7 @@ private constructor( address = userProfile.address airship = userProfile.airship apn = userProfile.apn + awsSns = userProfile.awsSns birthdate = userProfile.birthdate custom = userProfile.custom discord = userProfile.discord @@ -645,7 +649,6 @@ private constructor( profile = userProfile.profile slack = userProfile.slack sub = userProfile.sub - targetArn = userProfile.targetArn updatedAt = userProfile.updatedAt website = userProfile.website zoneinfo = userProfile.zoneinfo @@ -692,6 +695,23 @@ private constructor( */ fun apn(apn: JsonField) = apply { this.apn = apn } + /** + * Routes a push notification through the AWS SNS provider. The target ARN must be nested + * under `aws_sns` — a top-level `target_arn` on the profile is ignored by the provider. + */ + fun awsSns(awsSns: AwsSns?) = awsSns(JsonField.ofNullable(awsSns)) + + /** Alias for calling [Builder.awsSns] with `awsSns.orElse(null)`. */ + fun awsSns(awsSns: Optional) = awsSns(awsSns.getOrNull()) + + /** + * Sets [Builder.awsSns] to an arbitrary JSON value. + * + * You should usually call [Builder.awsSns] with a well-typed [AwsSns] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun awsSns(awsSns: JsonField) = apply { this.awsSns = awsSns } + fun birthdate(birthdate: String?) = birthdate(JsonField.ofNullable(birthdate)) /** Alias for calling [Builder.birthdate] with `birthdate.orElse(null)`. */ @@ -1117,20 +1137,6 @@ private constructor( */ fun sub(sub: JsonField) = apply { this.sub = sub } - fun targetArn(targetArn: String?) = targetArn(JsonField.ofNullable(targetArn)) - - /** Alias for calling [Builder.targetArn] with `targetArn.orElse(null)`. */ - fun targetArn(targetArn: Optional) = targetArn(targetArn.getOrNull()) - - /** - * Sets [Builder.targetArn] to an arbitrary JSON value. - * - * You should usually call [Builder.targetArn] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun targetArn(targetArn: JsonField) = apply { this.targetArn = targetArn } - fun updatedAt(updatedAt: String?) = updatedAt(JsonField.ofNullable(updatedAt)) /** Alias for calling [Builder.updatedAt] with `updatedAt.orElse(null)`. */ @@ -1200,6 +1206,7 @@ private constructor( address, airship, apn, + awsSns, birthdate, custom, discord, @@ -1224,7 +1231,6 @@ private constructor( profile, slack, sub, - targetArn, updatedAt, website, zoneinfo, @@ -1250,6 +1256,7 @@ private constructor( address().ifPresent { it.validate() } airship().ifPresent { it.validate() } apn() + awsSns().ifPresent { it.validate() } birthdate() custom().ifPresent { it.validate() } discord().ifPresent { it.validate() } @@ -1274,7 +1281,6 @@ private constructor( profile() slack().ifPresent { it.validate() } sub() - targetArn() updatedAt() website() zoneinfo() @@ -1299,6 +1305,7 @@ private constructor( (address.asKnown().getOrNull()?.validity() ?: 0) + (airship.asKnown().getOrNull()?.validity() ?: 0) + (if (apn.asKnown().isPresent) 1 else 0) + + (awsSns.asKnown().getOrNull()?.validity() ?: 0) + (if (birthdate.asKnown().isPresent) 1 else 0) + (custom.asKnown().getOrNull()?.validity() ?: 0) + (discord.asKnown().getOrNull()?.validity() ?: 0) + @@ -1323,7 +1330,6 @@ private constructor( (if (profile.asKnown().isPresent) 1 else 0) + (slack.asKnown().getOrNull()?.validity() ?: 0) + (if (sub.asKnown().isPresent) 1 else 0) + - (if (targetArn.asKnown().isPresent) 1 else 0) + (if (updatedAt.asKnown().isPresent) 1 else 0) + (if (website.asKnown().isPresent) 1 else 0) + (if (zoneinfo.asKnown().isPresent) 1 else 0) @@ -1811,6 +1817,7 @@ private constructor( address == other.address && airship == other.airship && apn == other.apn && + awsSns == other.awsSns && birthdate == other.birthdate && custom == other.custom && discord == other.discord && @@ -1835,7 +1842,6 @@ private constructor( profile == other.profile && slack == other.slack && sub == other.sub && - targetArn == other.targetArn && updatedAt == other.updatedAt && website == other.website && zoneinfo == other.zoneinfo && @@ -1847,6 +1853,7 @@ private constructor( address, airship, apn, + awsSns, birthdate, custom, discord, @@ -1871,7 +1878,6 @@ private constructor( profile, slack, sub, - targetArn, updatedAt, website, zoneinfo, @@ -1882,5 +1888,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "UserProfile{address=$address, airship=$airship, apn=$apn, birthdate=$birthdate, custom=$custom, discord=$discord, email=$email, emailVerified=$emailVerified, expo=$expo, facebookPsid=$facebookPsid, familyName=$familyName, firebaseToken=$firebaseToken, gender=$gender, givenName=$givenName, intercom=$intercom, locale=$locale, middleName=$middleName, msTeams=$msTeams, name=$name, nickname=$nickname, phoneNumber=$phoneNumber, phoneNumberVerified=$phoneNumberVerified, picture=$picture, preferredName=$preferredName, profile=$profile, slack=$slack, sub=$sub, targetArn=$targetArn, updatedAt=$updatedAt, website=$website, zoneinfo=$zoneinfo, additionalProperties=$additionalProperties}" + "UserProfile{address=$address, airship=$airship, apn=$apn, awsSns=$awsSns, birthdate=$birthdate, custom=$custom, discord=$discord, email=$email, emailVerified=$emailVerified, expo=$expo, facebookPsid=$facebookPsid, familyName=$familyName, firebaseToken=$firebaseToken, gender=$gender, givenName=$givenName, intercom=$intercom, locale=$locale, middleName=$middleName, msTeams=$msTeams, name=$name, nickname=$nickname, phoneNumber=$phoneNumber, phoneNumberVerified=$phoneNumberVerified, picture=$picture, preferredName=$preferredName, profile=$profile, slack=$slack, sub=$sub, updatedAt=$updatedAt, website=$website, zoneinfo=$zoneinfo, additionalProperties=$additionalProperties}" } diff --git a/courier-java-core/src/test/kotlin/com/courier/models/AwsSnsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/AwsSnsTest.kt new file mode 100644 index 0000000..c5980eb --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/AwsSnsTest.kt @@ -0,0 +1,29 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models + +import com.courier.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AwsSnsTest { + + @Test + fun create() { + val awsSns = AwsSns.builder().targetArn("target_arn").build() + + assertThat(awsSns.targetArn()).isEqualTo("target_arn") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val awsSns = AwsSns.builder().targetArn("target_arn").build() + + val roundtrippedAwsSns = + jsonMapper.readValue(jsonMapper.writeValueAsString(awsSns), jacksonTypeRef()) + + assertThat(roundtrippedAwsSns).isEqualTo(awsSns) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/UserProfileTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/UserProfileTest.kt index 1089d15..68577dd 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/UserProfileTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/UserProfileTest.kt @@ -31,6 +31,7 @@ internal class UserProfileTest { .build() ) .apn("apn") + .awsSns(AwsSns.builder().targetArn("target_arn").build()) .birthdate("birthdate") .custom( UserProfile.Custom.builder() @@ -75,7 +76,6 @@ internal class UserProfileTest { .build() ) .sub("sub") - .targetArn("target_arn") .updatedAt("updated_at") .website("website") .zoneinfo("zoneinfo") @@ -100,6 +100,7 @@ internal class UserProfileTest { .build() ) assertThat(userProfile.apn()).contains("apn") + assertThat(userProfile.awsSns()).contains(AwsSns.builder().targetArn("target_arn").build()) assertThat(userProfile.birthdate()).contains("birthdate") assertThat(userProfile.custom()) .contains( @@ -157,7 +158,6 @@ internal class UserProfileTest { ) ) assertThat(userProfile.sub()).contains("sub") - assertThat(userProfile.targetArn()).contains("target_arn") assertThat(userProfile.updatedAt()).contains("updated_at") assertThat(userProfile.website()).contains("website") assertThat(userProfile.zoneinfo()).contains("zoneinfo") @@ -185,6 +185,7 @@ internal class UserProfileTest { .build() ) .apn("apn") + .awsSns(AwsSns.builder().targetArn("target_arn").build()) .birthdate("birthdate") .custom( UserProfile.Custom.builder() @@ -229,7 +230,6 @@ internal class UserProfileTest { .build() ) .sub("sub") - .targetArn("target_arn") .updatedAt("updated_at") .website("website") .zoneinfo("zoneinfo")