diff --git a/.release-please-manifest.json b/.release-please-manifest.json index f425d970..112e32b3 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "5.5.0" + ".": "6.0.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 1629f07d..d004027c 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 45 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-05a1c7485ea6dd75ad2fb1a0628570d88a3e7c4f1e1ecad433711c78deae50e6.yml -openapi_spec_hash: 6d6014d50e18c98219b496bb2a5dab1d +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-f09e5f2c555d7ee764478b7bc73e92cd21f403d6ec189be14574c8367bc131ce.yml +openapi_spec_hash: bd0a8e001f14132c105992d40149909a config_hash: 53778a0b839c4f6ad34fbba051f5e8a6 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dae2b9c..38ebf293 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,41 @@ # Changelog +## 6.0.0 (2025-05-08) + +Full Changelog: [v5.5.0...v6.0.0](https://github.com/Finch-API/finch-api-java/compare/v5.5.0...v6.0.0) + +### ⚠ BREAKING CHANGES + +* **client:** don't require end-users to specify constants +* **client:** **Migration:** Builder methods that previously accepted a single possible value no longer need to be called. + +### Features + +* **api:** api update ([59c1d39](https://github.com/Finch-API/finch-api-java/commit/59c1d397d17589eec93f6c1dab760aaa1d548188)) +* **api:** api update ([2aa8003](https://github.com/Finch-API/finch-api-java/commit/2aa8003c7dfeb9be0a15a57d1c46931a7f85ab3e)) +* **api:** api update ([988e834](https://github.com/Finch-API/finch-api-java/commit/988e8348cd1d2e31f5e2aaa91adfc835ae973ba0)) +* **api:** api update ([b98adb3](https://github.com/Finch-API/finch-api-java/commit/b98adb325de5d5b7220bbeac1f1e5fd56f7a0c13)) +* **api:** api update ([f816b28](https://github.com/Finch-API/finch-api-java/commit/f816b281bd01e85660f613f14431a43eb761a221)) +* **api:** api update ([d399e4f](https://github.com/Finch-API/finch-api-java/commit/d399e4f9395f2e84f6a97399ae6f0fdcbc34d7cd)) +* **api:** api update ([cc2b828](https://github.com/Finch-API/finch-api-java/commit/cc2b8288f7c3ce5bc62e7ca074fd53fc6f05e253)) +* **api:** api update ([a9fefbc](https://github.com/Finch-API/finch-api-java/commit/a9fefbc485cfa35d7c34aa409333a7b2e244f26a)) +* **api:** api update ([9e451d0](https://github.com/Finch-API/finch-api-java/commit/9e451d0ea744078d1c4f10c878a950ca3719237b)) +* **api:** api update ([f45fb21](https://github.com/Finch-API/finch-api-java/commit/f45fb2151509dd96e2630b94ed4b3a1f3f711439)) +* **api:** api update ([43c21f7](https://github.com/Finch-API/finch-api-java/commit/43c21f75d63053a888c4ba99dd63847b145bf360)) +* **api:** api update ([35e522b](https://github.com/Finch-API/finch-api-java/commit/35e522ba3ad911b49f41ad4b62f1ddc3257dbcd2)) +* **api:** api update ([70708d7](https://github.com/Finch-API/finch-api-java/commit/70708d78bc704b34f936e835b614e54c87c2db03)) +* **api:** api update ([f8988d7](https://github.com/Finch-API/finch-api-java/commit/f8988d7fc959241b683da19b068c95a8ac023e24)) +* **api:** api update ([53c3147](https://github.com/Finch-API/finch-api-java/commit/53c31470ca6f0cf5985f8ebd60446f8f08e84913)) +* **api:** api update ([30df955](https://github.com/Finch-API/finch-api-java/commit/30df955523928c30ef0e29f1154ff5fee88d80d1)) +* **api:** api update ([79e067e](https://github.com/Finch-API/finch-api-java/commit/79e067e9790c16095a9a81cea65fb500c6f4aea6)) +* **client:** don't require end-users to specify constants ([055d459](https://github.com/Finch-API/finch-api-java/commit/055d4597de3f260537ccfa65a8f094e9df39bebb)) + + +### Chores + +* **internal:** remove flaky `-Xbackend-threads=0` option ([4271051](https://github.com/Finch-API/finch-api-java/commit/4271051bb2d5b34d55418363f2e8f958a3688dd5)) +* **internal:** update java toolchain ([0242272](https://github.com/Finch-API/finch-api-java/commit/02422720923c2ec5b5348b0c7e90657433015847)) + ## 5.5.0 (2025-04-23) Full Changelog: [v5.4.0...v5.5.0](https://github.com/Finch-API/finch-api-java/compare/v5.4.0...v5.5.0) diff --git a/README.md b/README.md index fc5a3b6f..fe0a5e8d 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.tryfinch.api/finch-java)](https://central.sonatype.com/artifact/com.tryfinch.api/finch-java/5.5.0) -[![javadoc](https://javadoc.io/badge2/com.tryfinch.api/finch-java/5.5.0/javadoc.svg)](https://javadoc.io/doc/com.tryfinch.api/finch-java/5.5.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.tryfinch.api/finch-java)](https://central.sonatype.com/artifact/com.tryfinch.api/finch-java/6.0.0) +[![javadoc](https://javadoc.io/badge2/com.tryfinch.api/finch-java/6.0.0/javadoc.svg)](https://javadoc.io/doc/com.tryfinch.api/finch-java/6.0.0) @@ -15,7 +15,7 @@ It is generated with [Stainless](https://www.stainless.com/). -The REST API documentation can be found on [developer.tryfinch.com](https://developer.tryfinch.com/). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.tryfinch.api/finch-java/5.5.0). +The REST API documentation can be found on [developer.tryfinch.com](https://developer.tryfinch.com/). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.tryfinch.api/finch-java/6.0.0). @@ -26,7 +26,7 @@ The REST API documentation can be found on [developer.tryfinch.com](https://deve ### Gradle ```kotlin -implementation("com.tryfinch.api:finch-java:5.5.0") +implementation("com.tryfinch.api:finch-java:6.0.0") ``` ### Maven @@ -35,7 +35,7 @@ implementation("com.tryfinch.api:finch-java:5.5.0") com.tryfinch.api finch-java - 5.5.0 + 6.0.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index c8fe62a1..dcfcd84d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.tryfinch.api" - version = "5.5.0" // x-release-please-version + version = "6.0.0" // x-release-please-version } subprojects { diff --git a/buildSrc/src/main/kotlin/finch.java.gradle.kts b/buildSrc/src/main/kotlin/finch.java.gradle.kts index e39d9ac6..dfbacb86 100644 --- a/buildSrc/src/main/kotlin/finch.java.gradle.kts +++ b/buildSrc/src/main/kotlin/finch.java.gradle.kts @@ -21,7 +21,7 @@ configure { java { toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) + languageVersion.set(JavaLanguageVersion.of(21)) } sourceCompatibility = JavaVersion.VERSION_1_8 diff --git a/buildSrc/src/main/kotlin/finch.kotlin.gradle.kts b/buildSrc/src/main/kotlin/finch.kotlin.gradle.kts index f274b11f..f3f20e2b 100644 --- a/buildSrc/src/main/kotlin/finch.kotlin.gradle.kts +++ b/buildSrc/src/main/kotlin/finch.kotlin.gradle.kts @@ -19,8 +19,6 @@ kotlin { // Suppress deprecation warnings because we may still reference and test deprecated members. // TODO: Replace with `-Xsuppress-warning=DEPRECATION` once we use Kotlin compiler 2.1.0+. "-nowarn", - // Use as many threads as there are CPU cores on the machine for compilation. - "-Xbackend-threads=0", ) jvmTarget.set(JvmTarget.JVM_1_8) languageVersion.set(KotlinVersion.KOTLIN_1_8) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Company.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Company.kt index 19928fb7..647a3af3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Company.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Company.kt @@ -692,18 +692,29 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Account]. */ + /** + * Returns a mutable builder for constructing an instance of [Account]. + * + * The following fields are required: + * ```java + * .accountName() + * .accountNumber() + * .accountType() + * .institutionName() + * .routingNumber() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Account]. */ class Builder internal constructor() { - private var accountName: JsonField = JsonMissing.of() - private var accountNumber: JsonField = JsonMissing.of() - private var accountType: JsonField = JsonMissing.of() - private var institutionName: JsonField = JsonMissing.of() - private var routingNumber: JsonField = JsonMissing.of() + private var accountName: JsonField? = null + private var accountNumber: JsonField? = null + private var accountType: JsonField? = null + private var institutionName: JsonField? = null + private var routingNumber: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -835,14 +846,25 @@ private constructor( * Returns an immutable instance of [Account]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .accountName() + * .accountNumber() + * .accountType() + * .institutionName() + * .routingNumber() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Account = Account( - accountName, - accountNumber, - accountType, - institutionName, - routingNumber, + checkRequired("accountName", accountName), + checkRequired("accountNumber", accountNumber), + checkRequired("accountType", accountType), + checkRequired("institutionName", institutionName), + checkRequired("routingNumber", routingNumber), additionalProperties.toMutableMap(), ) } @@ -1091,15 +1113,23 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Department]. */ + /** + * Returns a mutable builder for constructing an instance of [Department]. + * + * The following fields are required: + * ```java + * .name() + * .parent() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Department]. */ class Builder internal constructor() { - private var name: JsonField = JsonMissing.of() - private var parent: JsonField = JsonMissing.of() + private var name: JsonField? = null + private var parent: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -1162,8 +1192,21 @@ private constructor( * Returns an immutable instance of [Department]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .parent() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Department = Department(name, parent, additionalProperties.toMutableMap()) + fun build(): Department = + Department( + checkRequired("name", name), + checkRequired("parent", parent), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1238,14 +1281,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Parent]. */ + /** + * Returns a mutable builder for constructing an instance of [Parent]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Parent]. */ class Builder internal constructor() { - private var name: JsonField = JsonMissing.of() + private var name: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -1295,8 +1345,16 @@ private constructor( * Returns an immutable instance of [Parent]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Parent = Parent(name, additionalProperties.toMutableMap()) + fun build(): Parent = + Parent(checkRequired("name", name), additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -1420,15 +1478,23 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Entity]. */ + /** + * Returns a mutable builder for constructing an instance of [Entity]. + * + * The following fields are required: + * ```java + * .subtype() + * .type() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Entity]. */ class Builder internal constructor() { - private var subtype: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() + private var subtype: JsonField? = null + private var type: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -1491,8 +1557,21 @@ private constructor( * Returns an immutable instance of [Entity]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .subtype() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Entity = Entity(subtype, type, additionalProperties.toMutableMap()) + fun build(): Entity = + Entity( + checkRequired("subtype", subtype), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/CompanyBenefit.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/CompanyBenefit.kt index bc621dbe..2ece80bf 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/CompanyBenefit.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/CompanyBenefit.kt @@ -6,11 +6,14 @@ 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 com.tryfinch.api.core.Enum import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue +import com.tryfinch.api.core.checkKnown import com.tryfinch.api.core.checkRequired +import com.tryfinch.api.core.toImmutable import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects @@ -20,6 +23,7 @@ import kotlin.jvm.optionals.getOrNull class CompanyBenefit private constructor( private val benefitId: JsonField, + private val companyContribution: JsonField, private val description: JsonField, private val frequency: JsonField, private val type: JsonField, @@ -29,6 +33,9 @@ private constructor( @JsonCreator private constructor( @JsonProperty("benefit_id") @ExcludeMissing benefitId: JsonField = JsonMissing.of(), + @JsonProperty("company_contribution") + @ExcludeMissing + companyContribution: JsonField = JsonMissing.of(), @JsonProperty("description") @ExcludeMissing description: JsonField = JsonMissing.of(), @@ -36,7 +43,7 @@ private constructor( @ExcludeMissing frequency: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(benefitId, description, frequency, type, mutableMapOf()) + ) : this(benefitId, companyContribution, description, frequency, type, mutableMapOf()) /** * The id of the benefit. @@ -46,6 +53,15 @@ private constructor( */ fun benefitId(): String = benefitId.getRequired("benefit_id") + /** + * The company match for this benefit. + * + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun companyContribution(): Optional = + companyContribution.getOptional("company_contribution") + /** * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -75,6 +91,16 @@ private constructor( */ @JsonProperty("benefit_id") @ExcludeMissing fun _benefitId(): JsonField = benefitId + /** + * Returns the raw JSON value of [companyContribution]. + * + * Unlike [companyContribution], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("company_contribution") + @ExcludeMissing + fun _companyContribution(): JsonField = companyContribution + /** * Returns the raw JSON value of [description]. * @@ -118,6 +144,7 @@ private constructor( * The following fields are required: * ```java * .benefitId() + * .companyContribution() * .description() * .frequency() * .type() @@ -130,6 +157,7 @@ private constructor( class Builder internal constructor() { private var benefitId: JsonField? = null + private var companyContribution: JsonField? = null private var description: JsonField? = null private var frequency: JsonField? = null private var type: JsonField? = null @@ -138,6 +166,7 @@ private constructor( @JvmSynthetic internal fun from(companyBenefit: CompanyBenefit) = apply { benefitId = companyBenefit.benefitId + companyContribution = companyBenefit.companyContribution description = companyBenefit.description frequency = companyBenefit.frequency type = companyBenefit.type @@ -156,6 +185,28 @@ private constructor( */ fun benefitId(benefitId: JsonField) = apply { this.benefitId = benefitId } + /** The company match for this benefit. */ + fun companyContribution(companyContribution: BenefitCompanyMatchContribution?) = + companyContribution(JsonField.ofNullable(companyContribution)) + + /** + * Alias for calling [Builder.companyContribution] with `companyContribution.orElse(null)`. + */ + fun companyContribution(companyContribution: Optional) = + companyContribution(companyContribution.getOrNull()) + + /** + * Sets [Builder.companyContribution] to an arbitrary JSON value. + * + * You should usually call [Builder.companyContribution] with a well-typed + * [BenefitCompanyMatchContribution] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun companyContribution(companyContribution: JsonField) = + apply { + this.companyContribution = companyContribution + } + fun description(description: String?) = description(JsonField.ofNullable(description)) /** Alias for calling [Builder.description] with `description.orElse(null)`. */ @@ -227,6 +278,7 @@ private constructor( * The following fields are required: * ```java * .benefitId() + * .companyContribution() * .description() * .frequency() * .type() @@ -237,6 +289,7 @@ private constructor( fun build(): CompanyBenefit = CompanyBenefit( checkRequired("benefitId", benefitId), + checkRequired("companyContribution", companyContribution), checkRequired("description", description), checkRequired("frequency", frequency), checkRequired("type", type), @@ -252,6 +305,7 @@ private constructor( } benefitId() + companyContribution().ifPresent { it.validate() } description() frequency().ifPresent { it.validate() } type().ifPresent { it.validate() } @@ -274,24 +328,515 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (benefitId.asKnown().isPresent) 1 else 0) + + (companyContribution.asKnown().getOrNull()?.validity() ?: 0) + (if (description.asKnown().isPresent) 1 else 0) + (frequency.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + /** The company match for this benefit. */ + class BenefitCompanyMatchContribution + private constructor( + private val tiers: JsonField>, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(tiers, type, mutableMapOf()) + + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tiers(): Optional> = tiers.getOptional("tiers") + + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [tiers]. + * + * Unlike [tiers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tiers") @ExcludeMissing fun _tiers(): JsonField> = tiers + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @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 + * [BenefitCompanyMatchContribution]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BenefitCompanyMatchContribution]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(benefitCompanyMatchContribution: BenefitCompanyMatchContribution) = + apply { + tiers = benefitCompanyMatchContribution.tiers.map { it.toMutableList() } + type = benefitCompanyMatchContribution.type + additionalProperties = + benefitCompanyMatchContribution.additionalProperties.toMutableMap() + } + + fun tiers(tiers: List) = tiers(JsonField.of(tiers)) + + /** + * Sets [Builder.tiers] to an arbitrary JSON value. + * + * You should usually call [Builder.tiers] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tiers(tiers: JsonField>) = apply { + this.tiers = tiers.map { it.toMutableList() } + } + + /** + * Adds a single [Tier] to [tiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTier(tier: Tier) = apply { + tiers = + (tiers ?: JsonField.of(mutableListOf())).also { + checkKnown("tiers", it).add(tier) + } + } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonField) = apply { this.type = type } + + 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 [BenefitCompanyMatchContribution]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BenefitCompanyMatchContribution = + BenefitCompanyMatchContribution( + (tiers ?: JsonMissing.of()).map { it.toImmutable() }, + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BenefitCompanyMatchContribution = apply { + if (validated) { + return@apply + } + + tiers().ifPresent { it.forEach { it.validate() } } + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 = + (tiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Tier + private constructor( + private val match: JsonField, + private val threshold: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("match") @ExcludeMissing match: JsonField = JsonMissing.of(), + @JsonProperty("threshold") + @ExcludeMissing + threshold: JsonField = JsonMissing.of(), + ) : this(match, threshold, mutableMapOf()) + + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun match(): Optional = match.getOptional("match") + + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun threshold(): Optional = threshold.getOptional("threshold") + + /** + * Returns the raw JSON value of [match]. + * + * Unlike [match], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("match") @ExcludeMissing fun _match(): JsonField = match + + /** + * Returns the raw JSON value of [threshold]. + * + * Unlike [threshold], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("threshold") @ExcludeMissing fun _threshold(): JsonField = threshold + + @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 [Tier]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var match: JsonField = JsonMissing.of() + private var threshold: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(tier: Tier) = apply { + match = tier.match + threshold = tier.threshold + additionalProperties = tier.additionalProperties.toMutableMap() + } + + fun match(match: Long) = match(JsonField.of(match)) + + /** + * Sets [Builder.match] to an arbitrary JSON value. + * + * You should usually call [Builder.match] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun match(match: JsonField) = apply { this.match = match } + + fun threshold(threshold: Long) = threshold(JsonField.of(threshold)) + + /** + * Sets [Builder.threshold] to an arbitrary JSON value. + * + * You should usually call [Builder.threshold] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun threshold(threshold: JsonField) = apply { this.threshold = threshold } + + 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 [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Tier = Tier(match, threshold, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + match() + threshold() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 (match.asKnown().isPresent) 1 else 0) + + (if (threshold.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Tier && match == other.match && threshold == other.threshold && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(match, threshold, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{match=$match, threshold=$threshold, additionalProperties=$additionalProperties}" + } + + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MATCH = of("match") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + MATCH + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MATCH, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MATCH -> Value.MATCH + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws FinchInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + MATCH -> Known.MATCH + else -> throw FinchInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws FinchInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + FinchInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BenefitCompanyMatchContribution && tiers == other.tiers && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(tiers, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BenefitCompanyMatchContribution{tiers=$tiers, type=$type, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is CompanyBenefit && benefitId == other.benefitId && description == other.description && frequency == other.frequency && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is CompanyBenefit && benefitId == other.benefitId && companyContribution == other.companyContribution && description == other.description && frequency == other.frequency && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(benefitId, description, frequency, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(benefitId, companyContribution, description, frequency, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "CompanyBenefit{benefitId=$benefitId, description=$description, frequency=$frequency, type=$type, additionalProperties=$additionalProperties}" + "CompanyBenefit{benefitId=$benefitId, companyContribution=$companyContribution, description=$description, frequency=$frequency, type=$type, additionalProperties=$additionalProperties}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/EmploymentData.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/EmploymentData.kt index b90cc44a..d62ad375 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/EmploymentData.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/EmploymentData.kt @@ -6,12 +6,24 @@ 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 com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.tryfinch.api.core.BaseDeserializer +import com.tryfinch.api.core.BaseSerializer import com.tryfinch.api.core.Enum import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue +import com.tryfinch.api.core.allMaxBy import com.tryfinch.api.core.checkKnown +import com.tryfinch.api.core.checkRequired +import com.tryfinch.api.core.getOrThrow import com.tryfinch.api.core.toImmutable import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections @@ -19,959 +31,595 @@ import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull +@JsonDeserialize(using = EmploymentData.Deserializer::class) +@JsonSerialize(using = EmploymentData.Serializer::class) class EmploymentData private constructor( - private val id: JsonField, - private val classCode: JsonField, - private val customFields: JsonField>, - private val department: JsonField, - private val employment: JsonField, - private val employmentStatus: JsonField, - private val endDate: JsonField, - private val firstName: JsonField, - private val income: JsonField, - private val incomeHistory: JsonField>, - private val isActive: JsonField, - private val lastName: JsonField, - private val latestRehireDate: JsonField, - private val location: JsonField, - private val manager: JsonField, - private val middleName: JsonField, - private val sourceId: JsonField, - private val startDate: JsonField, - private val title: JsonField, - private val workId: JsonField, - private val additionalProperties: MutableMap, + private val unionMember0: UnionMember0? = null, + private val batchError: BatchError? = null, + private val _json: JsonValue? = null, ) { - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), - @JsonProperty("class_code") @ExcludeMissing classCode: JsonField = JsonMissing.of(), - @JsonProperty("custom_fields") - @ExcludeMissing - customFields: JsonField> = JsonMissing.of(), - @JsonProperty("department") - @ExcludeMissing - department: JsonField = JsonMissing.of(), - @JsonProperty("employment") - @ExcludeMissing - employment: JsonField = JsonMissing.of(), - @JsonProperty("employment_status") - @ExcludeMissing - employmentStatus: JsonField = JsonMissing.of(), - @JsonProperty("end_date") @ExcludeMissing endDate: JsonField = JsonMissing.of(), - @JsonProperty("first_name") @ExcludeMissing firstName: JsonField = JsonMissing.of(), - @JsonProperty("income") @ExcludeMissing income: JsonField = JsonMissing.of(), - @JsonProperty("income_history") - @ExcludeMissing - incomeHistory: JsonField> = JsonMissing.of(), - @JsonProperty("is_active") @ExcludeMissing isActive: JsonField = JsonMissing.of(), - @JsonProperty("last_name") @ExcludeMissing lastName: JsonField = JsonMissing.of(), - @JsonProperty("latest_rehire_date") - @ExcludeMissing - latestRehireDate: JsonField = JsonMissing.of(), - @JsonProperty("location") @ExcludeMissing location: JsonField = JsonMissing.of(), - @JsonProperty("manager") @ExcludeMissing manager: JsonField = JsonMissing.of(), - @JsonProperty("middle_name") - @ExcludeMissing - middleName: JsonField = JsonMissing.of(), - @JsonProperty("source_id") @ExcludeMissing sourceId: JsonField = JsonMissing.of(), - @JsonProperty("start_date") @ExcludeMissing startDate: JsonField = JsonMissing.of(), - @JsonProperty("title") @ExcludeMissing title: JsonField = JsonMissing.of(), - @JsonProperty("work_id") @ExcludeMissing workId: JsonField = JsonMissing.of(), - ) : this( - id, - classCode, - customFields, - department, - employment, - employmentStatus, - endDate, - firstName, - income, - incomeHistory, - isActive, - lastName, - latestRehireDate, - location, - manager, - middleName, - sourceId, - startDate, - title, - workId, - mutableMapOf(), - ) - - /** - * A stable Finch `id` (UUID v4) for an individual in the company. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun id(): Optional = id.getOptional("id") - - /** - * Worker's compensation classification code for this employee - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun classCode(): Optional = classCode.getOptional("class_code") - - /** - * Custom fields for the individual. These are fields which are defined by the employer in the - * system. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun customFields(): Optional> = customFields.getOptional("custom_fields") - - /** - * The department object. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun department(): Optional = department.getOptional("department") - - /** - * The employment object. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun employment(): Optional = employment.getOptional("employment") - - /** - * The detailed employment status of the individual. Available options: `active`, `deceased`, - * `leave`, `onboarding`, `prehire`, `retired`, `terminated`. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun employmentStatus(): Optional = - employmentStatus.getOptional("employment_status") - - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun endDate(): Optional = endDate.getOptional("end_date") - - /** - * The legal first name of the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun firstName(): Optional = firstName.getOptional("first_name") - - /** - * The employee's income as reported by the provider. This may not always be annualized income, - * but may be in units of bi-weekly, semi-monthly, daily, etc, depending on what information the - * provider returns. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun income(): Optional = income.getOptional("income") - - /** - * The array of income history. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun incomeHistory(): Optional> = incomeHistory.getOptional("income_history") - - /** - * `true` if the individual an an active employee or contractor at the company. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun isActive(): Optional = isActive.getOptional("is_active") - - /** - * The legal last name of the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun lastName(): Optional = lastName.getOptional("last_name") - - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun latestRehireDate(): Optional = latestRehireDate.getOptional("latest_rehire_date") - - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun location(): Optional = location.getOptional("location") + fun unionMember0(): Optional = Optional.ofNullable(unionMember0) - /** - * The manager object representing the manager of the individual within the org. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun manager(): Optional = manager.getOptional("manager") + fun batchError(): Optional = Optional.ofNullable(batchError) - /** - * The legal middle name of the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun middleName(): Optional = middleName.getOptional("middle_name") + fun isUnionMember0(): Boolean = unionMember0 != null - /** - * The source system's unique employment identifier for this individual - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun sourceId(): Optional = sourceId.getOptional("source_id") + fun isBatchError(): Boolean = batchError != null - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun startDate(): Optional = startDate.getOptional("start_date") + fun asUnionMember0(): UnionMember0 = unionMember0.getOrThrow("unionMember0") - /** - * The current title of the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun title(): Optional = title.getOptional("title") + fun asBatchError(): BatchError = batchError.getOrThrow("batchError") - /** - * This field is deprecated in favour of `source_id` - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - @Deprecated("deprecated") fun workId(): Optional = workId.getOptional("work_id") + fun _json(): Optional = Optional.ofNullable(_json) - /** - * Returns the raw JSON value of [id]. - * - * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + fun accept(visitor: Visitor): T = + when { + unionMember0 != null -> visitor.visitUnionMember0(unionMember0) + batchError != null -> visitor.visitBatchError(batchError) + else -> visitor.unknown(_json) + } - /** - * Returns the raw JSON value of [classCode]. - * - * Unlike [classCode], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("class_code") @ExcludeMissing fun _classCode(): JsonField = classCode + private var validated: Boolean = false - /** - * Returns the raw JSON value of [customFields]. - * - * Unlike [customFields], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("custom_fields") - @ExcludeMissing - fun _customFields(): JsonField> = customFields + fun validate(): EmploymentData = apply { + if (validated) { + return@apply + } - /** - * Returns the raw JSON value of [department]. - * - * Unlike [department], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("department") - @ExcludeMissing - fun _department(): JsonField = department + accept( + object : Visitor { + override fun visitUnionMember0(unionMember0: UnionMember0) { + unionMember0.validate() + } - /** - * Returns the raw JSON value of [employment]. - * - * Unlike [employment], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("employment") - @ExcludeMissing - fun _employment(): JsonField = employment + override fun visitBatchError(batchError: BatchError) { + batchError.validate() + } + } + ) + validated = true + } - /** - * Returns the raw JSON value of [employmentStatus]. - * - * Unlike [employmentStatus], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("employment_status") - @ExcludeMissing - fun _employmentStatus(): JsonField = employmentStatus + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + false + } /** - * Returns the raw JSON value of [endDate]. + * Returns a score indicating how many valid values are contained in this object recursively. * - * Unlike [endDate], this method doesn't throw if the JSON field has an unexpected type. + * Used for best match union deserialization. */ - @JsonProperty("end_date") @ExcludeMissing fun _endDate(): JsonField = endDate + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitUnionMember0(unionMember0: UnionMember0) = unionMember0.validity() - /** - * Returns the raw JSON value of [firstName]. - * - * Unlike [firstName], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("first_name") @ExcludeMissing fun _firstName(): JsonField = firstName + override fun visitBatchError(batchError: BatchError) = batchError.validity() - /** - * Returns the raw JSON value of [income]. - * - * Unlike [income], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("income") @ExcludeMissing fun _income(): JsonField = income + override fun unknown(json: JsonValue?) = 0 + } + ) - /** - * Returns the raw JSON value of [incomeHistory]. - * - * Unlike [incomeHistory], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("income_history") - @ExcludeMissing - fun _incomeHistory(): JsonField> = incomeHistory + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * Returns the raw JSON value of [isActive]. - * - * Unlike [isActive], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("is_active") @ExcludeMissing fun _isActive(): JsonField = isActive + return /* spotless:off */ other is EmploymentData && unionMember0 == other.unionMember0 && batchError == other.batchError /* spotless:on */ + } - /** - * Returns the raw JSON value of [lastName]. - * - * Unlike [lastName], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("last_name") @ExcludeMissing fun _lastName(): JsonField = lastName + override fun hashCode(): Int = /* spotless:off */ Objects.hash(unionMember0, batchError) /* spotless:on */ - /** - * Returns the raw JSON value of [latestRehireDate]. - * - * Unlike [latestRehireDate], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("latest_rehire_date") - @ExcludeMissing - fun _latestRehireDate(): JsonField = latestRehireDate + override fun toString(): String = + when { + unionMember0 != null -> "EmploymentData{unionMember0=$unionMember0}" + batchError != null -> "EmploymentData{batchError=$batchError}" + _json != null -> "EmploymentData{_unknown=$_json}" + else -> throw IllegalStateException("Invalid EmploymentData") + } - /** - * Returns the raw JSON value of [location]. - * - * Unlike [location], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("location") @ExcludeMissing fun _location(): JsonField = location + companion object { - /** - * Returns the raw JSON value of [manager]. - * - * Unlike [manager], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("manager") @ExcludeMissing fun _manager(): JsonField = manager + @JvmStatic + fun ofUnionMember0(unionMember0: UnionMember0) = EmploymentData(unionMember0 = unionMember0) - /** - * Returns the raw JSON value of [middleName]. - * - * Unlike [middleName], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("middle_name") @ExcludeMissing fun _middleName(): JsonField = middleName + @JvmStatic + fun ofBatchError(batchError: BatchError) = EmploymentData(batchError = batchError) + } /** - * Returns the raw JSON value of [sourceId]. - * - * Unlike [sourceId], this method doesn't throw if the JSON field has an unexpected type. + * An interface that defines how to map each variant of [EmploymentData] to a value of type [T]. */ - @JsonProperty("source_id") @ExcludeMissing fun _sourceId(): JsonField = sourceId + interface Visitor { - /** - * Returns the raw JSON value of [startDate]. - * - * Unlike [startDate], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("start_date") @ExcludeMissing fun _startDate(): JsonField = startDate + fun visitUnionMember0(unionMember0: UnionMember0): T - /** - * Returns the raw JSON value of [title]. - * - * Unlike [title], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("title") @ExcludeMissing fun _title(): JsonField = title + fun visitBatchError(batchError: BatchError): T - /** - * Returns the raw JSON value of [workId]. - * - * Unlike [workId], this method doesn't throw if the JSON field has an unexpected type. - */ - @Deprecated("deprecated") - @JsonProperty("work_id") - @ExcludeMissing - fun _workId(): JsonField = workId - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) + /** + * Maps an unknown variant of [EmploymentData] to a value of type [T]. + * + * An instance of [EmploymentData] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on an older + * version than the API, then the API may respond with new variants that the SDK is unaware + * of. + * + * @throws FinchInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw FinchInvalidDataException("Unknown EmploymentData: $json") + } } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - fun toBuilder() = Builder().from(this) - - companion object { - - /** Returns a mutable builder for constructing an instance of [EmploymentData]. */ - @JvmStatic fun builder() = Builder() + internal class Deserializer : BaseDeserializer(EmploymentData::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): EmploymentData { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + EmploymentData(unionMember0 = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + EmploymentData(batchError = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with all + // the possible variants (e.g. deserializing from boolean). + 0 -> EmploymentData(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } } - /** A builder for [EmploymentData]. */ - class Builder internal constructor() { - - private var id: JsonField = JsonMissing.of() - private var classCode: JsonField = JsonMissing.of() - private var customFields: JsonField>? = null - private var department: JsonField = JsonMissing.of() - private var employment: JsonField = JsonMissing.of() - private var employmentStatus: JsonField = JsonMissing.of() - private var endDate: JsonField = JsonMissing.of() - private var firstName: JsonField = JsonMissing.of() - private var income: JsonField = JsonMissing.of() - private var incomeHistory: JsonField>? = null - private var isActive: JsonField = JsonMissing.of() - private var lastName: JsonField = JsonMissing.of() - private var latestRehireDate: JsonField = JsonMissing.of() - private var location: JsonField = JsonMissing.of() - private var manager: JsonField = JsonMissing.of() - private var middleName: JsonField = JsonMissing.of() - private var sourceId: JsonField = JsonMissing.of() - private var startDate: JsonField = JsonMissing.of() - private var title: JsonField = JsonMissing.of() - private var workId: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(employmentData: EmploymentData) = apply { - id = employmentData.id - classCode = employmentData.classCode - customFields = employmentData.customFields.map { it.toMutableList() } - department = employmentData.department - employment = employmentData.employment - employmentStatus = employmentData.employmentStatus - endDate = employmentData.endDate - firstName = employmentData.firstName - income = employmentData.income - incomeHistory = employmentData.incomeHistory.map { it.toMutableList() } - isActive = employmentData.isActive - lastName = employmentData.lastName - latestRehireDate = employmentData.latestRehireDate - location = employmentData.location - manager = employmentData.manager - middleName = employmentData.middleName - sourceId = employmentData.sourceId - startDate = employmentData.startDate - title = employmentData.title - workId = employmentData.workId - additionalProperties = employmentData.additionalProperties.toMutableMap() + internal class Serializer : BaseSerializer(EmploymentData::class) { + + override fun serialize( + value: EmploymentData, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.unionMember0 != null -> generator.writeObject(value.unionMember0) + value.batchError != null -> generator.writeObject(value.batchError) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid EmploymentData") + } } + } + + class UnionMember0 + private constructor( + private val id: JsonField, + private val classCode: JsonField, + private val customFields: JsonField>, + private val department: JsonField, + private val employment: JsonField, + private val employmentStatus: JsonField, + private val endDate: JsonField, + private val firstName: JsonField, + private val isActive: JsonField, + private val lastName: JsonField, + private val latestRehireDate: JsonField, + private val location: JsonField, + private val manager: JsonField, + private val middleName: JsonField, + private val sourceId: JsonField, + private val startDate: JsonField, + private val title: JsonField, + private val workId: JsonField, + private val income: JsonField, + private val incomeHistory: JsonField>, + private val additionalProperties: MutableMap, + ) { - /** A stable Finch `id` (UUID v4) for an individual in the company. */ - fun id(id: String) = id(JsonField.of(id)) + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("class_code") + @ExcludeMissing + classCode: JsonField = JsonMissing.of(), + @JsonProperty("custom_fields") + @ExcludeMissing + customFields: JsonField> = JsonMissing.of(), + @JsonProperty("department") + @ExcludeMissing + department: JsonField = JsonMissing.of(), + @JsonProperty("employment") + @ExcludeMissing + employment: JsonField = JsonMissing.of(), + @JsonProperty("employment_status") + @ExcludeMissing + employmentStatus: JsonField = JsonMissing.of(), + @JsonProperty("end_date") @ExcludeMissing endDate: JsonField = JsonMissing.of(), + @JsonProperty("first_name") + @ExcludeMissing + firstName: JsonField = JsonMissing.of(), + @JsonProperty("is_active") + @ExcludeMissing + isActive: JsonField = JsonMissing.of(), + @JsonProperty("last_name") + @ExcludeMissing + lastName: JsonField = JsonMissing.of(), + @JsonProperty("latest_rehire_date") + @ExcludeMissing + latestRehireDate: JsonField = JsonMissing.of(), + @JsonProperty("location") + @ExcludeMissing + location: JsonField = JsonMissing.of(), + @JsonProperty("manager") @ExcludeMissing manager: JsonField = JsonMissing.of(), + @JsonProperty("middle_name") + @ExcludeMissing + middleName: JsonField = JsonMissing.of(), + @JsonProperty("source_id") + @ExcludeMissing + sourceId: JsonField = JsonMissing.of(), + @JsonProperty("start_date") + @ExcludeMissing + startDate: JsonField = JsonMissing.of(), + @JsonProperty("title") @ExcludeMissing title: JsonField = JsonMissing.of(), + @JsonProperty("work_id") @ExcludeMissing workId: JsonField = JsonMissing.of(), + @JsonProperty("income") @ExcludeMissing income: JsonField = JsonMissing.of(), + @JsonProperty("income_history") + @ExcludeMissing + incomeHistory: JsonField> = JsonMissing.of(), + ) : this( + id, + classCode, + customFields, + department, + employment, + employmentStatus, + endDate, + firstName, + isActive, + lastName, + latestRehireDate, + location, + manager, + middleName, + sourceId, + startDate, + title, + workId, + income, + incomeHistory, + mutableMapOf(), + ) /** - * Sets [Builder.id] to an arbitrary JSON value. + * A stable Finch `id` (UUID v4) for an individual in the company. * - * You should usually call [Builder.id] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws FinchInvalidDataException 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 id(id: JsonField) = apply { this.id = id } - - /** Worker's compensation classification code for this employee */ - fun classCode(classCode: String?) = classCode(JsonField.ofNullable(classCode)) - - /** Alias for calling [Builder.classCode] with `classCode.orElse(null)`. */ - fun classCode(classCode: Optional) = classCode(classCode.getOrNull()) + fun id(): String = id.getRequired("id") /** - * Sets [Builder.classCode] to an arbitrary JSON value. + * Worker's compensation classification code for this employee * - * You should usually call [Builder.classCode] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun classCode(classCode: JsonField) = apply { this.classCode = classCode } + fun classCode(): Optional = classCode.getOptional("class_code") /** * Custom fields for the individual. These are fields which are defined by the employer in * the system. - */ - fun customFields(customFields: List?) = - customFields(JsonField.ofNullable(customFields)) - - /** Alias for calling [Builder.customFields] with `customFields.orElse(null)`. */ - fun customFields(customFields: Optional>) = - customFields(customFields.getOrNull()) - - /** - * Sets [Builder.customFields] to an arbitrary JSON value. * - * You should usually call [Builder.customFields] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun customFields(customFields: JsonField>) = apply { - this.customFields = customFields.map { it.toMutableList() } - } + fun customFields(): Optional> = customFields.getOptional("custom_fields") /** - * Adds a single [CustomField] to [customFields]. + * The department object. * - * @throws IllegalStateException if the field was previously set to a non-list. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun addCustomField(customField: CustomField) = apply { - customFields = - (customFields ?: JsonField.of(mutableListOf())).also { - checkKnown("customFields", it).add(customField) - } - } - - /** The department object. */ - fun department(department: Department?) = department(JsonField.ofNullable(department)) - - /** Alias for calling [Builder.department] with `department.orElse(null)`. */ - fun department(department: Optional) = department(department.getOrNull()) + fun department(): Optional = department.getOptional("department") /** - * Sets [Builder.department] to an arbitrary JSON value. + * The employment object. * - * You should usually call [Builder.department] with a well-typed [Department] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun department(department: JsonField) = apply { this.department = department } - - /** The employment object. */ - fun employment(employment: Employment?) = employment(JsonField.ofNullable(employment)) - - /** Alias for calling [Builder.employment] with `employment.orElse(null)`. */ - fun employment(employment: Optional) = employment(employment.getOrNull()) + fun employment(): Optional = employment.getOptional("employment") /** - * Sets [Builder.employment] to an arbitrary JSON value. + * The detailed employment status of the individual. Available options: `active`, + * `deceased`, `leave`, `onboarding`, `prehire`, `retired`, `terminated`. * - * You should usually call [Builder.employment] with a well-typed [Employment] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun employment(employment: JsonField) = apply { this.employment = employment } + fun employmentStatus(): Optional = + employmentStatus.getOptional("employment_status") /** - * The detailed employment status of the individual. Available options: `active`, - * `deceased`, `leave`, `onboarding`, `prehire`, `retired`, `terminated`. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun employmentStatus(employmentStatus: EmploymentStatus?) = - employmentStatus(JsonField.ofNullable(employmentStatus)) - - /** Alias for calling [Builder.employmentStatus] with `employmentStatus.orElse(null)`. */ - fun employmentStatus(employmentStatus: Optional) = - employmentStatus(employmentStatus.getOrNull()) + fun endDate(): Optional = endDate.getOptional("end_date") /** - * Sets [Builder.employmentStatus] to an arbitrary JSON value. + * The legal first name of the individual. * - * You should usually call [Builder.employmentStatus] with a well-typed [EmploymentStatus] - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun employmentStatus(employmentStatus: JsonField) = apply { - this.employmentStatus = employmentStatus - } - - fun endDate(endDate: String?) = endDate(JsonField.ofNullable(endDate)) - - /** Alias for calling [Builder.endDate] with `endDate.orElse(null)`. */ - fun endDate(endDate: Optional) = endDate(endDate.getOrNull()) + fun firstName(): Optional = firstName.getOptional("first_name") /** - * Sets [Builder.endDate] to an arbitrary JSON value. + * `true` if the individual an an active employee or contractor at the company. * - * You should usually call [Builder.endDate] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun endDate(endDate: JsonField) = apply { this.endDate = endDate } - - /** The legal first name of the individual. */ - fun firstName(firstName: String?) = firstName(JsonField.ofNullable(firstName)) - - /** Alias for calling [Builder.firstName] with `firstName.orElse(null)`. */ - fun firstName(firstName: Optional) = firstName(firstName.getOrNull()) + fun isActive(): Optional = isActive.getOptional("is_active") /** - * Sets [Builder.firstName] to an arbitrary JSON value. + * The legal last name of the individual. * - * You should usually call [Builder.firstName] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun firstName(firstName: JsonField) = apply { this.firstName = firstName } + fun lastName(): Optional = lastName.getOptional("last_name") /** - * The employee's income as reported by the provider. This may not always be annualized - * income, but may be in units of bi-weekly, semi-monthly, daily, etc, depending on what - * information the provider returns. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun income(income: Income?) = income(JsonField.ofNullable(income)) - - /** Alias for calling [Builder.income] with `income.orElse(null)`. */ - fun income(income: Optional) = income(income.getOrNull()) + fun latestRehireDate(): Optional = + latestRehireDate.getOptional("latest_rehire_date") /** - * Sets [Builder.income] to an arbitrary JSON value. - * - * You should usually call [Builder.income] with a well-typed [Income] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun income(income: JsonField) = apply { this.income = income } - - /** The array of income history. */ - fun incomeHistory(incomeHistory: List?) = - incomeHistory(JsonField.ofNullable(incomeHistory)) - - /** Alias for calling [Builder.incomeHistory] with `incomeHistory.orElse(null)`. */ - fun incomeHistory(incomeHistory: Optional>) = - incomeHistory(incomeHistory.getOrNull()) + fun location(): Optional = location.getOptional("location") /** - * Sets [Builder.incomeHistory] to an arbitrary JSON value. + * The manager object representing the manager of the individual within the org. * - * You should usually call [Builder.incomeHistory] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun incomeHistory(incomeHistory: JsonField>) = apply { - this.incomeHistory = incomeHistory.map { it.toMutableList() } - } + fun manager(): Optional = manager.getOptional("manager") /** - * Adds a single [Income] to [Builder.incomeHistory]. + * The legal middle name of the individual. * - * @throws IllegalStateException if the field was previously set to a non-list. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun addIncomeHistory(incomeHistory: Income) = apply { - this.incomeHistory = - (this.incomeHistory ?: JsonField.of(mutableListOf())).also { - checkKnown("incomeHistory", it).add(incomeHistory) - } - } - - /** `true` if the individual an an active employee or contractor at the company. */ - fun isActive(isActive: Boolean?) = isActive(JsonField.ofNullable(isActive)) + fun middleName(): Optional = middleName.getOptional("middle_name") /** - * Alias for [Builder.isActive]. + * The source system's unique employment identifier for this individual * - * This unboxed primitive overload exists for backwards compatibility. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun isActive(isActive: Boolean) = isActive(isActive as Boolean?) + fun sourceId(): Optional = sourceId.getOptional("source_id") - /** Alias for calling [Builder.isActive] with `isActive.orElse(null)`. */ - fun isActive(isActive: Optional) = isActive(isActive.getOrNull()) + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun startDate(): Optional = startDate.getOptional("start_date") /** - * Sets [Builder.isActive] to an arbitrary JSON value. + * The current title of the individual. * - * You should usually call [Builder.isActive] with a well-typed [Boolean] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun isActive(isActive: JsonField) = apply { this.isActive = isActive } - - /** The legal last name of the individual. */ - fun lastName(lastName: String?) = lastName(JsonField.ofNullable(lastName)) - - /** Alias for calling [Builder.lastName] with `lastName.orElse(null)`. */ - fun lastName(lastName: Optional) = lastName(lastName.getOrNull()) + fun title(): Optional = title.getOptional("title") /** - * Sets [Builder.lastName] to an arbitrary JSON value. + * This field is deprecated in favour of `source_id` * - * You should usually call [Builder.lastName] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun lastName(lastName: JsonField) = apply { this.lastName = lastName } - - fun latestRehireDate(latestRehireDate: String?) = - latestRehireDate(JsonField.ofNullable(latestRehireDate)) - - /** Alias for calling [Builder.latestRehireDate] with `latestRehireDate.orElse(null)`. */ - fun latestRehireDate(latestRehireDate: Optional) = - latestRehireDate(latestRehireDate.getOrNull()) + @Deprecated("deprecated") fun workId(): Optional = workId.getOptional("work_id") /** - * Sets [Builder.latestRehireDate] to an arbitrary JSON value. + * The employee's income as reported by the provider. This may not always be annualized + * income, but may be in units of bi-weekly, semi-monthly, daily, etc, depending on what + * information the provider returns. * - * You should usually call [Builder.latestRehireDate] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun latestRehireDate(latestRehireDate: JsonField) = apply { - this.latestRehireDate = latestRehireDate - } - - fun location(location: Location?) = location(JsonField.ofNullable(location)) - - /** Alias for calling [Builder.location] with `location.orElse(null)`. */ - fun location(location: Optional) = location(location.getOrNull()) + fun income(): Optional = income.getOptional("income") /** - * Sets [Builder.location] to an arbitrary JSON value. + * The array of income history. * - * You should usually call [Builder.location] with a well-typed [Location] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun location(location: JsonField) = apply { this.location = location } - - /** The manager object representing the manager of the individual within the org. */ - fun manager(manager: Manager?) = manager(JsonField.ofNullable(manager)) - - /** Alias for calling [Builder.manager] with `manager.orElse(null)`. */ - fun manager(manager: Optional) = manager(manager.getOrNull()) + fun incomeHistory(): Optional> = incomeHistory.getOptional("income_history") /** - * Sets [Builder.manager] to an arbitrary JSON value. + * Returns the raw JSON value of [id]. * - * You should usually call [Builder.manager] with a well-typed [Manager] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. */ - fun manager(manager: JsonField) = apply { this.manager = manager } - - /** The legal middle name of the individual. */ - fun middleName(middleName: String?) = middleName(JsonField.ofNullable(middleName)) - - /** Alias for calling [Builder.middleName] with `middleName.orElse(null)`. */ - fun middleName(middleName: Optional) = middleName(middleName.getOrNull()) + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id /** - * Sets [Builder.middleName] to an arbitrary JSON value. + * Returns the raw JSON value of [classCode]. * - * You should usually call [Builder.middleName] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [classCode], this method doesn't throw if the JSON field has an unexpected type. */ - fun middleName(middleName: JsonField) = apply { this.middleName = middleName } - - /** The source system's unique employment identifier for this individual */ - fun sourceId(sourceId: String?) = sourceId(JsonField.ofNullable(sourceId)) - - /** Alias for calling [Builder.sourceId] with `sourceId.orElse(null)`. */ - fun sourceId(sourceId: Optional) = sourceId(sourceId.getOrNull()) + @JsonProperty("class_code") @ExcludeMissing fun _classCode(): JsonField = classCode /** - * Sets [Builder.sourceId] to an arbitrary JSON value. + * Returns the raw JSON value of [customFields]. * - * You should usually call [Builder.sourceId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [customFields], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun sourceId(sourceId: JsonField) = apply { this.sourceId = sourceId } - - fun startDate(startDate: String?) = startDate(JsonField.ofNullable(startDate)) - - /** Alias for calling [Builder.startDate] with `startDate.orElse(null)`. */ - fun startDate(startDate: Optional) = startDate(startDate.getOrNull()) + @JsonProperty("custom_fields") + @ExcludeMissing + fun _customFields(): JsonField> = customFields /** - * Sets [Builder.startDate] to an arbitrary JSON value. + * Returns the raw JSON value of [department]. * - * You should usually call [Builder.startDate] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [department], this method doesn't throw if the JSON field has an unexpected type. */ - fun startDate(startDate: JsonField) = apply { this.startDate = startDate } - - /** The current title of the individual. */ - fun title(title: String?) = title(JsonField.ofNullable(title)) - - /** Alias for calling [Builder.title] with `title.orElse(null)`. */ - fun title(title: Optional) = title(title.getOrNull()) + @JsonProperty("department") + @ExcludeMissing + fun _department(): JsonField = department /** - * Sets [Builder.title] to an arbitrary JSON value. + * Returns the raw JSON value of [employment]. * - * You should usually call [Builder.title] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [employment], this method doesn't throw if the JSON field has an unexpected type. */ - fun title(title: JsonField) = apply { this.title = title } - - /** This field is deprecated in favour of `source_id` */ - @Deprecated("deprecated") fun workId(workId: String?) = workId(JsonField.ofNullable(workId)) - - /** Alias for calling [Builder.workId] with `workId.orElse(null)`. */ - @Deprecated("deprecated") fun workId(workId: Optional) = workId(workId.getOrNull()) + @JsonProperty("employment") + @ExcludeMissing + fun _employment(): JsonField = employment /** - * Sets [Builder.workId] to an arbitrary JSON value. + * Returns the raw JSON value of [employmentStatus]. * - * You should usually call [Builder.workId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [employmentStatus], this method doesn't throw if the JSON field has an unexpected + * type. */ - @Deprecated("deprecated") - fun workId(workId: JsonField) = apply { this.workId = workId } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + @JsonProperty("employment_status") + @ExcludeMissing + fun _employmentStatus(): JsonField = employmentStatus - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Returns the raw JSON value of [endDate]. + * + * Unlike [endDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("end_date") @ExcludeMissing fun _endDate(): JsonField = endDate - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * Returns the raw JSON value of [firstName]. + * + * Unlike [firstName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_name") @ExcludeMissing fun _firstName(): JsonField = firstName - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** + * Returns the raw JSON value of [isActive]. + * + * Unlike [isActive], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("is_active") @ExcludeMissing fun _isActive(): JsonField = isActive - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + /** + * Returns the raw JSON value of [lastName]. + * + * Unlike [lastName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_name") @ExcludeMissing fun _lastName(): JsonField = lastName /** - * Returns an immutable instance of [EmploymentData]. + * Returns the raw JSON value of [latestRehireDate]. * - * Further updates to this [Builder] will not mutate the returned instance. + * Unlike [latestRehireDate], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun build(): EmploymentData = - EmploymentData( - id, - classCode, - (customFields ?: JsonMissing.of()).map { it.toImmutable() }, - department, - employment, - employmentStatus, - endDate, - firstName, - income, - (incomeHistory ?: JsonMissing.of()).map { it.toImmutable() }, - isActive, - lastName, - latestRehireDate, - location, - manager, - middleName, - sourceId, - startDate, - title, - workId, - additionalProperties.toMutableMap(), - ) - } + @JsonProperty("latest_rehire_date") + @ExcludeMissing + fun _latestRehireDate(): JsonField = latestRehireDate - private var validated: Boolean = false + /** + * Returns the raw JSON value of [location]. + * + * Unlike [location], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("location") @ExcludeMissing fun _location(): JsonField = location - fun validate(): EmploymentData = apply { - if (validated) { - return@apply - } + /** + * Returns the raw JSON value of [manager]. + * + * Unlike [manager], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("manager") @ExcludeMissing fun _manager(): JsonField = manager - id() - classCode() - customFields().ifPresent { it.forEach { it.validate() } } - department().ifPresent { it.validate() } - employment().ifPresent { it.validate() } - employmentStatus().ifPresent { it.validate() } - endDate() - firstName() - income().ifPresent { it.validate() } - incomeHistory().ifPresent { it.forEach { it?.validate() } } - isActive() - lastName() - latestRehireDate() - location().ifPresent { it.validate() } - manager().ifPresent { it.validate() } - middleName() - sourceId() - startDate() - title() - workId() - validated = true - } + /** + * Returns the raw JSON value of [middleName]. + * + * Unlike [middleName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("middle_name") + @ExcludeMissing + fun _middleName(): JsonField = middleName - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false - } + /** + * Returns the raw JSON value of [sourceId]. + * + * Unlike [sourceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source_id") @ExcludeMissing fun _sourceId(): JsonField = sourceId - /** - * 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 (id.asKnown().isPresent) 1 else 0) + - (if (classCode.asKnown().isPresent) 1 else 0) + - (customFields.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + - (department.asKnown().getOrNull()?.validity() ?: 0) + - (employment.asKnown().getOrNull()?.validity() ?: 0) + - (employmentStatus.asKnown().getOrNull()?.validity() ?: 0) + - (if (endDate.asKnown().isPresent) 1 else 0) + - (if (firstName.asKnown().isPresent) 1 else 0) + - (income.asKnown().getOrNull()?.validity() ?: 0) + - (incomeHistory.asKnown().getOrNull()?.sumOf { (it?.validity() ?: 0).toInt() } ?: 0) + - (if (isActive.asKnown().isPresent) 1 else 0) + - (if (lastName.asKnown().isPresent) 1 else 0) + - (if (latestRehireDate.asKnown().isPresent) 1 else 0) + - (location.asKnown().getOrNull()?.validity() ?: 0) + - (manager.asKnown().getOrNull()?.validity() ?: 0) + - (if (middleName.asKnown().isPresent) 1 else 0) + - (if (sourceId.asKnown().isPresent) 1 else 0) + - (if (startDate.asKnown().isPresent) 1 else 0) + - (if (title.asKnown().isPresent) 1 else 0) + - (if (workId.asKnown().isPresent) 1 else 0) - - class CustomField - private constructor( - private val name: JsonField, - private val value: JsonValue, - private val additionalProperties: MutableMap, - ) { + /** + * Returns the raw JSON value of [startDate]. + * + * Unlike [startDate], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("start_date") @ExcludeMissing fun _startDate(): JsonField = startDate - @JsonCreator - private constructor( - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), - @JsonProperty("value") @ExcludeMissing value: JsonValue = JsonMissing.of(), - ) : this(name, value, mutableMapOf()) + /** + * Returns the raw JSON value of [title]. + * + * Unlike [title], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("title") @ExcludeMissing fun _title(): JsonField = title /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * Returns the raw JSON value of [workId]. + * + * Unlike [workId], this method doesn't throw if the JSON field has an unexpected type. */ - fun name(): Optional = name.getOptional("name") + @Deprecated("deprecated") + @JsonProperty("work_id") + @ExcludeMissing + fun _workId(): JsonField = workId - @JsonProperty("value") @ExcludeMissing fun _value(): JsonValue = value + /** + * Returns the raw JSON value of [income]. + * + * Unlike [income], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("income") @ExcludeMissing fun _income(): JsonField = income /** - * Returns the raw JSON value of [name]. + * Returns the raw JSON value of [incomeHistory]. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [incomeHistory], this method doesn't throw if the JSON field has an unexpected + * type. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonProperty("income_history") + @ExcludeMissing + fun _incomeHistory(): JsonField> = incomeHistory @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -987,180 +635,444 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [CustomField]. */ + /** + * Returns a mutable builder for constructing an instance of [UnionMember0]. + * + * The following fields are required: + * ```java + * .id() + * .classCode() + * .customFields() + * .department() + * .employment() + * .employmentStatus() + * .endDate() + * .firstName() + * .isActive() + * .lastName() + * .latestRehireDate() + * .location() + * .manager() + * .middleName() + * .sourceId() + * .startDate() + * .title() + * .workId() + * ``` + */ @JvmStatic fun builder() = Builder() } - /** A builder for [CustomField]. */ + /** A builder for [UnionMember0]. */ class Builder internal constructor() { - private var name: JsonField = JsonMissing.of() - private var value: JsonValue = JsonMissing.of() + private var id: JsonField? = null + private var classCode: JsonField? = null + private var customFields: JsonField>? = null + private var department: JsonField? = null + private var employment: JsonField? = null + private var employmentStatus: JsonField? = null + private var endDate: JsonField? = null + private var firstName: JsonField? = null + private var isActive: JsonField? = null + private var lastName: JsonField? = null + private var latestRehireDate: JsonField? = null + private var location: JsonField? = null + private var manager: JsonField? = null + private var middleName: JsonField? = null + private var sourceId: JsonField? = null + private var startDate: JsonField? = null + private var title: JsonField? = null + private var workId: JsonField? = null + private var income: JsonField = JsonMissing.of() + private var incomeHistory: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(customField: CustomField) = apply { - name = customField.name - value = customField.value - additionalProperties = customField.additionalProperties.toMutableMap() + internal fun from(unionMember0: UnionMember0) = apply { + id = unionMember0.id + classCode = unionMember0.classCode + customFields = unionMember0.customFields.map { it.toMutableList() } + department = unionMember0.department + employment = unionMember0.employment + employmentStatus = unionMember0.employmentStatus + endDate = unionMember0.endDate + firstName = unionMember0.firstName + isActive = unionMember0.isActive + lastName = unionMember0.lastName + latestRehireDate = unionMember0.latestRehireDate + location = unionMember0.location + manager = unionMember0.manager + middleName = unionMember0.middleName + sourceId = unionMember0.sourceId + startDate = unionMember0.startDate + title = unionMember0.title + workId = unionMember0.workId + income = unionMember0.income + incomeHistory = unionMember0.incomeHistory.map { it.toMutableList() } + additionalProperties = unionMember0.additionalProperties.toMutableMap() } - fun name(name: String) = name(JsonField.of(name)) + /** A stable Finch `id` (UUID v4) for an individual in the company. */ + fun id(id: String) = id(JsonField.of(id)) /** - * Sets [Builder.name] to an arbitrary JSON value. + * Sets [Builder.id] to an arbitrary JSON value. * - * You should usually call [Builder.name] with a well-typed [String] value instead. This + * You should usually call [Builder.id] with a well-typed [String] value instead. This * method is primarily for setting the field to an undocumented or not yet supported * value. */ - fun name(name: JsonField) = apply { this.name = name } + fun id(id: JsonField) = apply { this.id = id } - fun value(value: JsonValue) = apply { this.value = value } + /** Worker's compensation classification code for this employee */ + fun classCode(classCode: String?) = classCode(JsonField.ofNullable(classCode)) - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + /** Alias for calling [Builder.classCode] with `classCode.orElse(null)`. */ + fun classCode(classCode: Optional) = classCode(classCode.getOrNull()) - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + /** + * Sets [Builder.classCode] to an arbitrary JSON value. + * + * You should usually call [Builder.classCode] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun classCode(classCode: JsonField) = apply { this.classCode = classCode } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + /** + * Custom fields for the individual. These are fields which are defined by the employer + * in the system. + */ + fun customFields(customFields: List?) = + customFields(JsonField.ofNullable(customFields)) - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + /** Alias for calling [Builder.customFields] with `customFields.orElse(null)`. */ + fun customFields(customFields: Optional>) = + customFields(customFields.getOrNull()) - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) + /** + * Sets [Builder.customFields] to an arbitrary JSON value. + * + * You should usually call [Builder.customFields] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun customFields(customFields: JsonField>) = apply { + this.customFields = customFields.map { it.toMutableList() } } /** - * Returns an immutable instance of [CustomField]. + * Adds a single [CustomField] to [customFields]. * - * Further updates to this [Builder] will not mutate the returned instance. + * @throws IllegalStateException if the field was previously set to a non-list. */ - fun build(): CustomField = CustomField(name, value, additionalProperties.toMutableMap()) - } - - private var validated: Boolean = false - - fun validate(): CustomField = apply { - if (validated) { - return@apply + fun addCustomField(customField: CustomField) = apply { + customFields = + (customFields ?: JsonField.of(mutableListOf())).also { + checkKnown("customFields", it).add(customField) + } } - name() - validated = true - } + /** The department object. */ + fun department(department: Department?) = department(JsonField.ofNullable(department)) - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false + /** Alias for calling [Builder.department] with `department.orElse(null)`. */ + fun department(department: Optional) = department(department.getOrNull()) + + /** + * Sets [Builder.department] to an arbitrary JSON value. + * + * You should usually call [Builder.department] with a well-typed [Department] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun department(department: JsonField) = apply { + this.department = department } - /** - * 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 (name.asKnown().isPresent) 1 else 0) + /** The employment object. */ + fun employment(employment: Employment?) = employment(JsonField.ofNullable(employment)) - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** Alias for calling [Builder.employment] with `employment.orElse(null)`. */ + fun employment(employment: Optional) = employment(employment.getOrNull()) + + /** + * Sets [Builder.employment] to an arbitrary JSON value. + * + * You should usually call [Builder.employment] with a well-typed [Employment] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun employment(employment: JsonField) = apply { + this.employment = employment } - return /* spotless:off */ other is CustomField && name == other.name && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * The detailed employment status of the individual. Available options: `active`, + * `deceased`, `leave`, `onboarding`, `prehire`, `retired`, `terminated`. + */ + fun employmentStatus(employmentStatus: EmploymentStatus?) = + employmentStatus(JsonField.ofNullable(employmentStatus)) - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, value, additionalProperties) } - /* spotless:on */ + /** + * Alias for calling [Builder.employmentStatus] with `employmentStatus.orElse(null)`. + */ + fun employmentStatus(employmentStatus: Optional) = + employmentStatus(employmentStatus.getOrNull()) - override fun hashCode(): Int = hashCode + /** + * Sets [Builder.employmentStatus] to an arbitrary JSON value. + * + * You should usually call [Builder.employmentStatus] with a well-typed + * [EmploymentStatus] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun employmentStatus(employmentStatus: JsonField) = apply { + this.employmentStatus = employmentStatus + } - override fun toString() = - "CustomField{name=$name, value=$value, additionalProperties=$additionalProperties}" - } + fun endDate(endDate: String?) = endDate(JsonField.ofNullable(endDate)) - /** The department object. */ - class Department - private constructor( - private val name: JsonField, - private val additionalProperties: MutableMap, - ) { + /** Alias for calling [Builder.endDate] with `endDate.orElse(null)`. */ + fun endDate(endDate: Optional) = endDate(endDate.getOrNull()) - @JsonCreator - private constructor( - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of() - ) : this(name, mutableMapOf()) + /** + * Sets [Builder.endDate] to an arbitrary JSON value. + * + * You should usually call [Builder.endDate] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun endDate(endDate: JsonField) = apply { this.endDate = endDate } - /** - * The name of the department associated with the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun name(): Optional = name.getOptional("name") + /** The legal first name of the individual. */ + fun firstName(firstName: String?) = firstName(JsonField.ofNullable(firstName)) - /** - * Returns the raw JSON value of [name]. - * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** Alias for calling [Builder.firstName] with `firstName.orElse(null)`. */ + fun firstName(firstName: Optional) = firstName(firstName.getOrNull()) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** + * Sets [Builder.firstName] to an arbitrary JSON value. + * + * You should usually call [Builder.firstName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun firstName(firstName: JsonField) = apply { this.firstName = firstName } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** `true` if the individual an an active employee or contractor at the company. */ + fun isActive(isActive: Boolean?) = isActive(JsonField.ofNullable(isActive)) - fun toBuilder() = Builder().from(this) + /** + * Alias for [Builder.isActive]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun isActive(isActive: Boolean) = isActive(isActive as Boolean?) - companion object { + /** Alias for calling [Builder.isActive] with `isActive.orElse(null)`. */ + fun isActive(isActive: Optional) = isActive(isActive.getOrNull()) - /** Returns a mutable builder for constructing an instance of [Department]. */ - @JvmStatic fun builder() = Builder() - } + /** + * Sets [Builder.isActive] to an arbitrary JSON value. + * + * You should usually call [Builder.isActive] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun isActive(isActive: JsonField) = apply { this.isActive = isActive } - /** A builder for [Department]. */ - class Builder internal constructor() { + /** The legal last name of the individual. */ + fun lastName(lastName: String?) = lastName(JsonField.ofNullable(lastName)) - private var name: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** Alias for calling [Builder.lastName] with `lastName.orElse(null)`. */ + fun lastName(lastName: Optional) = lastName(lastName.getOrNull()) - @JvmSynthetic - internal fun from(department: Department) = apply { - name = department.name - additionalProperties = department.additionalProperties.toMutableMap() + /** + * Sets [Builder.lastName] to an arbitrary JSON value. + * + * You should usually call [Builder.lastName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastName(lastName: JsonField) = apply { this.lastName = lastName } + + fun latestRehireDate(latestRehireDate: String?) = + latestRehireDate(JsonField.ofNullable(latestRehireDate)) + + /** + * Alias for calling [Builder.latestRehireDate] with `latestRehireDate.orElse(null)`. + */ + fun latestRehireDate(latestRehireDate: Optional) = + latestRehireDate(latestRehireDate.getOrNull()) + + /** + * Sets [Builder.latestRehireDate] to an arbitrary JSON value. + * + * You should usually call [Builder.latestRehireDate] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun latestRehireDate(latestRehireDate: JsonField) = apply { + this.latestRehireDate = latestRehireDate } - /** The name of the department associated with the individual. */ - fun name(name: String?) = name(JsonField.ofNullable(name)) + fun location(location: Location?) = location(JsonField.ofNullable(location)) - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) + /** Alias for calling [Builder.location] with `location.orElse(null)`. */ + fun location(location: Optional) = location(location.getOrNull()) /** - * Sets [Builder.name] to an arbitrary JSON value. + * Sets [Builder.location] to an arbitrary JSON value. * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. + * You should usually call [Builder.location] with a well-typed [Location] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun name(name: JsonField) = apply { this.name = name } + fun location(location: JsonField) = apply { this.location = location } + + /** The manager object representing the manager of the individual within the org. */ + fun manager(manager: Manager?) = manager(JsonField.ofNullable(manager)) + + /** Alias for calling [Builder.manager] with `manager.orElse(null)`. */ + fun manager(manager: Optional) = manager(manager.getOrNull()) + + /** + * Sets [Builder.manager] to an arbitrary JSON value. + * + * You should usually call [Builder.manager] with a well-typed [Manager] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun manager(manager: JsonField) = apply { this.manager = manager } + + /** The legal middle name of the individual. */ + fun middleName(middleName: String?) = middleName(JsonField.ofNullable(middleName)) + + /** Alias for calling [Builder.middleName] with `middleName.orElse(null)`. */ + fun middleName(middleName: Optional) = middleName(middleName.getOrNull()) + + /** + * Sets [Builder.middleName] to an arbitrary JSON value. + * + * You should usually call [Builder.middleName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun middleName(middleName: JsonField) = apply { this.middleName = middleName } + + /** The source system's unique employment identifier for this individual */ + fun sourceId(sourceId: String?) = sourceId(JsonField.ofNullable(sourceId)) + + /** Alias for calling [Builder.sourceId] with `sourceId.orElse(null)`. */ + fun sourceId(sourceId: Optional) = sourceId(sourceId.getOrNull()) + + /** + * Sets [Builder.sourceId] to an arbitrary JSON value. + * + * You should usually call [Builder.sourceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sourceId(sourceId: JsonField) = apply { this.sourceId = sourceId } + + fun startDate(startDate: String?) = startDate(JsonField.ofNullable(startDate)) + + /** Alias for calling [Builder.startDate] with `startDate.orElse(null)`. */ + fun startDate(startDate: Optional) = startDate(startDate.getOrNull()) + + /** + * Sets [Builder.startDate] to an arbitrary JSON value. + * + * You should usually call [Builder.startDate] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun startDate(startDate: JsonField) = apply { this.startDate = startDate } + + /** The current title of the individual. */ + fun title(title: String?) = title(JsonField.ofNullable(title)) + + /** Alias for calling [Builder.title] with `title.orElse(null)`. */ + fun title(title: Optional) = title(title.getOrNull()) + + /** + * Sets [Builder.title] to an arbitrary JSON value. + * + * You should usually call [Builder.title] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun title(title: JsonField) = apply { this.title = title } + + /** This field is deprecated in favour of `source_id` */ + @Deprecated("deprecated") + fun workId(workId: String?) = workId(JsonField.ofNullable(workId)) + + /** Alias for calling [Builder.workId] with `workId.orElse(null)`. */ + @Deprecated("deprecated") + fun workId(workId: Optional) = workId(workId.getOrNull()) + + /** + * Sets [Builder.workId] to an arbitrary JSON value. + * + * You should usually call [Builder.workId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + @Deprecated("deprecated") + fun workId(workId: JsonField) = apply { this.workId = workId } + + /** + * The employee's income as reported by the provider. This may not always be annualized + * income, but may be in units of bi-weekly, semi-monthly, daily, etc, depending on what + * information the provider returns. + */ + fun income(income: Income?) = income(JsonField.ofNullable(income)) + + /** Alias for calling [Builder.income] with `income.orElse(null)`. */ + fun income(income: Optional) = income(income.getOrNull()) + + /** + * Sets [Builder.income] to an arbitrary JSON value. + * + * You should usually call [Builder.income] with a well-typed [Income] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun income(income: JsonField) = apply { this.income = income } + + /** The array of income history. */ + fun incomeHistory(incomeHistory: List?) = + incomeHistory(JsonField.ofNullable(incomeHistory)) + + /** Alias for calling [Builder.incomeHistory] with `incomeHistory.orElse(null)`. */ + fun incomeHistory(incomeHistory: Optional>) = + incomeHistory(incomeHistory.getOrNull()) + + /** + * Sets [Builder.incomeHistory] to an arbitrary JSON value. + * + * You should usually call [Builder.incomeHistory] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun incomeHistory(incomeHistory: JsonField>) = apply { + this.incomeHistory = incomeHistory.map { it.toMutableList() } + } + + /** + * Adds a single [Income] to [Builder.incomeHistory]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addIncomeHistory(incomeHistory: Income) = apply { + this.incomeHistory = + (this.incomeHistory ?: JsonField.of(mutableListOf())).also { + checkKnown("incomeHistory", it).add(incomeHistory) + } + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -1182,21 +1094,87 @@ private constructor( } /** - * Returns an immutable instance of [Department]. + * Returns an immutable instance of [UnionMember0]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .classCode() + * .customFields() + * .department() + * .employment() + * .employmentStatus() + * .endDate() + * .firstName() + * .isActive() + * .lastName() + * .latestRehireDate() + * .location() + * .manager() + * .middleName() + * .sourceId() + * .startDate() + * .title() + * .workId() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Department = Department(name, additionalProperties.toMutableMap()) + fun build(): UnionMember0 = + UnionMember0( + checkRequired("id", id), + checkRequired("classCode", classCode), + checkRequired("customFields", customFields).map { it.toImmutable() }, + checkRequired("department", department), + checkRequired("employment", employment), + checkRequired("employmentStatus", employmentStatus), + checkRequired("endDate", endDate), + checkRequired("firstName", firstName), + checkRequired("isActive", isActive), + checkRequired("lastName", lastName), + checkRequired("latestRehireDate", latestRehireDate), + checkRequired("location", location), + checkRequired("manager", manager), + checkRequired("middleName", middleName), + checkRequired("sourceId", sourceId), + checkRequired("startDate", startDate), + checkRequired("title", title), + checkRequired("workId", workId), + income, + (incomeHistory ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): Department = apply { + fun validate(): UnionMember0 = apply { if (validated) { return@apply } - name() + id() + classCode() + customFields().ifPresent { it.forEach { it.validate() } } + department().ifPresent { it.validate() } + employment().ifPresent { it.validate() } + employmentStatus().ifPresent { it.validate() } + endDate() + firstName() + isActive() + lastName() + latestRehireDate() + location().ifPresent { it.validate() } + manager().ifPresent { it.validate() } + middleName() + sourceId() + startDate() + title() + workId() + income().ifPresent { it.validate() } + incomeHistory().ifPresent { it.forEach { it?.validate() } } validated = true } @@ -1214,200 +1192,1127 @@ private constructor( * * Used for best match union deserialization. */ - @JvmSynthetic internal fun validity(): Int = (if (name.asKnown().isPresent) 1 else 0) + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (classCode.asKnown().isPresent) 1 else 0) + + (customFields.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (department.asKnown().getOrNull()?.validity() ?: 0) + + (employment.asKnown().getOrNull()?.validity() ?: 0) + + (employmentStatus.asKnown().getOrNull()?.validity() ?: 0) + + (if (endDate.asKnown().isPresent) 1 else 0) + + (if (firstName.asKnown().isPresent) 1 else 0) + + (if (isActive.asKnown().isPresent) 1 else 0) + + (if (lastName.asKnown().isPresent) 1 else 0) + + (if (latestRehireDate.asKnown().isPresent) 1 else 0) + + (location.asKnown().getOrNull()?.validity() ?: 0) + + (manager.asKnown().getOrNull()?.validity() ?: 0) + + (if (middleName.asKnown().isPresent) 1 else 0) + + (if (sourceId.asKnown().isPresent) 1 else 0) + + (if (startDate.asKnown().isPresent) 1 else 0) + + (if (title.asKnown().isPresent) 1 else 0) + + (if (workId.asKnown().isPresent) 1 else 0) + + (income.asKnown().getOrNull()?.validity() ?: 0) + + (incomeHistory.asKnown().getOrNull()?.sumOf { (it?.validity() ?: 0).toInt() } ?: 0) + + class CustomField + private constructor( + private val name: JsonField, + private val value: JsonField, + private val additionalProperties: MutableMap, + ) { - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("value") @ExcludeMissing value: JsonField = JsonMissing.of(), + ) : this(name, value, mutableMapOf()) + + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun value(): Optional = value.getOptional("value") + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [value]. + * + * Unlike [value], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - return /* spotless:off */ other is Department && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ - } + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(name, additionalProperties) } - /* spotless:on */ + fun toBuilder() = Builder().from(this) - override fun hashCode(): Int = hashCode + companion object { - override fun toString() = - "Department{name=$name, additionalProperties=$additionalProperties}" - } + /** Returns a mutable builder for constructing an instance of [CustomField]. */ + @JvmStatic fun builder() = Builder() + } - /** The employment object. */ - class Employment - private constructor( - private val subtype: JsonField, - private val type: JsonField, - private val additionalProperties: MutableMap, - ) { + /** A builder for [CustomField]. */ + class Builder internal constructor() { - @JsonCreator - private constructor( - @JsonProperty("subtype") @ExcludeMissing subtype: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(subtype, type, mutableMapOf()) + private var name: JsonField = JsonMissing.of() + private var value: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - /** - * The secondary employment type of the individual. Options: `full_time`, `part_time`, - * `intern`, `temp`, `seasonal` and `individual_contractor`. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun subtype(): Optional = subtype.getOptional("subtype") + @JvmSynthetic + internal fun from(customField: CustomField) = apply { + name = customField.name + value = customField.value + additionalProperties = customField.additionalProperties.toMutableMap() + } - /** - * The main employment type of the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun type(): Optional = type.getOptional("type") + fun name(name: String) = name(JsonField.of(name)) - /** - * Returns the raw JSON value of [subtype]. - * - * Unlike [subtype], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("subtype") @ExcludeMissing fun _subtype(): JsonField = subtype + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun name(name: JsonField) = apply { this.name = name } - /** - * Returns the raw JSON value of [type]. - * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + fun value(value: Value?) = value(JsonField.ofNullable(value)) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } + /** Alias for calling [Builder.value] with `value.orElse(null)`. */ + fun value(value: Optional) = value(value.getOrNull()) - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** + * Sets [Builder.value] to an arbitrary JSON value. + * + * You should usually call [Builder.value] with a well-typed [Value] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun value(value: JsonField) = apply { this.value = value } - fun toBuilder() = Builder().from(this) + /** Alias for calling [value] with `Value.ofString(string)`. */ + fun value(string: String) = value(Value.ofString(string)) - companion object { + /** Alias for calling [value] with `Value.ofJsonValues(jsonValues)`. */ + fun valueOfJsonValues(jsonValues: List) = + value(Value.ofJsonValues(jsonValues)) - /** Returns a mutable builder for constructing an instance of [Employment]. */ - @JvmStatic fun builder() = Builder() - } + /** Alias for calling [value] with `Value.ofJson(json)`. */ + fun value(json: JsonValue) = value(Value.ofJson(json)) - /** A builder for [Employment]. */ - class Builder internal constructor() { + /** Alias for calling [value] with `Value.ofNumber(number)`. */ + fun value(number: Double) = value(Value.ofNumber(number)) - private var subtype: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + /** Alias for calling [value] with `Value.ofBool(bool)`. */ + fun value(bool: Boolean) = value(Value.ofBool(bool)) - @JvmSynthetic - internal fun from(employment: Employment) = apply { - subtype = employment.subtype - type = employment.type - additionalProperties = employment.additionalProperties.toMutableMap() + 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 [CustomField]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CustomField = + CustomField(name, value, additionalProperties.toMutableMap()) } - /** - * The secondary employment type of the individual. Options: `full_time`, `part_time`, - * `intern`, `temp`, `seasonal` and `individual_contractor`. - */ - fun subtype(subtype: Subtype?) = subtype(JsonField.ofNullable(subtype)) + private var validated: Boolean = false + + fun validate(): CustomField = apply { + if (validated) { + return@apply + } + + name() + value().ifPresent { it.validate() } + validated = true + } - /** Alias for calling [Builder.subtype] with `subtype.orElse(null)`. */ - fun subtype(subtype: Optional) = subtype(subtype.getOrNull()) + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + false + } /** - * Sets [Builder.subtype] to an arbitrary JSON value. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * You should usually call [Builder.subtype] with a well-typed [Subtype] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. + * Used for best match union deserialization. */ - fun subtype(subtype: JsonField) = apply { this.subtype = subtype } + @JvmSynthetic + internal fun validity(): Int = + (if (name.asKnown().isPresent) 1 else 0) + + (value.asKnown().getOrNull()?.validity() ?: 0) - /** The main employment type of the individual. */ - fun type(type: Type?) = type(JsonField.ofNullable(type)) + @JsonDeserialize(using = Value.Deserializer::class) + @JsonSerialize(using = Value.Serializer::class) + class Value + private constructor( + private val string: String? = null, + private val jsonValues: List? = null, + private val json: JsonValue? = null, + private val number: Double? = null, + private val bool: Boolean? = null, + private val _json: JsonValue? = null, + ) { - /** Alias for calling [Builder.type] with `type.orElse(null)`. */ - fun type(type: Optional) = type(type.getOrNull()) + fun string(): Optional = Optional.ofNullable(string) - /** - * Sets [Builder.type] to an arbitrary JSON value. - * - * You should usually call [Builder.type] with a well-typed [Type] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun type(type: JsonField) = apply { this.type = type } + fun jsonValues(): Optional> = Optional.ofNullable(jsonValues) - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun json(): Optional = Optional.ofNullable(json) - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun number(): Optional = Optional.ofNullable(number) - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } + fun bool(): Optional = Optional.ofNullable(bool) - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + fun isString(): Boolean = string != null + + fun isJsonValues(): Boolean = jsonValues != null + + fun isJson(): Boolean = json != null + + fun isNumber(): Boolean = number != null + + fun isBool(): Boolean = bool != null + + fun asString(): String = string.getOrThrow("string") + + fun asJsonValues(): List = jsonValues.getOrThrow("jsonValues") + + fun asJson(): JsonValue = json.getOrThrow("json") + + fun asNumber(): Double = number.getOrThrow("number") + + fun asBool(): Boolean = bool.getOrThrow("bool") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + string != null -> visitor.visitString(string) + jsonValues != null -> visitor.visitJsonValues(jsonValues) + json != null -> visitor.visitJson(json) + number != null -> visitor.visitNumber(number) + bool != null -> visitor.visitBool(bool) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Value = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitString(string: String) {} + + override fun visitJsonValues(jsonValues: List) {} + + override fun visitJson(json: JsonValue) {} + + override fun visitNumber(number: Double) {} + + override fun visitBool(bool: Boolean) {} + } + ) + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 = + accept( + object : Visitor { + override fun visitString(string: String) = 1 + + override fun visitJsonValues(jsonValues: List) = + jsonValues.size + + override fun visitJson(json: JsonValue) = 1 + + override fun visitNumber(number: Double) = 1 + + override fun visitBool(bool: Boolean) = 1 + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Value && string == other.string && jsonValues == other.jsonValues && json == other.json && number == other.number && bool == other.bool /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, jsonValues, json, number, bool) /* spotless:on */ + + override fun toString(): String = + when { + string != null -> "Value{string=$string}" + jsonValues != null -> "Value{jsonValues=$jsonValues}" + json != null -> "Value{json=$json}" + number != null -> "Value{number=$number}" + bool != null -> "Value{bool=$bool}" + _json != null -> "Value{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Value") + } + + companion object { + + @JvmStatic fun ofString(string: String) = Value(string = string) + + @JvmStatic + fun ofJsonValues(jsonValues: List) = Value(jsonValues = jsonValues) + + @JvmStatic fun ofJson(json: JsonValue) = Value(json = json) + + @JvmStatic fun ofNumber(number: Double) = Value(number = number) + + @JvmStatic fun ofBool(bool: Boolean) = Value(bool = bool) + } + + /** + * An interface that defines how to map each variant of [Value] to a value of type + * [T]. + */ + interface Visitor { + + fun visitString(string: String): T + + fun visitJsonValues(jsonValues: List): T + + fun visitJson(json: JsonValue): T + + fun visitNumber(number: Double): T + + fun visitBool(bool: Boolean): T + + /** + * Maps an unknown variant of [Value] to a value of type [T]. + * + * An instance of [Value] can contain an unknown variant if it was deserialized + * from data that doesn't match any known variant. For example, if the SDK is on + * an older version than the API, then the API may respond with new variants + * that the SDK is unaware of. + * + * @throws FinchInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw FinchInvalidDataException("Unknown Value: $json") + } + } + + internal class Deserializer : BaseDeserializer(Value::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Value { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Value(string = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef>())?.let { + Value(jsonValues = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(number = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(bool = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Value(json = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely + // incompatible with all the possible variants. + 0 -> Value(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use + // the first completely valid match, or simply the first match if none + // are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } + + internal class Serializer : BaseSerializer(Value::class) { + + override fun serialize( + value: Value, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.string != null -> generator.writeObject(value.string) + value.jsonValues != null -> generator.writeObject(value.jsonValues) + value.json != null -> generator.writeObject(value.json) + value.number != null -> generator.writeObject(value.number) + value.bool != null -> generator.writeObject(value.bool) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Value") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CustomField && name == other.name && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, value, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CustomField{name=$name, value=$value, additionalProperties=$additionalProperties}" + } + + /** The department object. */ + class Department + private constructor( + private val name: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of() + ) : this(name, mutableMapOf()) + + /** + * The name of the department associated with the individual. + * + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun name(): Optional = name.getOptional("name") + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @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 [Department]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Department]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(department: Department) = apply { + name = department.name + additionalProperties = department.additionalProperties.toMutableMap() + } + + /** The name of the department associated with the individual. */ + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + 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 [Department]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Department = + Department(checkRequired("name", name), additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Department = apply { + if (validated) { + return@apply + } + + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Department && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Department{name=$name, additionalProperties=$additionalProperties}" + } + + /** The employment object. */ + class Employment + private constructor( + private val subtype: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("subtype") + @ExcludeMissing + subtype: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(subtype, type, mutableMapOf()) + + /** + * The secondary employment type of the individual. Options: `full_time`, `part_time`, + * `intern`, `temp`, `seasonal` and `individual_contractor`. + * + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun subtype(): Optional = subtype.getOptional("subtype") + + /** + * The main employment type of the individual. + * + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [subtype]. + * + * Unlike [subtype], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("subtype") @ExcludeMissing fun _subtype(): JsonField = subtype + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @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 [Employment]. + * + * The following fields are required: + * ```java + * .subtype() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Employment]. */ + class Builder internal constructor() { + + private var subtype: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(employment: Employment) = apply { + subtype = employment.subtype + type = employment.type + additionalProperties = employment.additionalProperties.toMutableMap() + } + + /** + * The secondary employment type of the individual. Options: `full_time`, + * `part_time`, `intern`, `temp`, `seasonal` and `individual_contractor`. + */ + fun subtype(subtype: Subtype?) = subtype(JsonField.ofNullable(subtype)) + + /** Alias for calling [Builder.subtype] with `subtype.orElse(null)`. */ + fun subtype(subtype: Optional) = subtype(subtype.getOrNull()) + + /** + * Sets [Builder.subtype] to an arbitrary JSON value. + * + * You should usually call [Builder.subtype] with a well-typed [Subtype] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun subtype(subtype: JsonField) = apply { this.subtype = subtype } + + /** The main employment type of the individual. */ + fun type(type: Type?) = type(JsonField.ofNullable(type)) + + /** Alias for calling [Builder.type] with `type.orElse(null)`. */ + fun type(type: Optional) = type(type.getOrNull()) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + 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 [Employment]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .subtype() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Employment = + Employment( + checkRequired("subtype", subtype), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Employment = apply { + if (validated) { + return@apply + } + + subtype().ifPresent { it.validate() } + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 = + (subtype.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + /** + * The secondary employment type of the individual. Options: `full_time`, `part_time`, + * `intern`, `temp`, `seasonal` and `individual_contractor`. + */ + class Subtype @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val FULL_TIME = of("full_time") + + @JvmField val INTERN = of("intern") + + @JvmField val PART_TIME = of("part_time") + + @JvmField val TEMP = of("temp") + + @JvmField val SEASONAL = of("seasonal") + + @JvmField val INDIVIDUAL_CONTRACTOR = of("individual_contractor") + + @JvmStatic fun of(value: String) = Subtype(JsonField.of(value)) + } + + /** An enum containing [Subtype]'s known values. */ + enum class Known { + FULL_TIME, + INTERN, + PART_TIME, + TEMP, + SEASONAL, + INDIVIDUAL_CONTRACTOR, + } + + /** + * An enum containing [Subtype]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Subtype] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + FULL_TIME, + INTERN, + PART_TIME, + TEMP, + SEASONAL, + INDIVIDUAL_CONTRACTOR, + /** + * An enum member indicating that [Subtype] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + FULL_TIME -> Value.FULL_TIME + INTERN -> Value.INTERN + PART_TIME -> Value.PART_TIME + TEMP -> Value.TEMP + SEASONAL -> Value.SEASONAL + INDIVIDUAL_CONTRACTOR -> Value.INDIVIDUAL_CONTRACTOR + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws FinchInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + FULL_TIME -> Known.FULL_TIME + INTERN -> Known.INTERN + PART_TIME -> Known.PART_TIME + TEMP -> Known.TEMP + SEASONAL -> Known.SEASONAL + INDIVIDUAL_CONTRACTOR -> Known.INDIVIDUAL_CONTRACTOR + else -> throw FinchInvalidDataException("Unknown Subtype: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws FinchInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + FinchInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Subtype = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Subtype && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** The main employment type of the individual. */ + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val EMPLOYEE = of("employee") + + @JvmField val CONTRACTOR = of("contractor") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + EMPLOYEE, + CONTRACTOR, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + EMPLOYEE, + CONTRACTOR, + /** + * An enum member indicating that [Type] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + EMPLOYEE -> Value.EMPLOYEE + CONTRACTOR -> Value.CONTRACTOR + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws FinchInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + EMPLOYEE -> Known.EMPLOYEE + CONTRACTOR -> Known.CONTRACTOR + else -> throw FinchInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws FinchInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + FinchInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 (value() == Value._UNKNOWN) 0 else 1 - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * Returns an immutable instance of [Employment]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Employment = Employment(subtype, type, additionalProperties.toMutableMap()) - } + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } - private var validated: Boolean = false + override fun hashCode() = value.hashCode() - fun validate(): Employment = apply { - if (validated) { - return@apply + override fun toString() = value.toString() } - subtype().ifPresent { it.validate() } - type().ifPresent { it.validate() } - validated = true - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false + return /* spotless:off */ other is Employment && subtype == other.subtype && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } - /** - * 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 = - (subtype.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(subtype, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Employment{subtype=$subtype, type=$type, additionalProperties=$additionalProperties}" + } /** - * The secondary employment type of the individual. Options: `full_time`, `part_time`, - * `intern`, `temp`, `seasonal` and `individual_contractor`. + * The detailed employment status of the individual. Available options: `active`, + * `deceased`, `leave`, `onboarding`, `prehire`, `retired`, `terminated`. */ - class Subtype @JsonCreator private constructor(private val value: JsonField) : - Enum { + class EmploymentStatus + @JsonCreator + private constructor(private val value: JsonField) : Enum { /** * Returns this class instance's raw value. @@ -1421,49 +2326,55 @@ private constructor( companion object { - @JvmField val FULL_TIME = of("full_time") + @JvmField val ACTIVE = of("active") - @JvmField val INTERN = of("intern") + @JvmField val DECEASED = of("deceased") - @JvmField val PART_TIME = of("part_time") + @JvmField val LEAVE = of("leave") - @JvmField val TEMP = of("temp") + @JvmField val ONBOARDING = of("onboarding") - @JvmField val SEASONAL = of("seasonal") + @JvmField val PREHIRE = of("prehire") - @JvmField val INDIVIDUAL_CONTRACTOR = of("individual_contractor") + @JvmField val RETIRED = of("retired") - @JvmStatic fun of(value: String) = Subtype(JsonField.of(value)) + @JvmField val TERMINATED = of("terminated") + + @JvmStatic fun of(value: String) = EmploymentStatus(JsonField.of(value)) } - /** An enum containing [Subtype]'s known values. */ + /** An enum containing [EmploymentStatus]'s known values. */ enum class Known { - FULL_TIME, - INTERN, - PART_TIME, - TEMP, - SEASONAL, - INDIVIDUAL_CONTRACTOR, + ACTIVE, + DECEASED, + LEAVE, + ONBOARDING, + PREHIRE, + RETIRED, + TERMINATED, } /** - * An enum containing [Subtype]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [EmploymentStatus]'s known values, as well as an [_UNKNOWN] + * member. * - * An instance of [Subtype] can contain an unknown value in a couple of cases: + * An instance of [EmploymentStatus] can contain an unknown value in a couple of cases: * - It was deserialized from data that doesn't match any known member. For example, if * the SDK is on an older version than the API, then the API may respond with new * members that the SDK is unaware of. * - It was constructed with an arbitrary value using the [of] method. */ enum class Value { - FULL_TIME, - INTERN, - PART_TIME, - TEMP, - SEASONAL, - INDIVIDUAL_CONTRACTOR, + ACTIVE, + DECEASED, + LEAVE, + ONBOARDING, + PREHIRE, + RETIRED, + TERMINATED, /** - * An enum member indicating that [Subtype] was instantiated with an unknown value. + * An enum member indicating that [EmploymentStatus] was instantiated with an + * unknown value. */ _UNKNOWN, } @@ -1477,12 +2388,13 @@ private constructor( */ fun value(): Value = when (this) { - FULL_TIME -> Value.FULL_TIME - INTERN -> Value.INTERN - PART_TIME -> Value.PART_TIME - TEMP -> Value.TEMP - SEASONAL -> Value.SEASONAL - INDIVIDUAL_CONTRACTOR -> Value.INDIVIDUAL_CONTRACTOR + ACTIVE -> Value.ACTIVE + DECEASED -> Value.DECEASED + LEAVE -> Value.LEAVE + ONBOARDING -> Value.ONBOARDING + PREHIRE -> Value.PREHIRE + RETIRED -> Value.RETIRED + TERMINATED -> Value.TERMINATED else -> Value._UNKNOWN } @@ -1497,13 +2409,14 @@ private constructor( */ fun known(): Known = when (this) { - FULL_TIME -> Known.FULL_TIME - INTERN -> Known.INTERN - PART_TIME -> Known.PART_TIME - TEMP -> Known.TEMP - SEASONAL -> Known.SEASONAL - INDIVIDUAL_CONTRACTOR -> Known.INDIVIDUAL_CONTRACTOR - else -> throw FinchInvalidDataException("Unknown Subtype: $value") + ACTIVE -> Known.ACTIVE + DECEASED -> Known.DECEASED + LEAVE -> Known.LEAVE + ONBOARDING -> Known.ONBOARDING + PREHIRE -> Known.PREHIRE + RETIRED -> Known.RETIRED + TERMINATED -> Known.TERMINATED + else -> throw FinchInvalidDataException("Unknown EmploymentStatus: $value") } /** @@ -1522,7 +2435,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Subtype = apply { + fun validate(): EmploymentStatus = apply { if (validated) { return@apply } @@ -1552,7 +2465,7 @@ private constructor( return true } - return /* spotless:off */ other is Subtype && value == other.value /* spotless:on */ + return /* spotless:off */ other is EmploymentStatus && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() @@ -1560,102 +2473,129 @@ private constructor( override fun toString() = value.toString() } - /** The main employment type of the individual. */ - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + /** The manager object representing the manager of the individual within the org. */ + class Manager + private constructor( + private val id: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() + ) : this(id, mutableMapOf()) /** - * Returns this class instance's raw value. + * A stable Finch `id` (UUID v4) for an individual in the company. * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. For example, if the SDK is - * on an older version than the API, then the API may respond with new members that the - * SDK is unaware of. + * @throws FinchInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + fun id(): String = id.getRequired("id") - companion object { + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JvmField val EMPLOYEE = of("employee") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - @JvmField val CONTRACTOR = of("contractor") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } + fun toBuilder() = Builder().from(this) - /** An enum containing [Type]'s known values. */ - enum class Known { - EMPLOYEE, - CONTRACTOR, - } + companion object { - /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Type] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - EMPLOYEE, - CONTRACTOR, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ - _UNKNOWN, + /** + * Returns a mutable builder for constructing an instance of [Manager]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() } - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you - * want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - EMPLOYEE -> Value.EMPLOYEE - CONTRACTOR -> Value.CONTRACTOR - else -> Value._UNKNOWN + /** A builder for [Manager]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(manager: Manager) = apply { + id = manager.id + additionalProperties = manager.additionalProperties.toMutableMap() } - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws FinchInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - EMPLOYEE -> Known.EMPLOYEE - CONTRACTOR -> Known.CONTRACTOR - else -> throw FinchInvalidDataException("Unknown Type: $value") + /** A stable Finch `id` (UUID v4) for an individual in the company. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) } - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws FinchInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - FinchInvalidDataException("Value is not a String") + 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 [Manager]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Manager = + Manager(checkRequired("id", id), additionalProperties.toMutableMap()) + } + private var validated: Boolean = false - fun validate(): Type = apply { + fun validate(): Manager = apply { if (validated) { return@apply } - known() + id() validated = true } @@ -1673,19 +2613,23 @@ private constructor( * * Used for best match union deserialization. */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + @JvmSynthetic internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return /* spotless:off */ other is Manager && id == other.id && additionalProperties == other.additionalProperties /* spotless:on */ } - override fun hashCode() = value.hashCode() + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + /* spotless:on */ - override fun toString() = value.toString() + override fun hashCode(): Int = hashCode + + override fun toString() = "Manager{id=$id, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1693,207 +2637,89 @@ private constructor( return true } - return /* spotless:off */ other is Employment && subtype == other.subtype && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is UnionMember0 && id == other.id && classCode == other.classCode && customFields == other.customFields && department == other.department && employment == other.employment && employmentStatus == other.employmentStatus && endDate == other.endDate && firstName == other.firstName && isActive == other.isActive && lastName == other.lastName && latestRehireDate == other.latestRehireDate && location == other.location && manager == other.manager && middleName == other.middleName && sourceId == other.sourceId && startDate == other.startDate && title == other.title && workId == other.workId && income == other.income && incomeHistory == other.incomeHistory && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(subtype, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(id, classCode, customFields, department, employment, employmentStatus, endDate, firstName, isActive, lastName, latestRehireDate, location, manager, middleName, sourceId, startDate, title, workId, income, incomeHistory, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Employment{subtype=$subtype, type=$type, additionalProperties=$additionalProperties}" + "UnionMember0{id=$id, classCode=$classCode, customFields=$customFields, department=$department, employment=$employment, employmentStatus=$employmentStatus, endDate=$endDate, firstName=$firstName, isActive=$isActive, lastName=$lastName, latestRehireDate=$latestRehireDate, location=$location, manager=$manager, middleName=$middleName, sourceId=$sourceId, startDate=$startDate, title=$title, workId=$workId, income=$income, incomeHistory=$incomeHistory, additionalProperties=$additionalProperties}" } - /** - * The detailed employment status of the individual. Available options: `active`, `deceased`, - * `leave`, `onboarding`, `prehire`, `retired`, `terminated`. - */ - class EmploymentStatus @JsonCreator private constructor(private val value: JsonField) : - Enum { + class BatchError + private constructor( + private val code: JsonField, + private val message: JsonField, + private val name: JsonField, + private val finchCode: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("code") @ExcludeMissing code: JsonField = JsonMissing.of(), + @JsonProperty("message") @ExcludeMissing message: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("finch_code") + @ExcludeMissing + finchCode: JsonField = JsonMissing.of(), + ) : this(code, message, name, finchCode, mutableMapOf()) /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. For example, if the SDK is on an - * older version than the API, then the API may respond with new members that the SDK is - * unaware of. + * @throws FinchInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val ACTIVE = of("active") - - @JvmField val DECEASED = of("deceased") - - @JvmField val LEAVE = of("leave") - - @JvmField val ONBOARDING = of("onboarding") - - @JvmField val PREHIRE = of("prehire") - - @JvmField val RETIRED = of("retired") - - @JvmField val TERMINATED = of("terminated") - - @JvmStatic fun of(value: String) = EmploymentStatus(JsonField.of(value)) - } - - /** An enum containing [EmploymentStatus]'s known values. */ - enum class Known { - ACTIVE, - DECEASED, - LEAVE, - ONBOARDING, - PREHIRE, - RETIRED, - TERMINATED, - } + fun code(): Double = code.getRequired("code") /** - * An enum containing [EmploymentStatus]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [EmploymentStatus] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, if the - * SDK is on an older version than the API, then the API may respond with new members that - * the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. + * @throws FinchInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - enum class Value { - ACTIVE, - DECEASED, - LEAVE, - ONBOARDING, - PREHIRE, - RETIRED, - TERMINATED, - /** - * An enum member indicating that [EmploymentStatus] was instantiated with an unknown - * value. - */ - _UNKNOWN, - } + fun message(): String = message.getRequired("message") /** - * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] - * if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you want - * to throw for the unknown case. + * @throws FinchInvalidDataException 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 value(): Value = - when (this) { - ACTIVE -> Value.ACTIVE - DECEASED -> Value.DECEASED - LEAVE -> Value.LEAVE - ONBOARDING -> Value.ONBOARDING - PREHIRE -> Value.PREHIRE - RETIRED -> Value.RETIRED - TERMINATED -> Value.TERMINATED - else -> Value._UNKNOWN - } + fun name(): String = name.getRequired("name") /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and don't - * want to throw for the unknown case. - * - * @throws FinchInvalidDataException if this class instance's value is a not a known member. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun known(): Known = - when (this) { - ACTIVE -> Known.ACTIVE - DECEASED -> Known.DECEASED - LEAVE -> Known.LEAVE - ONBOARDING -> Known.ONBOARDING - PREHIRE -> Known.PREHIRE - RETIRED -> Known.RETIRED - TERMINATED -> Known.TERMINATED - else -> throw FinchInvalidDataException("Unknown EmploymentStatus: $value") - } + fun finchCode(): Optional = finchCode.getOptional("finch_code") /** - * Returns this class instance's primitive wire representation. + * Returns the raw JSON value of [code]. * - * This differs from the [toString] method because that method is primarily for debugging - * and generally doesn't throw. - * - * @throws FinchInvalidDataException if this class instance's value does not have the - * expected primitive type. + * Unlike [code], this method doesn't throw if the JSON field has an unexpected type. */ - fun asString(): String = - _value().asString().orElseThrow { FinchInvalidDataException("Value is not a String") } - - private var validated: Boolean = false - - fun validate(): EmploymentStatus = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false - } + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code /** - * Returns a score indicating how many valid values are contained in this object - * recursively. + * Returns the raw JSON value of [message]. * - * Used for best match union deserialization. + * Unlike [message], this method doesn't throw if the JSON field has an unexpected type. */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is EmploymentStatus && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - /** The manager object representing the manager of the individual within the org. */ - class Manager - private constructor( - private val id: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of() - ) : this(id, mutableMapOf()) + @JsonProperty("message") @ExcludeMissing fun _message(): JsonField = message /** - * A stable Finch `id` (UUID v4) for an individual in the company. + * Returns the raw JSON value of [name]. * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. */ - fun id(): Optional = id.getOptional("id") + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name /** - * Returns the raw JSON value of [id]. + * Returns the raw JSON value of [finchCode]. * - * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [finchCode], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + @JsonProperty("finch_code") @ExcludeMissing fun _finchCode(): JsonField = finchCode @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -1909,33 +2735,80 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Manager]. */ + /** + * Returns a mutable builder for constructing an instance of [BatchError]. + * + * The following fields are required: + * ```java + * .code() + * .message() + * .name() + * ``` + */ @JvmStatic fun builder() = Builder() } - /** A builder for [Manager]. */ + /** A builder for [BatchError]. */ class Builder internal constructor() { - private var id: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var message: JsonField? = null + private var name: JsonField? = null + private var finchCode: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(manager: Manager) = apply { - id = manager.id - additionalProperties = manager.additionalProperties.toMutableMap() + internal fun from(batchError: BatchError) = apply { + code = batchError.code + message = batchError.message + name = batchError.name + finchCode = batchError.finchCode + additionalProperties = batchError.additionalProperties.toMutableMap() } - /** A stable Finch `id` (UUID v4) for an individual in the company. */ - fun id(id: String) = id(JsonField.of(id)) + fun code(code: Double) = code(JsonField.of(code)) /** - * Sets [Builder.id] to an arbitrary JSON value. + * Sets [Builder.code] to an arbitrary JSON value. * - * You should usually call [Builder.id] with a well-typed [String] value instead. This + * You should usually call [Builder.code] with a well-typed [Double] value instead. This * method is primarily for setting the field to an undocumented or not yet supported * value. */ - fun id(id: JsonField) = apply { this.id = id } + fun code(code: JsonField) = apply { this.code = code } + + fun message(message: String) = message(JsonField.of(message)) + + /** + * Sets [Builder.message] to an arbitrary JSON value. + * + * You should usually call [Builder.message] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun message(message: JsonField) = apply { this.message = message } + + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun finchCode(finchCode: String) = finchCode(JsonField.of(finchCode)) + + /** + * Sets [Builder.finchCode] to an arbitrary JSON value. + * + * You should usually call [Builder.finchCode] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun finchCode(finchCode: JsonField) = apply { this.finchCode = finchCode } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -1957,21 +2830,40 @@ private constructor( } /** - * Returns an immutable instance of [Manager]. + * Returns an immutable instance of [BatchError]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .code() + * .message() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Manager = Manager(id, additionalProperties.toMutableMap()) + fun build(): BatchError = + BatchError( + checkRequired("code", code), + checkRequired("message", message), + checkRequired("name", name), + finchCode, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): Manager = apply { + fun validate(): BatchError = apply { if (validated) { return@apply } - id() + code() + message() + name() + finchCode() validated = true } @@ -1989,39 +2881,28 @@ private constructor( * * Used for best match union deserialization. */ - @JvmSynthetic internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + @JvmSynthetic + internal fun validity(): Int = + (if (code.asKnown().isPresent) 1 else 0) + + (if (message.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (finchCode.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Manager && id == other.id && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is BatchError && code == other.code && message == other.message && name == other.name && finchCode == other.finchCode && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(code, message, name, finchCode, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode - override fun toString() = "Manager{id=$id, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is EmploymentData && id == other.id && classCode == other.classCode && customFields == other.customFields && department == other.department && employment == other.employment && employmentStatus == other.employmentStatus && endDate == other.endDate && firstName == other.firstName && income == other.income && incomeHistory == other.incomeHistory && isActive == other.isActive && lastName == other.lastName && latestRehireDate == other.latestRehireDate && location == other.location && manager == other.manager && middleName == other.middleName && sourceId == other.sourceId && startDate == other.startDate && title == other.title && workId == other.workId && additionalProperties == other.additionalProperties /* spotless:on */ + override fun toString() = + "BatchError{code=$code, message=$message, name=$name, finchCode=$finchCode, additionalProperties=$additionalProperties}" } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, classCode, customFields, department, employment, employmentStatus, endDate, firstName, income, incomeHistory, isActive, lastName, latestRehireDate, location, manager, middleName, sourceId, startDate, title, workId, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "EmploymentData{id=$id, classCode=$classCode, customFields=$customFields, department=$department, employment=$employment, employmentStatus=$employmentStatus, endDate=$endDate, firstName=$firstName, income=$income, incomeHistory=$incomeHistory, isActive=$isActive, lastName=$lastName, latestRehireDate=$latestRehireDate, location=$location, manager=$manager, middleName=$middleName, sourceId=$sourceId, startDate=$startDate, title=$title, workId=$workId, additionalProperties=$additionalProperties}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/EmploymentDataResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/EmploymentDataResponse.kt index 4f8bcca8..5066700c 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/EmploymentDataResponse.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/EmploymentDataResponse.kt @@ -10,10 +10,10 @@ import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects -import java.util.Optional import kotlin.jvm.optionals.getOrNull class EmploymentDataResponse @@ -34,24 +34,24 @@ private constructor( ) : this(body, code, individualId, mutableMapOf()) /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws FinchInvalidDataException 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 body(): Optional = body.getOptional("body") + fun body(): EmploymentData = body.getRequired("body") /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws FinchInvalidDataException 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 code(): Optional = code.getOptional("code") + fun code(): Long = code.getRequired("code") /** * A stable Finch `id` (UUID v4) for an individual in the company. * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws FinchInvalidDataException 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 individualId(): Optional = individualId.getOptional("individual_id") + fun individualId(): String = individualId.getRequired("individual_id") /** * Returns the raw JSON value of [body]. @@ -90,16 +90,25 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [EmploymentDataResponse]. */ + /** + * Returns a mutable builder for constructing an instance of [EmploymentDataResponse]. + * + * The following fields are required: + * ```java + * .body() + * .code() + * .individualId() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [EmploymentDataResponse]. */ class Builder internal constructor() { - private var body: JsonField = JsonMissing.of() - private var code: JsonField = JsonMissing.of() - private var individualId: JsonField = JsonMissing.of() + private var body: JsonField? = null + private var code: JsonField? = null + private var individualId: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -121,6 +130,14 @@ private constructor( */ fun body(body: JsonField) = apply { this.body = body } + /** Alias for calling [body] with `EmploymentData.ofUnionMember0(unionMember0)`. */ + fun body(unionMember0: EmploymentData.UnionMember0) = + body(EmploymentData.ofUnionMember0(unionMember0)) + + /** Alias for calling [body] with `EmploymentData.ofBatchError(batchError)`. */ + fun body(batchError: EmploymentData.BatchError) = + body(EmploymentData.ofBatchError(batchError)) + fun code(code: Long) = code(JsonField.of(code)) /** @@ -168,9 +185,23 @@ private constructor( * Returns an immutable instance of [EmploymentDataResponse]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .body() + * .code() + * .individualId() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): EmploymentDataResponse = - EmploymentDataResponse(body, code, individualId, additionalProperties.toMutableMap()) + EmploymentDataResponse( + checkRequired("body", body), + checkRequired("code", code), + checkRequired("individualId", individualId), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -180,7 +211,7 @@ private constructor( return@apply } - body().ifPresent { it.validate() } + body().validate() code() individualId() validated = true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitCreateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitCreateParams.kt index 72a4557e..80d41eaa 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitCreateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitCreateParams.kt @@ -6,13 +6,16 @@ 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 com.tryfinch.api.core.Enum import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.Params +import com.tryfinch.api.core.checkKnown import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams +import com.tryfinch.api.core.toImmutable import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects @@ -30,6 +33,15 @@ private constructor( private val additionalQueryParams: QueryParams, ) : Params { + /** + * The company match for this benefit. + * + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun companyContribution(): Optional = + body.companyContribution() + /** * Name of the benefit as it appears in the provider and pay statements. Recommend limiting this * to <30 characters due to limitations in specific providers (e.g. Justworks). @@ -55,6 +67,15 @@ private constructor( */ fun type(): Optional = body.type() + /** + * Returns the raw JSON value of [companyContribution]. + * + * Unlike [companyContribution], this method doesn't throw if the JSON field has an unexpected + * type. + */ + fun _companyContribution(): JsonField = + body._companyContribution() + /** * Returns the raw JSON value of [description]. * @@ -111,12 +132,36 @@ private constructor( * * This is generally only useful if you are already constructing the body separately. * Otherwise, it's more convenient to use the top-level setters instead: + * - [companyContribution] * - [description] * - [frequency] * - [type] */ fun body(body: Body) = apply { this.body = body.toBuilder() } + /** The company match for this benefit. */ + fun companyContribution(companyContribution: BenefitCompanyMatchContribution?) = apply { + body.companyContribution(companyContribution) + } + + /** + * Alias for calling [Builder.companyContribution] with `companyContribution.orElse(null)`. + */ + fun companyContribution(companyContribution: Optional) = + companyContribution(companyContribution.getOrNull()) + + /** + * Sets [Builder.companyContribution] to an arbitrary JSON value. + * + * You should usually call [Builder.companyContribution] with a well-typed + * [BenefitCompanyMatchContribution] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun companyContribution(companyContribution: JsonField) = + apply { + body.companyContribution(companyContribution) + } + /** * Name of the benefit as it appears in the provider and pay statements. Recommend limiting * this to <30 characters due to limitations in specific providers (e.g. Justworks). @@ -300,6 +345,7 @@ private constructor( class Body private constructor( + private val companyContribution: JsonField, private val description: JsonField, private val frequency: JsonField, private val type: JsonField, @@ -308,6 +354,9 @@ private constructor( @JsonCreator private constructor( + @JsonProperty("company_contribution") + @ExcludeMissing + companyContribution: JsonField = JsonMissing.of(), @JsonProperty("description") @ExcludeMissing description: JsonField = JsonMissing.of(), @@ -315,7 +364,16 @@ private constructor( @ExcludeMissing frequency: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(description, frequency, type, mutableMapOf()) + ) : this(companyContribution, description, frequency, type, mutableMapOf()) + + /** + * The company match for this benefit. + * + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun companyContribution(): Optional = + companyContribution.getOptional("company_contribution") /** * Name of the benefit as it appears in the provider and pay statements. Recommend limiting @@ -342,6 +400,16 @@ private constructor( */ fun type(): Optional = type.getOptional("type") + /** + * Returns the raw JSON value of [companyContribution]. + * + * Unlike [companyContribution], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("company_contribution") + @ExcludeMissing + fun _companyContribution(): JsonField = companyContribution + /** * Returns the raw JSON value of [description]. * @@ -388,6 +456,8 @@ private constructor( /** A builder for [Body]. */ class Builder internal constructor() { + private var companyContribution: JsonField = + JsonMissing.of() private var description: JsonField = JsonMissing.of() private var frequency: JsonField = JsonMissing.of() private var type: JsonField = JsonMissing.of() @@ -395,12 +465,36 @@ private constructor( @JvmSynthetic internal fun from(body: Body) = apply { + companyContribution = body.companyContribution description = body.description frequency = body.frequency type = body.type additionalProperties = body.additionalProperties.toMutableMap() } + /** The company match for this benefit. */ + fun companyContribution(companyContribution: BenefitCompanyMatchContribution?) = + companyContribution(JsonField.ofNullable(companyContribution)) + + /** + * Alias for calling [Builder.companyContribution] with + * `companyContribution.orElse(null)`. + */ + fun companyContribution( + companyContribution: Optional + ) = companyContribution(companyContribution.getOrNull()) + + /** + * Sets [Builder.companyContribution] to an arbitrary JSON value. + * + * You should usually call [Builder.companyContribution] with a well-typed + * [BenefitCompanyMatchContribution] value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun companyContribution( + companyContribution: JsonField + ) = apply { this.companyContribution = companyContribution } + /** * Name of the benefit as it appears in the provider and pay statements. Recommend * limiting this to <30 characters due to limitations in specific providers (e.g. @@ -476,7 +570,13 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): Body = - Body(description, frequency, type, additionalProperties.toMutableMap()) + Body( + companyContribution, + description, + frequency, + type, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -486,6 +586,7 @@ private constructor( return@apply } + companyContribution().ifPresent { it.validate() } description() frequency().ifPresent { it.validate() } type().ifPresent { it.validate() } @@ -508,7 +609,8 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (description.asKnown().isPresent) 1 else 0) + + (companyContribution.asKnown().getOrNull()?.validity() ?: 0) + + (if (description.asKnown().isPresent) 1 else 0) + (frequency.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) @@ -517,17 +619,507 @@ private constructor( return true } - return /* spotless:off */ other is Body && description == other.description && frequency == other.frequency && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Body && companyContribution == other.companyContribution && description == other.description && frequency == other.frequency && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(companyContribution, description, frequency, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{companyContribution=$companyContribution, description=$description, frequency=$frequency, type=$type, additionalProperties=$additionalProperties}" + } + + /** The company match for this benefit. */ + class BenefitCompanyMatchContribution + private constructor( + private val tiers: JsonField>, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("tiers") @ExcludeMissing tiers: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(tiers, type, mutableMapOf()) + + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun tiers(): Optional> = tiers.getOptional("tiers") + + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [tiers]. + * + * Unlike [tiers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tiers") @ExcludeMissing fun _tiers(): JsonField> = tiers + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @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 + * [BenefitCompanyMatchContribution]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BenefitCompanyMatchContribution]. */ + class Builder internal constructor() { + + private var tiers: JsonField>? = null + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(benefitCompanyMatchContribution: BenefitCompanyMatchContribution) = + apply { + tiers = benefitCompanyMatchContribution.tiers.map { it.toMutableList() } + type = benefitCompanyMatchContribution.type + additionalProperties = + benefitCompanyMatchContribution.additionalProperties.toMutableMap() + } + + fun tiers(tiers: List) = tiers(JsonField.of(tiers)) + + /** + * Sets [Builder.tiers] to an arbitrary JSON value. + * + * You should usually call [Builder.tiers] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun tiers(tiers: JsonField>) = apply { + this.tiers = tiers.map { it.toMutableList() } + } + + /** + * Adds a single [Tier] to [tiers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addTier(tier: Tier) = apply { + tiers = + (tiers ?: JsonField.of(mutableListOf())).also { + checkKnown("tiers", it).add(tier) + } + } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonField) = apply { this.type = type } + + 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 [BenefitCompanyMatchContribution]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BenefitCompanyMatchContribution = + BenefitCompanyMatchContribution( + (tiers ?: JsonMissing.of()).map { it.toImmutable() }, + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BenefitCompanyMatchContribution = apply { + if (validated) { + return@apply + } + + tiers().ifPresent { it.forEach { it.validate() } } + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 = + (tiers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Tier + private constructor( + private val match: JsonField, + private val threshold: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("match") @ExcludeMissing match: JsonField = JsonMissing.of(), + @JsonProperty("threshold") + @ExcludeMissing + threshold: JsonField = JsonMissing.of(), + ) : this(match, threshold, mutableMapOf()) + + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun match(): Optional = match.getOptional("match") + + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun threshold(): Optional = threshold.getOptional("threshold") + + /** + * Returns the raw JSON value of [match]. + * + * Unlike [match], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("match") @ExcludeMissing fun _match(): JsonField = match + + /** + * Returns the raw JSON value of [threshold]. + * + * Unlike [threshold], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("threshold") @ExcludeMissing fun _threshold(): JsonField = threshold + + @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 [Tier]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Tier]. */ + class Builder internal constructor() { + + private var match: JsonField = JsonMissing.of() + private var threshold: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(tier: Tier) = apply { + match = tier.match + threshold = tier.threshold + additionalProperties = tier.additionalProperties.toMutableMap() + } + + fun match(match: Long) = match(JsonField.of(match)) + + /** + * Sets [Builder.match] to an arbitrary JSON value. + * + * You should usually call [Builder.match] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun match(match: JsonField) = apply { this.match = match } + + fun threshold(threshold: Long) = threshold(JsonField.of(threshold)) + + /** + * Sets [Builder.threshold] to an arbitrary JSON value. + * + * You should usually call [Builder.threshold] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun threshold(threshold: JsonField) = apply { this.threshold = threshold } + + 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 [Tier]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Tier = Tier(match, threshold, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Tier = apply { + if (validated) { + return@apply + } + + match() + threshold() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 (match.asKnown().isPresent) 1 else 0) + + (if (threshold.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Tier && match == other.match && threshold == other.threshold && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(match, threshold, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Tier{match=$match, threshold=$threshold, additionalProperties=$additionalProperties}" + } + + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val MATCH = of("match") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + MATCH + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + MATCH, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + MATCH -> Value.MATCH + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws FinchInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + MATCH -> Known.MATCH + else -> throw FinchInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws FinchInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + FinchInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BenefitCompanyMatchContribution && tiers == other.tiers && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(description, frequency, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(tiers, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Body{description=$description, frequency=$frequency, type=$type, additionalProperties=$additionalProperties}" + "BenefitCompanyMatchContribution{tiers=$tiers, type=$type, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Income.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Income.kt index 03ac872e..99e6b081 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Income.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Income.kt @@ -11,6 +11,7 @@ import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects @@ -118,17 +119,27 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Income]. */ + /** + * Returns a mutable builder for constructing an instance of [Income]. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .effectiveDate() + * .unit() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Income]. */ class Builder internal constructor() { - private var amount: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var effectiveDate: JsonField = JsonMissing.of() - private var unit: JsonField = JsonMissing.of() + private var amount: JsonField? = null + private var currency: JsonField? = null + private var effectiveDate: JsonField? = null + private var unit: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -234,9 +245,25 @@ private constructor( * Returns an immutable instance of [Income]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .effectiveDate() + * .unit() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Income = - Income(amount, currency, effectiveDate, unit, additionalProperties.toMutableMap()) + Income( + checkRequired("amount", amount), + checkRequired("currency", currency), + checkRequired("effectiveDate", effectiveDate), + checkRequired("unit", unit), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Individual.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Individual.kt index bffd234c..5197ccd9 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Individual.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Individual.kt @@ -6,12 +6,24 @@ 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 com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.tryfinch.api.core.BaseDeserializer +import com.tryfinch.api.core.BaseSerializer import com.tryfinch.api.core.Enum import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue +import com.tryfinch.api.core.allMaxBy import com.tryfinch.api.core.checkKnown +import com.tryfinch.api.core.checkRequired +import com.tryfinch.api.core.getOrThrow import com.tryfinch.api.core.toImmutable import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections @@ -19,679 +31,445 @@ import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull +@JsonDeserialize(using = Individual.Deserializer::class) +@JsonSerialize(using = Individual.Serializer::class) class Individual private constructor( - private val id: JsonField, - private val dob: JsonField, - private val emails: JsonField>, - private val encryptedSsn: JsonField, - private val ethnicity: JsonField, - private val firstName: JsonField, - private val gender: JsonField, - private val lastName: JsonField, - private val middleName: JsonField, - private val phoneNumbers: JsonField>, - private val preferredName: JsonField, - private val residence: JsonField, - private val ssn: JsonField, - private val additionalProperties: MutableMap, + private val unionMember0: UnionMember0? = null, + private val batchError: BatchError? = null, + private val _json: JsonValue? = null, ) { - @JsonCreator - private constructor( - @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), - @JsonProperty("dob") @ExcludeMissing dob: JsonField = JsonMissing.of(), - @JsonProperty("emails") @ExcludeMissing emails: JsonField> = JsonMissing.of(), - @JsonProperty("encrypted_ssn") - @ExcludeMissing - encryptedSsn: JsonField = JsonMissing.of(), - @JsonProperty("ethnicity") - @ExcludeMissing - ethnicity: JsonField = JsonMissing.of(), - @JsonProperty("first_name") @ExcludeMissing firstName: JsonField = JsonMissing.of(), - @JsonProperty("gender") @ExcludeMissing gender: JsonField = JsonMissing.of(), - @JsonProperty("last_name") @ExcludeMissing lastName: JsonField = JsonMissing.of(), - @JsonProperty("middle_name") - @ExcludeMissing - middleName: JsonField = JsonMissing.of(), - @JsonProperty("phone_numbers") - @ExcludeMissing - phoneNumbers: JsonField> = JsonMissing.of(), - @JsonProperty("preferred_name") - @ExcludeMissing - preferredName: JsonField = JsonMissing.of(), - @JsonProperty("residence") - @ExcludeMissing - residence: JsonField = JsonMissing.of(), - @JsonProperty("ssn") @ExcludeMissing ssn: JsonField = JsonMissing.of(), - ) : this( - id, - dob, - emails, - encryptedSsn, - ethnicity, - firstName, - gender, - lastName, - middleName, - phoneNumbers, - preferredName, - residence, - ssn, - mutableMapOf(), - ) - - /** - * A stable Finch `id` (UUID v4) for an individual in the company. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun id(): Optional = id.getOptional("id") - - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun dob(): Optional = dob.getOptional("dob") - - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun emails(): Optional> = emails.getOptional("emails") + fun unionMember0(): Optional = Optional.ofNullable(unionMember0) - /** - * Social Security Number of the individual in **encrypted** format. This field is only - * available with the `ssn` scope enabled and the `options: { include: ['ssn'] }` param set in - * the body. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun encryptedSsn(): Optional = encryptedSsn.getOptional("encrypted_ssn") - - /** - * The EEOC-defined ethnicity of the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun ethnicity(): Optional = ethnicity.getOptional("ethnicity") - - /** - * The legal first name of the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun firstName(): Optional = firstName.getOptional("first_name") + fun batchError(): Optional = Optional.ofNullable(batchError) - /** - * The gender of the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun gender(): Optional = gender.getOptional("gender") + fun isUnionMember0(): Boolean = unionMember0 != null - /** - * The legal last name of the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun lastName(): Optional = lastName.getOptional("last_name") + fun isBatchError(): Boolean = batchError != null - /** - * The legal middle name of the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun middleName(): Optional = middleName.getOptional("middle_name") + fun asUnionMember0(): UnionMember0 = unionMember0.getOrThrow("unionMember0") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun phoneNumbers(): Optional> = phoneNumbers.getOptional("phone_numbers") + fun asBatchError(): BatchError = batchError.getOrThrow("batchError") - /** - * The preferred name of the individual. - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun preferredName(): Optional = preferredName.getOptional("preferred_name") + fun _json(): Optional = Optional.ofNullable(_json) - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun residence(): Optional = residence.getOptional("residence") + fun accept(visitor: Visitor): T = + when { + unionMember0 != null -> visitor.visitUnionMember0(unionMember0) + batchError != null -> visitor.visitBatchError(batchError) + else -> visitor.unknown(_json) + } - /** - * Social Security Number of the individual. This field is only available with the `ssn` scope - * enabled and the `options: { include: ['ssn'] }` param set in the body. - * [Click here to learn more about enabling the SSN field](/developer-resources/Enable-SSN-Field). - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun ssn(): Optional = ssn.getOptional("ssn") + private var validated: Boolean = false - /** - * Returns the raw JSON value of [id]. - * - * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + fun validate(): Individual = apply { + if (validated) { + return@apply + } - /** - * Returns the raw JSON value of [dob]. - * - * Unlike [dob], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("dob") @ExcludeMissing fun _dob(): JsonField = dob + accept( + object : Visitor { + override fun visitUnionMember0(unionMember0: UnionMember0) { + unionMember0.validate() + } - /** - * Returns the raw JSON value of [emails]. - * - * Unlike [emails], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("emails") @ExcludeMissing fun _emails(): JsonField> = emails + override fun visitBatchError(batchError: BatchError) { + batchError.validate() + } + } + ) + validated = true + } - /** - * Returns the raw JSON value of [encryptedSsn]. - * - * Unlike [encryptedSsn], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("encrypted_ssn") - @ExcludeMissing - fun _encryptedSsn(): JsonField = encryptedSsn + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + false + } /** - * Returns the raw JSON value of [ethnicity]. + * Returns a score indicating how many valid values are contained in this object recursively. * - * Unlike [ethnicity], this method doesn't throw if the JSON field has an unexpected type. + * Used for best match union deserialization. */ - @JsonProperty("ethnicity") @ExcludeMissing fun _ethnicity(): JsonField = ethnicity + @JvmSynthetic + internal fun validity(): Int = + accept( + object : Visitor { + override fun visitUnionMember0(unionMember0: UnionMember0) = unionMember0.validity() - /** - * Returns the raw JSON value of [firstName]. - * - * Unlike [firstName], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("first_name") @ExcludeMissing fun _firstName(): JsonField = firstName + override fun visitBatchError(batchError: BatchError) = batchError.validity() - /** - * Returns the raw JSON value of [gender]. - * - * Unlike [gender], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("gender") @ExcludeMissing fun _gender(): JsonField = gender + override fun unknown(json: JsonValue?) = 0 + } + ) - /** - * Returns the raw JSON value of [lastName]. - * - * Unlike [lastName], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("last_name") @ExcludeMissing fun _lastName(): JsonField = lastName + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * Returns the raw JSON value of [middleName]. - * - * Unlike [middleName], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("middle_name") @ExcludeMissing fun _middleName(): JsonField = middleName + return /* spotless:off */ other is Individual && unionMember0 == other.unionMember0 && batchError == other.batchError /* spotless:on */ + } - /** - * Returns the raw JSON value of [phoneNumbers]. - * - * Unlike [phoneNumbers], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("phone_numbers") - @ExcludeMissing - fun _phoneNumbers(): JsonField> = phoneNumbers + override fun hashCode(): Int = /* spotless:off */ Objects.hash(unionMember0, batchError) /* spotless:on */ - /** - * Returns the raw JSON value of [preferredName]. - * - * Unlike [preferredName], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("preferred_name") - @ExcludeMissing - fun _preferredName(): JsonField = preferredName + override fun toString(): String = + when { + unionMember0 != null -> "Individual{unionMember0=$unionMember0}" + batchError != null -> "Individual{batchError=$batchError}" + _json != null -> "Individual{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Individual") + } - /** - * Returns the raw JSON value of [residence]. - * - * Unlike [residence], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("residence") @ExcludeMissing fun _residence(): JsonField = residence + companion object { - /** - * Returns the raw JSON value of [ssn]. - * - * Unlike [ssn], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("ssn") @ExcludeMissing fun _ssn(): JsonField = ssn + @JvmStatic + fun ofUnionMember0(unionMember0: UnionMember0) = Individual(unionMember0 = unionMember0) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) + @JvmStatic fun ofBatchError(batchError: BatchError) = Individual(batchError = batchError) } - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** An interface that defines how to map each variant of [Individual] to a value of type [T]. */ + interface Visitor { - fun toBuilder() = Builder().from(this) + fun visitUnionMember0(unionMember0: UnionMember0): T - companion object { + fun visitBatchError(batchError: BatchError): T - /** Returns a mutable builder for constructing an instance of [Individual]. */ - @JvmStatic fun builder() = Builder() + /** + * Maps an unknown variant of [Individual] to a value of type [T]. + * + * An instance of [Individual] can contain an unknown variant if it was deserialized from + * data that doesn't match any known variant. For example, if the SDK is on an older version + * than the API, then the API may respond with new variants that the SDK is unaware of. + * + * @throws FinchInvalidDataException in the default implementation. + */ + fun unknown(json: JsonValue?): T { + throw FinchInvalidDataException("Unknown Individual: $json") + } } - /** A builder for [Individual]. */ - class Builder internal constructor() { - - private var id: JsonField = JsonMissing.of() - private var dob: JsonField = JsonMissing.of() - private var emails: JsonField>? = null - private var encryptedSsn: JsonField = JsonMissing.of() - private var ethnicity: JsonField = JsonMissing.of() - private var firstName: JsonField = JsonMissing.of() - private var gender: JsonField = JsonMissing.of() - private var lastName: JsonField = JsonMissing.of() - private var middleName: JsonField = JsonMissing.of() - private var phoneNumbers: JsonField>? = null - private var preferredName: JsonField = JsonMissing.of() - private var residence: JsonField = JsonMissing.of() - private var ssn: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + internal class Deserializer : BaseDeserializer(Individual::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Individual { + val json = JsonValue.fromJsonNode(node) + + val bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef())?.let { + Individual(unionMember0 = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + Individual(batchError = it, _json = json) + }, + ) + .filterNotNull() + .allMaxBy { it.validity() } + .toList() + return when (bestMatches.size) { + // This can happen if what we're deserializing is completely incompatible with all + // the possible variants (e.g. deserializing from boolean). + 0 -> Individual(_json = json) + 1 -> bestMatches.single() + // If there's more than one match with the highest validity, then use the first + // completely valid match, or simply the first match if none are completely valid. + else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first() + } + } + } - @JvmSynthetic - internal fun from(individual: Individual) = apply { - id = individual.id - dob = individual.dob - emails = individual.emails.map { it.toMutableList() } - encryptedSsn = individual.encryptedSsn - ethnicity = individual.ethnicity - firstName = individual.firstName - gender = individual.gender - lastName = individual.lastName - middleName = individual.middleName - phoneNumbers = individual.phoneNumbers.map { it.toMutableList() } - preferredName = individual.preferredName - residence = individual.residence - ssn = individual.ssn - additionalProperties = individual.additionalProperties.toMutableMap() + internal class Serializer : BaseSerializer(Individual::class) { + + override fun serialize( + value: Individual, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.unionMember0 != null -> generator.writeObject(value.unionMember0) + value.batchError != null -> generator.writeObject(value.batchError) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Individual") + } } + } + + class UnionMember0 + private constructor( + private val id: JsonField, + private val dob: JsonField, + private val ethnicity: JsonField, + private val firstName: JsonField, + private val gender: JsonField, + private val lastName: JsonField, + private val middleName: JsonField, + private val phoneNumbers: JsonField>, + private val preferredName: JsonField, + private val residence: JsonField, + private val emails: JsonField>, + private val encryptedSsn: JsonField, + private val ssn: JsonField, + private val additionalProperties: MutableMap, + ) { - /** A stable Finch `id` (UUID v4) for an individual in the company. */ - fun id(id: String) = id(JsonField.of(id)) + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("dob") @ExcludeMissing dob: JsonField = JsonMissing.of(), + @JsonProperty("ethnicity") + @ExcludeMissing + ethnicity: JsonField = JsonMissing.of(), + @JsonProperty("first_name") + @ExcludeMissing + firstName: JsonField = JsonMissing.of(), + @JsonProperty("gender") @ExcludeMissing gender: JsonField = JsonMissing.of(), + @JsonProperty("last_name") + @ExcludeMissing + lastName: JsonField = JsonMissing.of(), + @JsonProperty("middle_name") + @ExcludeMissing + middleName: JsonField = JsonMissing.of(), + @JsonProperty("phone_numbers") + @ExcludeMissing + phoneNumbers: JsonField> = JsonMissing.of(), + @JsonProperty("preferred_name") + @ExcludeMissing + preferredName: JsonField = JsonMissing.of(), + @JsonProperty("residence") + @ExcludeMissing + residence: JsonField = JsonMissing.of(), + @JsonProperty("emails") + @ExcludeMissing + emails: JsonField> = JsonMissing.of(), + @JsonProperty("encrypted_ssn") + @ExcludeMissing + encryptedSsn: JsonField = JsonMissing.of(), + @JsonProperty("ssn") @ExcludeMissing ssn: JsonField = JsonMissing.of(), + ) : this( + id, + dob, + ethnicity, + firstName, + gender, + lastName, + middleName, + phoneNumbers, + preferredName, + residence, + emails, + encryptedSsn, + ssn, + mutableMapOf(), + ) /** - * Sets [Builder.id] to an arbitrary JSON value. + * A stable Finch `id` (UUID v4) for an individual in the company. * - * You should usually call [Builder.id] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws FinchInvalidDataException 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 id(id: JsonField) = apply { this.id = id } - - fun dob(dob: String?) = dob(JsonField.ofNullable(dob)) + fun id(): String = id.getRequired("id") - /** Alias for calling [Builder.dob] with `dob.orElse(null)`. */ - fun dob(dob: Optional) = dob(dob.getOrNull()) + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dob(): Optional = dob.getOptional("dob") /** - * Sets [Builder.dob] to an arbitrary JSON value. + * The EEOC-defined ethnicity of the individual. * - * You should usually call [Builder.dob] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun dob(dob: JsonField) = apply { this.dob = dob } - - fun emails(emails: List?) = emails(JsonField.ofNullable(emails)) - - /** Alias for calling [Builder.emails] with `emails.orElse(null)`. */ - fun emails(emails: Optional>) = emails(emails.getOrNull()) + fun ethnicity(): Optional = ethnicity.getOptional("ethnicity") /** - * Sets [Builder.emails] to an arbitrary JSON value. + * The legal first name of the individual. * - * You should usually call [Builder.emails] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun emails(emails: JsonField>) = apply { - this.emails = emails.map { it.toMutableList() } - } + fun firstName(): Optional = firstName.getOptional("first_name") /** - * Adds a single [Email] to [emails]. + * The gender of the individual. * - * @throws IllegalStateException if the field was previously set to a non-list. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun addEmail(email: Email) = apply { - emails = - (emails ?: JsonField.of(mutableListOf())).also { - checkKnown("emails", it).add(email) - } - } + fun gender(): Optional = gender.getOptional("gender") /** - * Social Security Number of the individual in **encrypted** format. This field is only - * available with the `ssn` scope enabled and the `options: { include: ['ssn'] }` param set - * in the body. + * The legal last name of the individual. + * + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun encryptedSsn(encryptedSsn: String?) = encryptedSsn(JsonField.ofNullable(encryptedSsn)) - - /** Alias for calling [Builder.encryptedSsn] with `encryptedSsn.orElse(null)`. */ - fun encryptedSsn(encryptedSsn: Optional) = encryptedSsn(encryptedSsn.getOrNull()) + fun lastName(): Optional = lastName.getOptional("last_name") /** - * Sets [Builder.encryptedSsn] to an arbitrary JSON value. + * The legal middle name of the individual. * - * You should usually call [Builder.encryptedSsn] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun encryptedSsn(encryptedSsn: JsonField) = apply { - this.encryptedSsn = encryptedSsn - } + fun middleName(): Optional = middleName.getOptional("middle_name") - /** The EEOC-defined ethnicity of the individual. */ - fun ethnicity(ethnicity: Ethnicity?) = ethnicity(JsonField.ofNullable(ethnicity)) - - /** Alias for calling [Builder.ethnicity] with `ethnicity.orElse(null)`. */ - fun ethnicity(ethnicity: Optional) = ethnicity(ethnicity.getOrNull()) + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun phoneNumbers(): Optional> = phoneNumbers.getOptional("phone_numbers") /** - * Sets [Builder.ethnicity] to an arbitrary JSON value. + * The preferred name of the individual. * - * You should usually call [Builder.ethnicity] with a well-typed [Ethnicity] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun ethnicity(ethnicity: JsonField) = apply { this.ethnicity = ethnicity } + fun preferredName(): Optional = preferredName.getOptional("preferred_name") - /** The legal first name of the individual. */ - fun firstName(firstName: String?) = firstName(JsonField.ofNullable(firstName)) + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun residence(): Optional = residence.getOptional("residence") - /** Alias for calling [Builder.firstName] with `firstName.orElse(null)`. */ - fun firstName(firstName: Optional) = firstName(firstName.getOrNull()) + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun emails(): Optional> = emails.getOptional("emails") /** - * Sets [Builder.firstName] to an arbitrary JSON value. + * Social Security Number of the individual in **encrypted** format. This field is only + * available with the `ssn` scope enabled and the `options: { include: ['ssn'] }` param set + * in the body. * - * You should usually call [Builder.firstName] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun firstName(firstName: JsonField) = apply { this.firstName = firstName } - - /** The gender of the individual. */ - fun gender(gender: Gender?) = gender(JsonField.ofNullable(gender)) - - /** Alias for calling [Builder.gender] with `gender.orElse(null)`. */ - fun gender(gender: Optional) = gender(gender.getOrNull()) + fun encryptedSsn(): Optional = encryptedSsn.getOptional("encrypted_ssn") /** - * Sets [Builder.gender] to an arbitrary JSON value. + * Social Security Number of the individual. This field is only available with the `ssn` + * scope enabled and the `options: { include: ['ssn'] }` param set in the body. + * [Click here to learn more about enabling the SSN field](/developer-resources/Enable-SSN-Field). * - * You should usually call [Builder.gender] with a well-typed [Gender] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun gender(gender: JsonField) = apply { this.gender = gender } - - /** The legal last name of the individual. */ - fun lastName(lastName: String?) = lastName(JsonField.ofNullable(lastName)) - - /** Alias for calling [Builder.lastName] with `lastName.orElse(null)`. */ - fun lastName(lastName: Optional) = lastName(lastName.getOrNull()) + fun ssn(): Optional = ssn.getOptional("ssn") /** - * Sets [Builder.lastName] to an arbitrary JSON value. + * Returns the raw JSON value of [id]. * - * You should usually call [Builder.lastName] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. */ - fun lastName(lastName: JsonField) = apply { this.lastName = lastName } - - /** The legal middle name of the individual. */ - fun middleName(middleName: String?) = middleName(JsonField.ofNullable(middleName)) - - /** Alias for calling [Builder.middleName] with `middleName.orElse(null)`. */ - fun middleName(middleName: Optional) = middleName(middleName.getOrNull()) + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id /** - * Sets [Builder.middleName] to an arbitrary JSON value. + * Returns the raw JSON value of [dob]. * - * You should usually call [Builder.middleName] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [dob], this method doesn't throw if the JSON field has an unexpected type. */ - fun middleName(middleName: JsonField) = apply { this.middleName = middleName } - - fun phoneNumbers(phoneNumbers: List?) = - phoneNumbers(JsonField.ofNullable(phoneNumbers)) - - /** Alias for calling [Builder.phoneNumbers] with `phoneNumbers.orElse(null)`. */ - fun phoneNumbers(phoneNumbers: Optional>) = - phoneNumbers(phoneNumbers.getOrNull()) + @JsonProperty("dob") @ExcludeMissing fun _dob(): JsonField = dob /** - * Sets [Builder.phoneNumbers] to an arbitrary JSON value. + * Returns the raw JSON value of [ethnicity]. * - * You should usually call [Builder.phoneNumbers] with a well-typed `List` - * value instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. + * Unlike [ethnicity], this method doesn't throw if the JSON field has an unexpected type. */ - fun phoneNumbers(phoneNumbers: JsonField>) = apply { - this.phoneNumbers = phoneNumbers.map { it.toMutableList() } - } + @JsonProperty("ethnicity") + @ExcludeMissing + fun _ethnicity(): JsonField = ethnicity /** - * Adds a single [PhoneNumber] to [phoneNumbers]. + * Returns the raw JSON value of [firstName]. * - * @throws IllegalStateException if the field was previously set to a non-list. + * Unlike [firstName], this method doesn't throw if the JSON field has an unexpected type. */ - fun addPhoneNumber(phoneNumber: PhoneNumber) = apply { - phoneNumbers = - (phoneNumbers ?: JsonField.of(mutableListOf())).also { - checkKnown("phoneNumbers", it).add(phoneNumber) - } - } - - /** The preferred name of the individual. */ - fun preferredName(preferredName: String?) = - preferredName(JsonField.ofNullable(preferredName)) - - /** Alias for calling [Builder.preferredName] with `preferredName.orElse(null)`. */ - fun preferredName(preferredName: Optional) = - preferredName(preferredName.getOrNull()) + @JsonProperty("first_name") @ExcludeMissing fun _firstName(): JsonField = firstName /** - * Sets [Builder.preferredName] to an arbitrary JSON value. + * Returns the raw JSON value of [gender]. * - * You should usually call [Builder.preferredName] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [gender], this method doesn't throw if the JSON field has an unexpected type. */ - fun preferredName(preferredName: JsonField) = apply { - this.preferredName = preferredName - } - - fun residence(residence: Location?) = residence(JsonField.ofNullable(residence)) - - /** Alias for calling [Builder.residence] with `residence.orElse(null)`. */ - fun residence(residence: Optional) = residence(residence.getOrNull()) + @JsonProperty("gender") @ExcludeMissing fun _gender(): JsonField = gender /** - * Sets [Builder.residence] to an arbitrary JSON value. + * Returns the raw JSON value of [lastName]. * - * You should usually call [Builder.residence] with a well-typed [Location] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. + * Unlike [lastName], this method doesn't throw if the JSON field has an unexpected type. */ - fun residence(residence: JsonField) = apply { this.residence = residence } + @JsonProperty("last_name") @ExcludeMissing fun _lastName(): JsonField = lastName /** - * Social Security Number of the individual. This field is only available with the `ssn` - * scope enabled and the `options: { include: ['ssn'] }` param set in the body. - * [Click here to learn more about enabling the SSN field](/developer-resources/Enable-SSN-Field). + * Returns the raw JSON value of [middleName]. + * + * Unlike [middleName], this method doesn't throw if the JSON field has an unexpected type. */ - fun ssn(ssn: String?) = ssn(JsonField.ofNullable(ssn)) - - /** Alias for calling [Builder.ssn] with `ssn.orElse(null)`. */ - fun ssn(ssn: Optional) = ssn(ssn.getOrNull()) + @JsonProperty("middle_name") + @ExcludeMissing + fun _middleName(): JsonField = middleName /** - * Sets [Builder.ssn] to an arbitrary JSON value. + * Returns the raw JSON value of [phoneNumbers]. * - * You should usually call [Builder.ssn] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * Unlike [phoneNumbers], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun ssn(ssn: JsonField) = apply { this.ssn = ssn } - - 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) - } + @JsonProperty("phone_numbers") + @ExcludeMissing + fun _phoneNumbers(): JsonField> = phoneNumbers /** - * Returns an immutable instance of [Individual]. + * Returns the raw JSON value of [preferredName]. * - * Further updates to this [Builder] will not mutate the returned instance. + * Unlike [preferredName], this method doesn't throw if the JSON field has an unexpected + * type. */ - fun build(): Individual = - Individual( - id, - dob, - (emails ?: JsonMissing.of()).map { it.toImmutable() }, - encryptedSsn, - ethnicity, - firstName, - gender, - lastName, - middleName, - (phoneNumbers ?: JsonMissing.of()).map { it.toImmutable() }, - preferredName, - residence, - ssn, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Individual = apply { - if (validated) { - return@apply - } - - id() - dob() - emails().ifPresent { it.forEach { it.validate() } } - encryptedSsn() - ethnicity().ifPresent { it.validate() } - firstName() - gender().ifPresent { it.validate() } - lastName() - middleName() - phoneNumbers().ifPresent { it.forEach { it?.validate() } } - preferredName() - residence().ifPresent { it.validate() } - ssn() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - 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 (id.asKnown().isPresent) 1 else 0) + - (if (dob.asKnown().isPresent) 1 else 0) + - (emails.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + - (if (encryptedSsn.asKnown().isPresent) 1 else 0) + - (ethnicity.asKnown().getOrNull()?.validity() ?: 0) + - (if (firstName.asKnown().isPresent) 1 else 0) + - (gender.asKnown().getOrNull()?.validity() ?: 0) + - (if (lastName.asKnown().isPresent) 1 else 0) + - (if (middleName.asKnown().isPresent) 1 else 0) + - (phoneNumbers.asKnown().getOrNull()?.sumOf { (it?.validity() ?: 0).toInt() } ?: 0) + - (if (preferredName.asKnown().isPresent) 1 else 0) + - (residence.asKnown().getOrNull()?.validity() ?: 0) + - (if (ssn.asKnown().isPresent) 1 else 0) - - class Email - private constructor( - private val data: JsonField, - private val type: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(data, type, mutableMapOf()) + @JsonProperty("preferred_name") + @ExcludeMissing + fun _preferredName(): JsonField = preferredName /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * Returns the raw JSON value of [residence]. + * + * Unlike [residence], this method doesn't throw if the JSON field has an unexpected type. */ - fun data(): Optional = data.getOptional("data") + @JsonProperty("residence") @ExcludeMissing fun _residence(): JsonField = residence /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * Returns the raw JSON value of [emails]. + * + * Unlike [emails], this method doesn't throw if the JSON field has an unexpected type. */ - fun type(): Optional = type.getOptional("type") + @JsonProperty("emails") @ExcludeMissing fun _emails(): JsonField> = emails /** - * Returns the raw JSON value of [data]. + * Returns the raw JSON value of [encryptedSsn]. * - * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [encryptedSsn], this method doesn't throw if the JSON field has an unexpected + * type. */ - @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + @JsonProperty("encrypted_ssn") + @ExcludeMissing + fun _encryptedSsn(): JsonField = encryptedSsn /** - * Returns the raw JSON value of [type]. + * Returns the raw JSON value of [ssn]. * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [ssn], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("ssn") @ExcludeMissing fun _ssn(): JsonField = ssn @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -707,48 +485,295 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Email]. */ + /** + * Returns a mutable builder for constructing an instance of [UnionMember0]. + * + * The following fields are required: + * ```java + * .id() + * .dob() + * .ethnicity() + * .firstName() + * .gender() + * .lastName() + * .middleName() + * .phoneNumbers() + * .preferredName() + * .residence() + * ``` + */ @JvmStatic fun builder() = Builder() } - /** A builder for [Email]. */ + /** A builder for [UnionMember0]. */ class Builder internal constructor() { - private var data: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() + private var id: JsonField? = null + private var dob: JsonField? = null + private var ethnicity: JsonField? = null + private var firstName: JsonField? = null + private var gender: JsonField? = null + private var lastName: JsonField? = null + private var middleName: JsonField? = null + private var phoneNumbers: JsonField>? = null + private var preferredName: JsonField? = null + private var residence: JsonField? = null + private var emails: JsonField>? = null + private var encryptedSsn: JsonField = JsonMissing.of() + private var ssn: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() - @JvmSynthetic - internal fun from(email: Email) = apply { - data = email.data - type = email.type - additionalProperties = email.additionalProperties.toMutableMap() + @JvmSynthetic + internal fun from(unionMember0: UnionMember0) = apply { + id = unionMember0.id + dob = unionMember0.dob + ethnicity = unionMember0.ethnicity + firstName = unionMember0.firstName + gender = unionMember0.gender + lastName = unionMember0.lastName + middleName = unionMember0.middleName + phoneNumbers = unionMember0.phoneNumbers.map { it.toMutableList() } + preferredName = unionMember0.preferredName + residence = unionMember0.residence + emails = unionMember0.emails.map { it.toMutableList() } + encryptedSsn = unionMember0.encryptedSsn + ssn = unionMember0.ssn + additionalProperties = unionMember0.additionalProperties.toMutableMap() + } + + /** A stable Finch `id` (UUID v4) for an individual in the company. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + fun dob(dob: String?) = dob(JsonField.ofNullable(dob)) + + /** Alias for calling [Builder.dob] with `dob.orElse(null)`. */ + fun dob(dob: Optional) = dob(dob.getOrNull()) + + /** + * Sets [Builder.dob] to an arbitrary JSON value. + * + * You should usually call [Builder.dob] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun dob(dob: JsonField) = apply { this.dob = dob } + + /** The EEOC-defined ethnicity of the individual. */ + fun ethnicity(ethnicity: Ethnicity?) = ethnicity(JsonField.ofNullable(ethnicity)) + + /** Alias for calling [Builder.ethnicity] with `ethnicity.orElse(null)`. */ + fun ethnicity(ethnicity: Optional) = ethnicity(ethnicity.getOrNull()) + + /** + * Sets [Builder.ethnicity] to an arbitrary JSON value. + * + * You should usually call [Builder.ethnicity] with a well-typed [Ethnicity] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun ethnicity(ethnicity: JsonField) = apply { this.ethnicity = ethnicity } + + /** The legal first name of the individual. */ + fun firstName(firstName: String?) = firstName(JsonField.ofNullable(firstName)) + + /** Alias for calling [Builder.firstName] with `firstName.orElse(null)`. */ + fun firstName(firstName: Optional) = firstName(firstName.getOrNull()) + + /** + * Sets [Builder.firstName] to an arbitrary JSON value. + * + * You should usually call [Builder.firstName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun firstName(firstName: JsonField) = apply { this.firstName = firstName } + + /** The gender of the individual. */ + fun gender(gender: Gender?) = gender(JsonField.ofNullable(gender)) + + /** Alias for calling [Builder.gender] with `gender.orElse(null)`. */ + fun gender(gender: Optional) = gender(gender.getOrNull()) + + /** + * Sets [Builder.gender] to an arbitrary JSON value. + * + * You should usually call [Builder.gender] with a well-typed [Gender] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun gender(gender: JsonField) = apply { this.gender = gender } + + /** The legal last name of the individual. */ + fun lastName(lastName: String?) = lastName(JsonField.ofNullable(lastName)) + + /** Alias for calling [Builder.lastName] with `lastName.orElse(null)`. */ + fun lastName(lastName: Optional) = lastName(lastName.getOrNull()) + + /** + * Sets [Builder.lastName] to an arbitrary JSON value. + * + * You should usually call [Builder.lastName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastName(lastName: JsonField) = apply { this.lastName = lastName } + + /** The legal middle name of the individual. */ + fun middleName(middleName: String?) = middleName(JsonField.ofNullable(middleName)) + + /** Alias for calling [Builder.middleName] with `middleName.orElse(null)`. */ + fun middleName(middleName: Optional) = middleName(middleName.getOrNull()) + + /** + * Sets [Builder.middleName] to an arbitrary JSON value. + * + * You should usually call [Builder.middleName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun middleName(middleName: JsonField) = apply { this.middleName = middleName } + + fun phoneNumbers(phoneNumbers: List?) = + phoneNumbers(JsonField.ofNullable(phoneNumbers)) + + /** Alias for calling [Builder.phoneNumbers] with `phoneNumbers.orElse(null)`. */ + fun phoneNumbers(phoneNumbers: Optional>) = + phoneNumbers(phoneNumbers.getOrNull()) + + /** + * Sets [Builder.phoneNumbers] to an arbitrary JSON value. + * + * You should usually call [Builder.phoneNumbers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun phoneNumbers(phoneNumbers: JsonField>) = apply { + this.phoneNumbers = phoneNumbers.map { it.toMutableList() } + } + + /** + * Adds a single [PhoneNumber] to [phoneNumbers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addPhoneNumber(phoneNumber: PhoneNumber) = apply { + phoneNumbers = + (phoneNumbers ?: JsonField.of(mutableListOf())).also { + checkKnown("phoneNumbers", it).add(phoneNumber) + } + } + + /** The preferred name of the individual. */ + fun preferredName(preferredName: String?) = + preferredName(JsonField.ofNullable(preferredName)) + + /** Alias for calling [Builder.preferredName] with `preferredName.orElse(null)`. */ + fun preferredName(preferredName: Optional) = + preferredName(preferredName.getOrNull()) + + /** + * Sets [Builder.preferredName] to an arbitrary JSON value. + * + * You should usually call [Builder.preferredName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun preferredName(preferredName: JsonField) = apply { + this.preferredName = preferredName + } + + fun residence(residence: Location?) = residence(JsonField.ofNullable(residence)) + + /** Alias for calling [Builder.residence] with `residence.orElse(null)`. */ + fun residence(residence: Optional) = residence(residence.getOrNull()) + + /** + * Sets [Builder.residence] to an arbitrary JSON value. + * + * You should usually call [Builder.residence] with a well-typed [Location] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun residence(residence: JsonField) = apply { this.residence = residence } + + fun emails(emails: List?) = emails(JsonField.ofNullable(emails)) + + /** Alias for calling [Builder.emails] with `emails.orElse(null)`. */ + fun emails(emails: Optional>) = emails(emails.getOrNull()) + + /** + * Sets [Builder.emails] to an arbitrary JSON value. + * + * You should usually call [Builder.emails] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun emails(emails: JsonField>) = apply { + this.emails = emails.map { it.toMutableList() } + } + + /** + * Adds a single [Email] to [emails]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addEmail(email: Email) = apply { + emails = + (emails ?: JsonField.of(mutableListOf())).also { + checkKnown("emails", it).add(email) + } } - fun data(data: String) = data(JsonField.of(data)) + /** + * Social Security Number of the individual in **encrypted** format. This field is only + * available with the `ssn` scope enabled and the `options: { include: ['ssn'] }` param + * set in the body. + */ + fun encryptedSsn(encryptedSsn: String?) = + encryptedSsn(JsonField.ofNullable(encryptedSsn)) + + /** Alias for calling [Builder.encryptedSsn] with `encryptedSsn.orElse(null)`. */ + fun encryptedSsn(encryptedSsn: Optional) = + encryptedSsn(encryptedSsn.getOrNull()) /** - * Sets [Builder.data] to an arbitrary JSON value. + * Sets [Builder.encryptedSsn] to an arbitrary JSON value. * - * You should usually call [Builder.data] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported - * value. + * You should usually call [Builder.encryptedSsn] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. */ - fun data(data: JsonField) = apply { this.data = data } + fun encryptedSsn(encryptedSsn: JsonField) = apply { + this.encryptedSsn = encryptedSsn + } - fun type(type: Type?) = type(JsonField.ofNullable(type)) + /** + * Social Security Number of the individual. This field is only available with the `ssn` + * scope enabled and the `options: { include: ['ssn'] }` param set in the body. + * [Click here to learn more about enabling the SSN field](/developer-resources/Enable-SSN-Field). + */ + fun ssn(ssn: String?) = ssn(JsonField.ofNullable(ssn)) - /** Alias for calling [Builder.type] with `type.orElse(null)`. */ - fun type(type: Optional) = type(type.getOrNull()) + /** Alias for calling [Builder.ssn] with `ssn.orElse(null)`. */ + fun ssn(ssn: Optional) = ssn(ssn.getOrNull()) /** - * Sets [Builder.type] to an arbitrary JSON value. + * Sets [Builder.ssn] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * You should usually call [Builder.ssn] with a well-typed [String] value instead. This * method is primarily for setting the field to an undocumented or not yet supported * value. */ - fun type(type: JsonField) = apply { this.type = type } + fun ssn(ssn: JsonField) = apply { this.ssn = ssn } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -770,22 +795,65 @@ private constructor( } /** - * Returns an immutable instance of [Email]. + * Returns an immutable instance of [UnionMember0]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .dob() + * .ethnicity() + * .firstName() + * .gender() + * .lastName() + * .middleName() + * .phoneNumbers() + * .preferredName() + * .residence() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Email = Email(data, type, additionalProperties.toMutableMap()) + fun build(): UnionMember0 = + UnionMember0( + checkRequired("id", id), + checkRequired("dob", dob), + checkRequired("ethnicity", ethnicity), + checkRequired("firstName", firstName), + checkRequired("gender", gender), + checkRequired("lastName", lastName), + checkRequired("middleName", middleName), + checkRequired("phoneNumbers", phoneNumbers).map { it.toImmutable() }, + checkRequired("preferredName", preferredName), + checkRequired("residence", residence), + (emails ?: JsonMissing.of()).map { it.toImmutable() }, + encryptedSsn, + ssn, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): Email = apply { + fun validate(): UnionMember0 = apply { if (validated) { return@apply } - data() - type().ifPresent { it.validate() } + id() + dob() + ethnicity().ifPresent { it.validate() } + firstName() + gender().ifPresent { it.validate() } + lastName() + middleName() + phoneNumbers().ifPresent { it.forEach { it?.validate() } } + preferredName() + residence().ifPresent { it.validate() } + emails().ifPresent { it.forEach { it.validate() } } + encryptedSsn() + ssn() validated = true } @@ -805,9 +873,23 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (data.asKnown().isPresent) 1 else 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + (if (id.asKnown().isPresent) 1 else 0) + + (if (dob.asKnown().isPresent) 1 else 0) + + (ethnicity.asKnown().getOrNull()?.validity() ?: 0) + + (if (firstName.asKnown().isPresent) 1 else 0) + + (gender.asKnown().getOrNull()?.validity() ?: 0) + + (if (lastName.asKnown().isPresent) 1 else 0) + + (if (middleName.asKnown().isPresent) 1 else 0) + + (phoneNumbers.asKnown().getOrNull()?.sumOf { (it?.validity() ?: 0).toInt() } ?: 0) + + (if (preferredName.asKnown().isPresent) 1 else 0) + + (residence.asKnown().getOrNull()?.validity() ?: 0) + + (emails.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (encryptedSsn.asKnown().isPresent) 1 else 0) + + (if (ssn.asKnown().isPresent) 1 else 0) - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + /** The EEOC-defined ethnicity of the individual. */ + class Ethnicity @JsonCreator private constructor(private val value: JsonField) : + Enum { /** * Returns this class instance's raw value. @@ -821,32 +903,61 @@ private constructor( companion object { - @JvmField val WORK = of("work") + @JvmField val ASIAN = of("asian") - @JvmField val PERSONAL = of("personal") + @JvmField val WHITE = of("white") - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + @JvmField val BLACK_OR_AFRICAN_AMERICAN = of("black_or_african_american") + + @JvmField + val NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER = of("native_hawaiian_or_pacific_islander") + + @JvmField + val AMERICAN_INDIAN_OR_ALASKA_NATIVE = of("american_indian_or_alaska_native") + + @JvmField val HISPANIC_OR_LATINO = of("hispanic_or_latino") + + @JvmField val TWO_OR_MORE_RACES = of("two_or_more_races") + + @JvmField val DECLINE_TO_SPECIFY = of("decline_to_specify") + + @JvmStatic fun of(value: String) = Ethnicity(JsonField.of(value)) } - /** An enum containing [Type]'s known values. */ + /** An enum containing [Ethnicity]'s known values. */ enum class Known { - WORK, - PERSONAL, + ASIAN, + WHITE, + BLACK_OR_AFRICAN_AMERICAN, + NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER, + AMERICAN_INDIAN_OR_ALASKA_NATIVE, + HISPANIC_OR_LATINO, + TWO_OR_MORE_RACES, + DECLINE_TO_SPECIFY, } /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * An enum containing [Ethnicity]'s known values, as well as an [_UNKNOWN] member. * - * An instance of [Type] can contain an unknown value in a couple of cases: + * An instance of [Ethnicity] can contain an unknown value in a couple of cases: * - It was deserialized from data that doesn't match any known member. For example, if * the SDK is on an older version than the API, then the API may respond with new * members that the SDK is unaware of. * - It was constructed with an arbitrary value using the [of] method. */ enum class Value { - WORK, - PERSONAL, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ + ASIAN, + WHITE, + BLACK_OR_AFRICAN_AMERICAN, + NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER, + AMERICAN_INDIAN_OR_ALASKA_NATIVE, + HISPANIC_OR_LATINO, + TWO_OR_MORE_RACES, + DECLINE_TO_SPECIFY, + /** + * An enum member indicating that [Ethnicity] was instantiated with an unknown + * value. + */ _UNKNOWN, } @@ -859,8 +970,14 @@ private constructor( */ fun value(): Value = when (this) { - WORK -> Value.WORK - PERSONAL -> Value.PERSONAL + ASIAN -> Value.ASIAN + WHITE -> Value.WHITE + BLACK_OR_AFRICAN_AMERICAN -> Value.BLACK_OR_AFRICAN_AMERICAN + NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER -> Value.NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER + AMERICAN_INDIAN_OR_ALASKA_NATIVE -> Value.AMERICAN_INDIAN_OR_ALASKA_NATIVE + HISPANIC_OR_LATINO -> Value.HISPANIC_OR_LATINO + TWO_OR_MORE_RACES -> Value.TWO_OR_MORE_RACES + DECLINE_TO_SPECIFY -> Value.DECLINE_TO_SPECIFY else -> Value._UNKNOWN } @@ -875,9 +992,15 @@ private constructor( */ fun known(): Known = when (this) { - WORK -> Known.WORK - PERSONAL -> Known.PERSONAL - else -> throw FinchInvalidDataException("Unknown Type: $value") + ASIAN -> Known.ASIAN + WHITE -> Known.WHITE + BLACK_OR_AFRICAN_AMERICAN -> Known.BLACK_OR_AFRICAN_AMERICAN + NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER -> Known.NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER + AMERICAN_INDIAN_OR_ALASKA_NATIVE -> Known.AMERICAN_INDIAN_OR_ALASKA_NATIVE + HISPANIC_OR_LATINO -> Known.HISPANIC_OR_LATINO + TWO_OR_MORE_RACES -> Known.TWO_OR_MORE_RACES + DECLINE_TO_SPECIFY -> Known.DECLINE_TO_SPECIFY + else -> throw FinchInvalidDataException("Unknown Ethnicity: $value") } /** @@ -896,7 +1019,7 @@ private constructor( private var validated: Boolean = false - fun validate(): Type = apply { + fun validate(): Ethnicity = apply { if (validated) { return@apply } @@ -926,7 +1049,7 @@ private constructor( return true } - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + return /* spotless:off */ other is Ethnicity && value == other.value /* spotless:on */ } override fun hashCode() = value.hashCode() @@ -934,363 +1057,892 @@ private constructor( override fun toString() = value.toString() } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true + /** The gender of the individual. */ + class Gender @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val FEMALE = of("female") + + @JvmField val MALE = of("male") + + @JvmField val OTHER = of("other") + + @JvmField val DECLINE_TO_SPECIFY = of("decline_to_specify") + + @JvmStatic fun of(value: String) = Gender(JsonField.of(value)) + } + + /** An enum containing [Gender]'s known values. */ + enum class Known { + FEMALE, + MALE, + OTHER, + DECLINE_TO_SPECIFY, + } + + /** + * An enum containing [Gender]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Gender] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + FEMALE, + MALE, + OTHER, + DECLINE_TO_SPECIFY, + /** + * An enum member indicating that [Gender] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + FEMALE -> Value.FEMALE + MALE -> Value.MALE + OTHER -> Value.OTHER + DECLINE_TO_SPECIFY -> Value.DECLINE_TO_SPECIFY + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws FinchInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + FEMALE -> Known.FEMALE + MALE -> Known.MALE + OTHER -> Known.OTHER + DECLINE_TO_SPECIFY -> Known.DECLINE_TO_SPECIFY + else -> throw FinchInvalidDataException("Unknown Gender: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws FinchInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + FinchInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Gender = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Gender && value == other.value /* spotless:on */ } - return /* spotless:off */ other is Email && data == other.data && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, type, additionalProperties) } - /* spotless:on */ + class PhoneNumber + private constructor( + private val data: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { - override fun hashCode(): Int = hashCode + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(data, type, mutableMapOf()) - override fun toString() = - "Email{data=$data, type=$type, additionalProperties=$additionalProperties}" - } + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun data(): Optional = data.getOptional("data") - /** The EEOC-defined ethnicity of the individual. */ - class Ethnicity @JsonCreator private constructor(private val value: JsonField) : Enum { + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. For example, if the SDK is on an - * older version than the API, then the API may respond with new members that the SDK is - * unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data - companion object { + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - @JvmField val ASIAN = of("asian") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - @JvmField val WHITE = of("white") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - @JvmField val BLACK_OR_AFRICAN_AMERICAN = of("black_or_african_american") + fun toBuilder() = Builder().from(this) - @JvmField - val NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER = of("native_hawaiian_or_pacific_islander") + companion object { - @JvmField val AMERICAN_INDIAN_OR_ALASKA_NATIVE = of("american_indian_or_alaska_native") + /** + * Returns a mutable builder for constructing an instance of [PhoneNumber]. + * + * The following fields are required: + * ```java + * .data() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - @JvmField val HISPANIC_OR_LATINO = of("hispanic_or_latino") + /** A builder for [PhoneNumber]. */ + class Builder internal constructor() { - @JvmField val TWO_OR_MORE_RACES = of("two_or_more_races") + private var data: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() - @JvmField val DECLINE_TO_SPECIFY = of("decline_to_specify") + @JvmSynthetic + internal fun from(phoneNumber: PhoneNumber) = apply { + data = phoneNumber.data + type = phoneNumber.type + additionalProperties = phoneNumber.additionalProperties.toMutableMap() + } - @JvmStatic fun of(value: String) = Ethnicity(JsonField.of(value)) - } + fun data(data: String?) = data(JsonField.ofNullable(data)) + + /** Alias for calling [Builder.data] with `data.orElse(null)`. */ + fun data(data: Optional) = data(data.getOrNull()) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField) = apply { this.data = data } + + fun type(type: Type?) = type(JsonField.ofNullable(type)) + + /** Alias for calling [Builder.type] with `type.orElse(null)`. */ + fun type(type: Optional) = type(type.getOrNull()) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - /** An enum containing [Ethnicity]'s known values. */ - enum class Known { - ASIAN, - WHITE, - BLACK_OR_AFRICAN_AMERICAN, - NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER, - AMERICAN_INDIAN_OR_ALASKA_NATIVE, - HISPANIC_OR_LATINO, - TWO_OR_MORE_RACES, - DECLINE_TO_SPECIFY, - } + 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 [PhoneNumber]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PhoneNumber = + PhoneNumber( + checkRequired("data", data), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PhoneNumber = apply { + if (validated) { + return@apply + } + + data() + type().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + false + } - /** - * An enum containing [Ethnicity]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Ethnicity] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, if the - * SDK is on an older version than the API, then the API may respond with new members that - * the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - ASIAN, - WHITE, - BLACK_OR_AFRICAN_AMERICAN, - NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER, - AMERICAN_INDIAN_OR_ALASKA_NATIVE, - HISPANIC_OR_LATINO, - TWO_OR_MORE_RACES, - DECLINE_TO_SPECIFY, /** - * An enum member indicating that [Ethnicity] was instantiated with an unknown value. + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. */ - _UNKNOWN, + @JvmSynthetic + internal fun validity(): Int = + (if (data.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val WORK = of("work") + + @JvmField val PERSONAL = of("personal") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + WORK, + PERSONAL, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + WORK, + PERSONAL, + /** + * An enum member indicating that [Type] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + WORK -> Value.WORK + PERSONAL -> Value.PERSONAL + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws FinchInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + WORK -> Known.WORK + PERSONAL -> Known.PERSONAL + else -> throw FinchInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws FinchInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + FinchInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PhoneNumber && data == other.data && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PhoneNumber{data=$data, type=$type, additionalProperties=$additionalProperties}" } - /** - * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] - * if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you want - * to throw for the unknown case. - */ - fun value(): Value = - when (this) { - ASIAN -> Value.ASIAN - WHITE -> Value.WHITE - BLACK_OR_AFRICAN_AMERICAN -> Value.BLACK_OR_AFRICAN_AMERICAN - NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER -> Value.NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER - AMERICAN_INDIAN_OR_ALASKA_NATIVE -> Value.AMERICAN_INDIAN_OR_ALASKA_NATIVE - HISPANIC_OR_LATINO -> Value.HISPANIC_OR_LATINO - TWO_OR_MORE_RACES -> Value.TWO_OR_MORE_RACES - DECLINE_TO_SPECIFY -> Value.DECLINE_TO_SPECIFY - else -> Value._UNKNOWN + class Email + private constructor( + private val data: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(data, type, mutableMapOf()) + + /** + * @throws FinchInvalidDataException 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 data(): String = data.getRequired("data") + + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) } - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and don't - * want to throw for the unknown case. - * - * @throws FinchInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - ASIAN -> Known.ASIAN - WHITE -> Known.WHITE - BLACK_OR_AFRICAN_AMERICAN -> Known.BLACK_OR_AFRICAN_AMERICAN - NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER -> Known.NATIVE_HAWAIIAN_OR_PACIFIC_ISLANDER - AMERICAN_INDIAN_OR_ALASKA_NATIVE -> Known.AMERICAN_INDIAN_OR_ALASKA_NATIVE - HISPANIC_OR_LATINO -> Known.HISPANIC_OR_LATINO - TWO_OR_MORE_RACES -> Known.TWO_OR_MORE_RACES - DECLINE_TO_SPECIFY -> Known.DECLINE_TO_SPECIFY - else -> throw FinchInvalidDataException("Unknown Ethnicity: $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 [Email]. + * + * The following fields are required: + * ```java + * .data() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() } - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for debugging - * and generally doesn't throw. - * - * @throws FinchInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { FinchInvalidDataException("Value is not a String") } + /** A builder for [Email]. */ + class Builder internal constructor() { + + private var data: JsonField? = null + private var type: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(email: Email) = apply { + data = email.data + type = email.type + additionalProperties = email.additionalProperties.toMutableMap() + } + + fun data(data: String) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField) = apply { this.data = data } + + fun type(type: Type?) = type(JsonField.ofNullable(type)) + + /** Alias for calling [Builder.type] with `type.orElse(null)`. */ + fun type(type: Optional) = type(type.getOrNull()) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - private var validated: Boolean = false + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - fun validate(): Ethnicity = apply { - if (validated) { - return@apply - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - known() - validated = true - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false + /** + * Returns an immutable instance of [Email]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Email = + Email( + checkRequired("data", data), + checkRequired("type", type), + additionalProperties.toMutableMap(), + ) } - /** - * 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 (value() == Value._UNKNOWN) 0 else 1 + private var validated: Boolean = false - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun validate(): Email = apply { + if (validated) { + return@apply + } - return /* spotless:off */ other is Ethnicity && value == other.value /* spotless:on */ - } + data() + type().ifPresent { it.validate() } + validated = true + } - override fun hashCode() = value.hashCode() + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + false + } - override fun toString() = value.toString() - } + /** + * 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 (data.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) - /** The gender of the individual. */ - class Gender @JsonCreator private constructor(private val value: JsonField) : Enum { + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. For example, if the SDK is on an - * older version than the API, then the API may respond with new members that the SDK is - * unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that + * doesn't match any known member, and you want to know that value. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - companion object { + companion object { - @JvmField val FEMALE = of("female") + @JvmField val WORK = of("work") - @JvmField val MALE = of("male") + @JvmField val PERSONAL = of("personal") - @JvmField val OTHER = of("other") + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } - @JvmField val DECLINE_TO_SPECIFY = of("decline_to_specify") + /** An enum containing [Type]'s known values. */ + enum class Known { + WORK, + PERSONAL, + } - @JvmStatic fun of(value: String) = Gender(JsonField.of(value)) - } + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, + * if the SDK is on an older version than the API, then the API may respond with + * new members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + WORK, + PERSONAL, + /** + * An enum member indicating that [Type] was instantiated with an unknown value. + */ + _UNKNOWN, + } - /** An enum containing [Gender]'s known values. */ - enum class Known { - FEMALE, - MALE, - OTHER, - DECLINE_TO_SPECIFY, - } + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if + * you want to throw for the unknown case. + */ + fun value(): Value = + when (this) { + WORK -> Value.WORK + PERSONAL -> Value.PERSONAL + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws FinchInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + WORK -> Known.WORK + PERSONAL -> Known.PERSONAL + else -> throw FinchInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for + * debugging and generally doesn't throw. + * + * @throws FinchInvalidDataException if this class instance's value does not have + * the expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + FinchInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Type = apply { + if (validated) { + return@apply + } + + known() + validated = true + } - /** - * An enum containing [Gender]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Gender] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, if the - * SDK is on an older version than the API, then the API may respond with new members that - * the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - FEMALE, - MALE, - OTHER, - DECLINE_TO_SPECIFY, - /** An enum member indicating that [Gender] was instantiated with an unknown value. */ - _UNKNOWN, - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + 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 (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } - /** - * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] - * if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you want - * to throw for the unknown case. - */ - fun value(): Value = - when (this) { - FEMALE -> Value.FEMALE - MALE -> Value.MALE - OTHER -> Value.OTHER - DECLINE_TO_SPECIFY -> Value.DECLINE_TO_SPECIFY - else -> Value._UNKNOWN - } + override fun hashCode() = value.hashCode() - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and don't - * want to throw for the unknown case. - * - * @throws FinchInvalidDataException if this class instance's value is a not a known member. - */ - fun known(): Known = - when (this) { - FEMALE -> Known.FEMALE - MALE -> Known.MALE - OTHER -> Known.OTHER - DECLINE_TO_SPECIFY -> Known.DECLINE_TO_SPECIFY - else -> throw FinchInvalidDataException("Unknown Gender: $value") + override fun toString() = value.toString() } - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for debugging - * and generally doesn't throw. - * - * @throws FinchInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { FinchInvalidDataException("Value is not a String") } - - private var validated: Boolean = false + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - fun validate(): Gender = apply { - if (validated) { - return@apply + return /* spotless:off */ other is Email && data == other.data && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } - known() - validated = true - } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, type, additionalProperties) } + /* spotless:on */ - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false - } + override fun hashCode(): Int = hashCode - /** - * 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 (value() == Value._UNKNOWN) 0 else 1 + override fun toString() = + "Email{data=$data, type=$type, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Gender && value == other.value /* spotless:on */ + return /* spotless:off */ other is UnionMember0 && id == other.id && dob == other.dob && ethnicity == other.ethnicity && firstName == other.firstName && gender == other.gender && lastName == other.lastName && middleName == other.middleName && phoneNumbers == other.phoneNumbers && preferredName == other.preferredName && residence == other.residence && emails == other.emails && encryptedSsn == other.encryptedSsn && ssn == other.ssn && additionalProperties == other.additionalProperties /* spotless:on */ } - override fun hashCode() = value.hashCode() + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, dob, ethnicity, firstName, gender, lastName, middleName, phoneNumbers, preferredName, residence, emails, encryptedSsn, ssn, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode - override fun toString() = value.toString() + override fun toString() = + "UnionMember0{id=$id, dob=$dob, ethnicity=$ethnicity, firstName=$firstName, gender=$gender, lastName=$lastName, middleName=$middleName, phoneNumbers=$phoneNumbers, preferredName=$preferredName, residence=$residence, emails=$emails, encryptedSsn=$encryptedSsn, ssn=$ssn, additionalProperties=$additionalProperties}" } - class PhoneNumber + class BatchError private constructor( - private val data: JsonField, - private val type: JsonField, + private val code: JsonField, + private val message: JsonField, + private val name: JsonField, + private val finchCode: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(data, type, mutableMapOf()) + @JsonProperty("code") @ExcludeMissing code: JsonField = JsonMissing.of(), + @JsonProperty("message") @ExcludeMissing message: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("finch_code") + @ExcludeMissing + finchCode: JsonField = JsonMissing.of(), + ) : this(code, message, name, finchCode, mutableMapOf()) /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws FinchInvalidDataException 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 code(): Double = code.getRequired("code") + + /** + * @throws FinchInvalidDataException 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 data(): Optional = data.getOptional("data") + fun message(): String = message.getRequired("message") + + /** + * @throws FinchInvalidDataException 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 name(): String = name.getRequired("name") /** * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun type(): Optional = type.getOptional("type") + fun finchCode(): Optional = finchCode.getOptional("finch_code") + + /** + * Returns the raw JSON value of [code]. + * + * Unlike [code], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code + + /** + * Returns the raw JSON value of [message]. + * + * Unlike [message], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("message") @ExcludeMissing fun _message(): JsonField = message /** - * Returns the raw JSON value of [data]. + * Returns the raw JSON value of [name]. * - * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name /** - * Returns the raw JSON value of [type]. + * Returns the raw JSON value of [finchCode]. * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [finchCode], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + @JsonProperty("finch_code") @ExcludeMissing fun _finchCode(): JsonField = finchCode @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -1306,51 +1958,80 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [PhoneNumber]. */ + /** + * Returns a mutable builder for constructing an instance of [BatchError]. + * + * The following fields are required: + * ```java + * .code() + * .message() + * .name() + * ``` + */ @JvmStatic fun builder() = Builder() } - /** A builder for [PhoneNumber]. */ + /** A builder for [BatchError]. */ class Builder internal constructor() { - private var data: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var message: JsonField? = null + private var name: JsonField? = null + private var finchCode: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic - internal fun from(phoneNumber: PhoneNumber) = apply { - data = phoneNumber.data - type = phoneNumber.type - additionalProperties = phoneNumber.additionalProperties.toMutableMap() + internal fun from(batchError: BatchError) = apply { + code = batchError.code + message = batchError.message + name = batchError.name + finchCode = batchError.finchCode + additionalProperties = batchError.additionalProperties.toMutableMap() } - fun data(data: String?) = data(JsonField.ofNullable(data)) - - /** Alias for calling [Builder.data] with `data.orElse(null)`. */ - fun data(data: Optional) = data(data.getOrNull()) + fun code(code: Double) = code(JsonField.of(code)) /** - * Sets [Builder.data] to an arbitrary JSON value. + * Sets [Builder.code] to an arbitrary JSON value. * - * You should usually call [Builder.data] with a well-typed [String] value instead. This + * You should usually call [Builder.code] with a well-typed [Double] value instead. This * method is primarily for setting the field to an undocumented or not yet supported * value. */ - fun data(data: JsonField) = apply { this.data = data } + fun code(code: JsonField) = apply { this.code = code } + + fun message(message: String) = message(JsonField.of(message)) - fun type(type: Type?) = type(JsonField.ofNullable(type)) + /** + * Sets [Builder.message] to an arbitrary JSON value. + * + * You should usually call [Builder.message] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun message(message: JsonField) = apply { this.message = message } - /** Alias for calling [Builder.type] with `type.orElse(null)`. */ - fun type(type: Optional) = type(type.getOrNull()) + fun name(name: String) = name(JsonField.of(name)) /** - * Sets [Builder.type] to an arbitrary JSON value. + * Sets [Builder.name] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * You should usually call [Builder.name] with a well-typed [String] value instead. This * method is primarily for setting the field to an undocumented or not yet supported * value. */ - fun type(type: JsonField) = apply { this.type = type } + fun name(name: JsonField) = apply { this.name = name } + + fun finchCode(finchCode: String) = finchCode(JsonField.of(finchCode)) + + /** + * Sets [Builder.finchCode] to an arbitrary JSON value. + * + * You should usually call [Builder.finchCode] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun finchCode(finchCode: JsonField) = apply { this.finchCode = finchCode } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -1372,22 +2053,40 @@ private constructor( } /** - * Returns an immutable instance of [PhoneNumber]. + * Returns an immutable instance of [BatchError]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .code() + * .message() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): PhoneNumber = PhoneNumber(data, type, additionalProperties.toMutableMap()) + fun build(): BatchError = + BatchError( + checkRequired("code", code), + checkRequired("message", message), + checkRequired("name", name), + finchCode, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false - fun validate(): PhoneNumber = apply { + fun validate(): BatchError = apply { if (validated) { return@apply } - data() - type().ifPresent { it.validate() } + code() + message() + name() + finchCode() validated = true } @@ -1407,167 +2106,26 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (data.asKnown().isPresent) 1 else 0) + (type.asKnown().getOrNull()?.validity() ?: 0) - - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. For example, if the SDK is - * on an older version than the API, then the API may respond with new members that the - * SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val WORK = of("work") - - @JvmField val PERSONAL = of("personal") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - WORK, - PERSONAL, - } - - /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Type] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - WORK, - PERSONAL, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you - * want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - WORK -> Value.WORK - PERSONAL -> Value.PERSONAL - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws FinchInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - WORK -> Known.WORK - PERSONAL -> Known.PERSONAL - else -> throw FinchInvalidDataException("Unknown Type: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws FinchInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - FinchInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - 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 (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } + (if (code.asKnown().isPresent) 1 else 0) + + (if (message.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (finchCode.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PhoneNumber && data == other.data && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is BatchError && code == other.code && message == other.message && name == other.name && finchCode == other.finchCode && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(data, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(code, message, name, finchCode, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "PhoneNumber{data=$data, type=$type, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Individual && id == other.id && dob == other.dob && emails == other.emails && encryptedSsn == other.encryptedSsn && ethnicity == other.ethnicity && firstName == other.firstName && gender == other.gender && lastName == other.lastName && middleName == other.middleName && phoneNumbers == other.phoneNumbers && preferredName == other.preferredName && residence == other.residence && ssn == other.ssn && additionalProperties == other.additionalProperties /* spotless:on */ + "BatchError{code=$code, message=$message, name=$name, finchCode=$finchCode, additionalProperties=$additionalProperties}" } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, dob, emails, encryptedSsn, ethnicity, firstName, gender, lastName, middleName, phoneNumbers, preferredName, residence, ssn, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Individual{id=$id, dob=$dob, emails=$emails, encryptedSsn=$encryptedSsn, ethnicity=$ethnicity, firstName=$firstName, gender=$gender, lastName=$lastName, middleName=$middleName, phoneNumbers=$phoneNumbers, preferredName=$preferredName, residence=$residence, ssn=$ssn, additionalProperties=$additionalProperties}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/IndividualInDirectory.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/IndividualInDirectory.kt index fad446f4..7a2f70b6 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/IndividualInDirectory.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/IndividualInDirectory.kt @@ -10,6 +10,7 @@ import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects @@ -46,10 +47,10 @@ private constructor( /** * A stable Finch `id` (UUID v4) for an individual in the company. * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws FinchInvalidDataException 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 id(): Optional = id.getOptional("id") + fun id(): String = id.getRequired("id") /** * The department object. @@ -164,20 +165,33 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [IndividualInDirectory]. */ + /** + * Returns a mutable builder for constructing an instance of [IndividualInDirectory]. + * + * The following fields are required: + * ```java + * .id() + * .department() + * .firstName() + * .isActive() + * .lastName() + * .manager() + * .middleName() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [IndividualInDirectory]. */ class Builder internal constructor() { - private var id: JsonField = JsonMissing.of() - private var department: JsonField = JsonMissing.of() - private var firstName: JsonField = JsonMissing.of() - private var isActive: JsonField = JsonMissing.of() - private var lastName: JsonField = JsonMissing.of() - private var manager: JsonField = JsonMissing.of() - private var middleName: JsonField = JsonMissing.of() + private var id: JsonField? = null + private var department: JsonField? = null + private var firstName: JsonField? = null + private var isActive: JsonField? = null + private var lastName: JsonField? = null + private var manager: JsonField? = null + private var middleName: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -321,16 +335,29 @@ private constructor( * Returns an immutable instance of [IndividualInDirectory]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .department() + * .firstName() + * .isActive() + * .lastName() + * .manager() + * .middleName() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): IndividualInDirectory = IndividualInDirectory( - id, - department, - firstName, - isActive, - lastName, - manager, - middleName, + checkRequired("id", id), + checkRequired("department", department), + checkRequired("firstName", firstName), + checkRequired("isActive", isActive), + checkRequired("lastName", lastName), + checkRequired("manager", manager), + checkRequired("middleName", middleName), additionalProperties.toMutableMap(), ) } @@ -534,10 +561,10 @@ private constructor( /** * A stable Finch `id` (UUID v4) for an individual in the company. * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws FinchInvalidDataException 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 id(): Optional = id.getOptional("id") + fun id(): String = id.getRequired("id") /** * Returns the raw JSON value of [id]. @@ -560,14 +587,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Manager]. */ + /** + * Returns a mutable builder for constructing an instance of [Manager]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Manager]. */ class Builder internal constructor() { - private var id: JsonField = JsonMissing.of() + private var id: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -611,8 +645,16 @@ private constructor( * Returns an immutable instance of [Manager]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Manager = Manager(id, additionalProperties.toMutableMap()) + fun build(): Manager = + Manager(checkRequired("id", id), additionalProperties.toMutableMap()) } private var validated: Boolean = false diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/IndividualResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/IndividualResponse.kt index a01069c2..e2930cf2 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/IndividualResponse.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/IndividualResponse.kt @@ -10,10 +10,10 @@ import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects -import java.util.Optional import kotlin.jvm.optionals.getOrNull class IndividualResponse @@ -34,22 +34,22 @@ private constructor( ) : this(body, code, individualId, mutableMapOf()) /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws FinchInvalidDataException 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 body(): Optional = body.getOptional("body") + fun body(): Individual = body.getRequired("body") /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws FinchInvalidDataException 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 code(): Optional = code.getOptional("code") + fun code(): Long = code.getRequired("code") /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws FinchInvalidDataException 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 individualId(): Optional = individualId.getOptional("individual_id") + fun individualId(): String = individualId.getRequired("individual_id") /** * Returns the raw JSON value of [body]. @@ -88,16 +88,25 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [IndividualResponse]. */ + /** + * Returns a mutable builder for constructing an instance of [IndividualResponse]. + * + * The following fields are required: + * ```java + * .body() + * .code() + * .individualId() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [IndividualResponse]. */ class Builder internal constructor() { - private var body: JsonField = JsonMissing.of() - private var code: JsonField = JsonMissing.of() - private var individualId: JsonField = JsonMissing.of() + private var body: JsonField? = null + private var code: JsonField? = null + private var individualId: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -118,6 +127,13 @@ private constructor( */ fun body(body: JsonField) = apply { this.body = body } + /** Alias for calling [body] with `Individual.ofUnionMember0(unionMember0)`. */ + fun body(unionMember0: Individual.UnionMember0) = + body(Individual.ofUnionMember0(unionMember0)) + + /** Alias for calling [body] with `Individual.ofBatchError(batchError)`. */ + fun body(batchError: Individual.BatchError) = body(Individual.ofBatchError(batchError)) + fun code(code: Long) = code(JsonField.of(code)) /** @@ -164,9 +180,23 @@ private constructor( * Returns an immutable instance of [IndividualResponse]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .body() + * .code() + * .individualId() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): IndividualResponse = - IndividualResponse(body, code, individualId, additionalProperties.toMutableMap()) + IndividualResponse( + checkRequired("body", body), + checkRequired("code", code), + checkRequired("individualId", individualId), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -176,7 +206,7 @@ private constructor( return@apply } - body().ifPresent { it.validate() } + body().validate() code() individualId() validated = true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedCreateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedCreateParams.kt index ac13130c..939ba0bc 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedCreateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedCreateParams.kt @@ -15,7 +15,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.tryfinch.api.core.BaseDeserializer import com.tryfinch.api.core.BaseSerializer -import com.tryfinch.api.core.Enum import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing @@ -88,8 +87,8 @@ private constructor( /** Alias for calling [Builder.body] with `body.orElse(null)`. */ fun body(body: Optional) = body(body.getOrNull()) - /** Alias for calling [body] with `Body.ofDataSyncAll(dataSyncAll)`. */ - fun body(dataSyncAll: Body.DataSyncAll) = body(Body.ofDataSyncAll(dataSyncAll)) + /** Alias for calling [body] with `Body.ofDataSyncAll()`. */ + fun bodyDataSyncAll() = body(Body.ofDataSyncAll()) /** Alias for calling [body] with `Body.ofW4FormEmployeeSync(w4FormEmployeeSync)`. */ fun body(w4FormEmployeeSync: Body.W4FormEmployeeSync) = @@ -99,20 +98,12 @@ private constructor( * Alias for calling [body] with the following: * ```java * Body.W4FormEmployeeSync.builder() - * .type(JobAutomatedCreateParams.Body.W4FormEmployeeSync.Type.W4_FORM_EMPLOYEE_SYNC) * .params(params) * .build() * ``` */ fun w4FormEmployeeSyncBody(params: Body.W4FormEmployeeSync.Params) = - body( - Body.W4FormEmployeeSync.builder() - .type( - JobAutomatedCreateParams.Body.W4FormEmployeeSync.Type.W4_FORM_EMPLOYEE_SYNC - ) - .params(params) - .build() - ) + body(Body.W4FormEmployeeSync.builder().params(params).build()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -231,12 +222,12 @@ private constructor( @JsonSerialize(using = Body.Serializer::class) class Body private constructor( - private val dataSyncAll: DataSyncAll? = null, + private val dataSyncAll: JsonValue? = null, private val w4FormEmployeeSync: W4FormEmployeeSync? = null, private val _json: JsonValue? = null, ) { - fun dataSyncAll(): Optional = Optional.ofNullable(dataSyncAll) + fun dataSyncAll(): Optional = Optional.ofNullable(dataSyncAll) fun w4FormEmployeeSync(): Optional = Optional.ofNullable(w4FormEmployeeSync) @@ -245,7 +236,7 @@ private constructor( fun isW4FormEmployeeSync(): Boolean = w4FormEmployeeSync != null - fun asDataSyncAll(): DataSyncAll = dataSyncAll.getOrThrow("dataSyncAll") + fun asDataSyncAll(): JsonValue = dataSyncAll.getOrThrow("dataSyncAll") fun asW4FormEmployeeSync(): W4FormEmployeeSync = w4FormEmployeeSync.getOrThrow("w4FormEmployeeSync") @@ -268,8 +259,14 @@ private constructor( accept( object : Visitor { - override fun visitDataSyncAll(dataSyncAll: DataSyncAll) { - dataSyncAll.validate() + override fun visitDataSyncAll(dataSyncAll: JsonValue) { + dataSyncAll.let { + if (it != JsonValue.from(mapOf("type" to "data_sync_all"))) { + throw FinchInvalidDataException( + "'dataSyncAll' is invalid, received $it" + ) + } + } } override fun visitW4FormEmployeeSync(w4FormEmployeeSync: W4FormEmployeeSync) { @@ -298,7 +295,10 @@ private constructor( internal fun validity(): Int = accept( object : Visitor { - override fun visitDataSyncAll(dataSyncAll: DataSyncAll) = dataSyncAll.validity() + override fun visitDataSyncAll(dataSyncAll: JsonValue) = + dataSyncAll.let { + if (it == JsonValue.from(mapOf("type" to "data_sync_all"))) 1 else 0 + } override fun visitW4FormEmployeeSync(w4FormEmployeeSync: W4FormEmployeeSync) = w4FormEmployeeSync.validity() @@ -327,7 +327,9 @@ private constructor( companion object { - @JvmStatic fun ofDataSyncAll(dataSyncAll: DataSyncAll) = Body(dataSyncAll = dataSyncAll) + @JvmStatic + fun ofDataSyncAll() = + Body(dataSyncAll = JsonValue.from(mapOf("type" to "data_sync_all"))) @JvmStatic fun ofW4FormEmployeeSync(w4FormEmployeeSync: W4FormEmployeeSync) = @@ -337,7 +339,7 @@ private constructor( /** An interface that defines how to map each variant of [Body] to a value of type [T]. */ interface Visitor { - fun visitDataSyncAll(dataSyncAll: DataSyncAll): T + fun visitDataSyncAll(dataSyncAll: JsonValue): T fun visitW4FormEmployeeSync(w4FormEmployeeSync: W4FormEmployeeSync): T @@ -363,9 +365,9 @@ private constructor( when (type) { "data_sync_all" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Body(dataSyncAll = it, _json = json) - } ?: Body(_json = json) + return tryDeserialize(node, jacksonTypeRef()) + ?.let { Body(dataSyncAll = it, _json = json) } + ?.takeIf { it.isValid() } ?: Body(_json = json) } "w4_form_employee_sync" -> { return tryDeserialize(node, jacksonTypeRef())?.let { @@ -395,295 +397,10 @@ private constructor( } } - class DataSyncAll - private constructor( - private val type: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of() - ) : this(type, mutableMapOf()) - - /** - * The type of job to start. - * - * @throws FinchInvalidDataException 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 type(): Type = type.getRequired("type") - - /** - * Returns the raw JSON value of [type]. - * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - - @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 [DataSyncAll]. - * - * The following fields are required: - * ```java - * .type() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [DataSyncAll]. */ - class Builder internal constructor() { - - private var type: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(dataSyncAll: DataSyncAll) = apply { - type = dataSyncAll.type - additionalProperties = dataSyncAll.additionalProperties.toMutableMap() - } - - /** The type of job to start. */ - fun type(type: Type) = type(JsonField.of(type)) - - /** - * Sets [Builder.type] to an arbitrary JSON value. - * - * You should usually call [Builder.type] with a well-typed [Type] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun type(type: JsonField) = apply { this.type = type } - - 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 [DataSyncAll]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): DataSyncAll = - DataSyncAll(checkRequired("type", type), additionalProperties.toMutableMap()) - } - - private var validated: Boolean = false - - fun validate(): DataSyncAll = apply { - if (validated) { - return@apply - } - - type().validate() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - 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 = (type.asKnown().getOrNull()?.validity() ?: 0) - - /** The type of job to start. */ - class Type @JsonCreator private constructor(private val value: JsonField) : - Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val DATA_SYNC_ALL = of("data_sync_all") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - DATA_SYNC_ALL - } - - /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Type] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - DATA_SYNC_ALL, - /** - * An enum member indicating that [Type] was instantiated with an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if - * you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - DATA_SYNC_ALL -> Value.DATA_SYNC_ALL - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws FinchInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - DATA_SYNC_ALL -> Known.DATA_SYNC_ALL - else -> throw FinchInvalidDataException("Unknown Type: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws FinchInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - FinchInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - 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 (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is DataSyncAll && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "DataSyncAll{type=$type, additionalProperties=$additionalProperties}" - } - class W4FormEmployeeSync private constructor( private val params: JsonField, - private val type: JsonField, + private val type: JsonValue, private val additionalProperties: MutableMap, ) { @@ -692,7 +409,7 @@ private constructor( @JsonProperty("params") @ExcludeMissing params: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), ) : this(params, type, mutableMapOf()) /** @@ -705,11 +422,15 @@ private constructor( /** * The type of job to start. * - * @throws FinchInvalidDataException if the JSON field has an unexpected type or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected - * value). + * Expected to always return the following: + * ```java + * JsonValue.from("w4_form_employee_sync") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server + * responded with an unexpected value). */ - fun type(): Type = type.getRequired("type") + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type /** * Returns the raw JSON value of [params]. @@ -718,13 +439,6 @@ private constructor( */ @JsonProperty("params") @ExcludeMissing fun _params(): JsonField = params - /** - * Returns the raw JSON value of [type]. - * - * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -745,7 +459,6 @@ private constructor( * The following fields are required: * ```java * .params() - * .type() * ``` */ @JvmStatic fun builder() = Builder() @@ -755,7 +468,7 @@ private constructor( class Builder internal constructor() { private var params: JsonField? = null - private var type: JsonField? = null + private var type: JsonValue = JsonValue.from("w4_form_employee_sync") private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -776,17 +489,19 @@ private constructor( */ fun params(params: JsonField) = apply { this.params = params } - /** The type of job to start. */ - fun type(type: Type) = type(JsonField.of(type)) - /** - * Sets [Builder.type] to an arbitrary JSON value. + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("w4_form_employee_sync") + * ``` * - * You should usually call [Builder.type] with a well-typed [Type] value instead. * This method is primarily for setting the field to an undocumented or not yet * supported value. */ - fun type(type: JsonField) = apply { this.type = type } + fun type(type: JsonValue) = apply { this.type = type } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -818,7 +533,6 @@ private constructor( * The following fields are required: * ```java * .params() - * .type() * ``` * * @throws IllegalStateException if any required field is unset. @@ -826,7 +540,7 @@ private constructor( fun build(): W4FormEmployeeSync = W4FormEmployeeSync( checkRequired("params", params), - checkRequired("type", type), + type, additionalProperties.toMutableMap(), ) } @@ -839,7 +553,11 @@ private constructor( } params().validate() - type().validate() + _type().let { + if (it != JsonValue.from("w4_form_employee_sync")) { + throw FinchInvalidDataException("'type' is invalid, received $it") + } + } validated = true } @@ -860,7 +578,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (params.asKnown().getOrNull()?.validity() ?: 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + type.let { if (it == JsonValue.from("w4_form_employee_sync")) 1 else 0 } class Params private constructor( @@ -1033,131 +751,6 @@ private constructor( "Params{individualId=$individualId, additionalProperties=$additionalProperties}" } - /** The type of job to start. */ - class Type @JsonCreator private constructor(private val value: JsonField) : - Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that - * doesn't match any known member, and you want to know that value. For example, if - * the SDK is on an older version than the API, then the API may respond with new - * members that the SDK is unaware of. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val W4_FORM_EMPLOYEE_SYNC = of("w4_form_employee_sync") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - W4_FORM_EMPLOYEE_SYNC - } - - /** - * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Type] can contain an unknown value in a couple of cases: - * - It was deserialized from data that doesn't match any known member. For example, - * if the SDK is on an older version than the API, then the API may respond with - * new members that the SDK is unaware of. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - W4_FORM_EMPLOYEE_SYNC, - /** - * An enum member indicating that [Type] was instantiated with an unknown value. - */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if - * you want to throw for the unknown case. - */ - fun value(): Value = - when (this) { - W4_FORM_EMPLOYEE_SYNC -> Value.W4_FORM_EMPLOYEE_SYNC - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and - * don't want to throw for the unknown case. - * - * @throws FinchInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - W4_FORM_EMPLOYEE_SYNC -> Known.W4_FORM_EMPLOYEE_SYNC - else -> throw FinchInvalidDataException("Unknown Type: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for - * debugging and generally doesn't throw. - * - * @throws FinchInvalidDataException if this class instance's value does not have - * the expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - FinchInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Type = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - 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 (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Location.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Location.kt index 5af14dcb..e2c3a920 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Location.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Location.kt @@ -10,6 +10,7 @@ import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects @@ -22,10 +23,10 @@ private constructor( private val country: JsonField, private val line1: JsonField, private val line2: JsonField, - private val name: JsonField, private val postalCode: JsonField, - private val sourceId: JsonField, private val state: JsonField, + private val name: JsonField, + private val sourceId: JsonField, private val additionalProperties: MutableMap, ) { @@ -35,13 +36,13 @@ private constructor( @JsonProperty("country") @ExcludeMissing country: JsonField = JsonMissing.of(), @JsonProperty("line1") @ExcludeMissing line1: JsonField = JsonMissing.of(), @JsonProperty("line2") @ExcludeMissing line2: JsonField = JsonMissing.of(), - @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("postal_code") @ExcludeMissing postalCode: JsonField = JsonMissing.of(), - @JsonProperty("source_id") @ExcludeMissing sourceId: JsonField = JsonMissing.of(), @JsonProperty("state") @ExcludeMissing state: JsonField = JsonMissing.of(), - ) : this(city, country, line1, line2, name, postalCode, sourceId, state, mutableMapOf()) + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("source_id") @ExcludeMissing sourceId: JsonField = JsonMissing.of(), + ) : this(city, country, line1, line2, postalCode, state, name, sourceId, mutableMapOf()) /** * City, district, suburb, town, or village. @@ -76,32 +77,32 @@ private constructor( fun line2(): Optional = line2.getOptional("line2") /** + * The postal code or zip code. + * * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun name(): Optional = name.getOptional("name") + fun postalCode(): Optional = postalCode.getOptional("postal_code") /** - * The postal code or zip code. + * The state code. * * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun postalCode(): Optional = postalCode.getOptional("postal_code") + fun state(): Optional = state.getOptional("state") /** * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun sourceId(): Optional = sourceId.getOptional("source_id") + fun name(): Optional = name.getOptional("name") /** - * The state code. - * * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun state(): Optional = state.getOptional("state") + fun sourceId(): Optional = sourceId.getOptional("source_id") /** * Returns the raw JSON value of [city]. @@ -132,32 +133,32 @@ private constructor( @JsonProperty("line2") @ExcludeMissing fun _line2(): JsonField = line2 /** - * Returns the raw JSON value of [name]. + * Returns the raw JSON value of [postalCode]. * - * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [postalCode], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + @JsonProperty("postal_code") @ExcludeMissing fun _postalCode(): JsonField = postalCode /** - * Returns the raw JSON value of [postalCode]. + * Returns the raw JSON value of [state]. * - * Unlike [postalCode], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [state], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("postal_code") @ExcludeMissing fun _postalCode(): JsonField = postalCode + @JsonProperty("state") @ExcludeMissing fun _state(): JsonField = state /** - * Returns the raw JSON value of [sourceId]. + * Returns the raw JSON value of [name]. * - * Unlike [sourceId], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("source_id") @ExcludeMissing fun _sourceId(): JsonField = sourceId + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name /** - * Returns the raw JSON value of [state]. + * Returns the raw JSON value of [sourceId]. * - * Unlike [state], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [sourceId], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("state") @ExcludeMissing fun _state(): JsonField = state + @JsonProperty("source_id") @ExcludeMissing fun _sourceId(): JsonField = sourceId @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -173,21 +174,33 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Location]. */ + /** + * Returns a mutable builder for constructing an instance of [Location]. + * + * The following fields are required: + * ```java + * .city() + * .country() + * .line1() + * .line2() + * .postalCode() + * .state() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Location]. */ class Builder internal constructor() { - private var city: JsonField = JsonMissing.of() - private var country: JsonField = JsonMissing.of() - private var line1: JsonField = JsonMissing.of() - private var line2: JsonField = JsonMissing.of() + private var city: JsonField? = null + private var country: JsonField? = null + private var line1: JsonField? = null + private var line2: JsonField? = null + private var postalCode: JsonField? = null + private var state: JsonField? = null private var name: JsonField = JsonMissing.of() - private var postalCode: JsonField = JsonMissing.of() private var sourceId: JsonField = JsonMissing.of() - private var state: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -196,10 +209,10 @@ private constructor( country = location.country line1 = location.line1 line2 = location.line2 - name = location.name postalCode = location.postalCode - sourceId = location.sourceId state = location.state + name = location.name + sourceId = location.sourceId additionalProperties = location.additionalProperties.toMutableMap() } @@ -259,19 +272,6 @@ private constructor( */ fun line2(line2: JsonField) = apply { this.line2 = line2 } - fun name(name: String?) = name(JsonField.ofNullable(name)) - - /** Alias for calling [Builder.name] with `name.orElse(null)`. */ - fun name(name: Optional) = name(name.getOrNull()) - - /** - * Sets [Builder.name] to an arbitrary JSON value. - * - * You should usually call [Builder.name] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun name(name: JsonField) = apply { this.name = name } - /** The postal code or zip code. */ fun postalCode(postalCode: String?) = postalCode(JsonField.ofNullable(postalCode)) @@ -287,19 +287,6 @@ private constructor( */ fun postalCode(postalCode: JsonField) = apply { this.postalCode = postalCode } - fun sourceId(sourceId: String?) = sourceId(JsonField.ofNullable(sourceId)) - - /** Alias for calling [Builder.sourceId] with `sourceId.orElse(null)`. */ - fun sourceId(sourceId: Optional) = sourceId(sourceId.getOrNull()) - - /** - * Sets [Builder.sourceId] to an arbitrary JSON value. - * - * You should usually call [Builder.sourceId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun sourceId(sourceId: JsonField) = apply { this.sourceId = sourceId } - /** The state code. */ fun state(state: String?) = state(JsonField.ofNullable(state)) @@ -314,6 +301,32 @@ private constructor( */ fun state(state: JsonField) = apply { this.state = state } + fun name(name: String?) = name(JsonField.ofNullable(name)) + + /** Alias for calling [Builder.name] with `name.orElse(null)`. */ + fun name(name: Optional) = name(name.getOrNull()) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + fun sourceId(sourceId: String?) = sourceId(JsonField.ofNullable(sourceId)) + + /** Alias for calling [Builder.sourceId] with `sourceId.orElse(null)`. */ + fun sourceId(sourceId: Optional) = sourceId(sourceId.getOrNull()) + + /** + * Sets [Builder.sourceId] to an arbitrary JSON value. + * + * You should usually call [Builder.sourceId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun sourceId(sourceId: JsonField) = apply { this.sourceId = sourceId } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -337,17 +350,29 @@ private constructor( * Returns an immutable instance of [Location]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .city() + * .country() + * .line1() + * .line2() + * .postalCode() + * .state() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Location = Location( - city, - country, - line1, - line2, + checkRequired("city", city), + checkRequired("country", country), + checkRequired("line1", line1), + checkRequired("line2", line2), + checkRequired("postalCode", postalCode), + checkRequired("state", state), name, - postalCode, sourceId, - state, additionalProperties.toMutableMap(), ) } @@ -363,10 +388,10 @@ private constructor( country() line1() line2() - name() postalCode() - sourceId() state() + name() + sourceId() validated = true } @@ -389,25 +414,25 @@ private constructor( (if (country.asKnown().isPresent) 1 else 0) + (if (line1.asKnown().isPresent) 1 else 0) + (if (line2.asKnown().isPresent) 1 else 0) + - (if (name.asKnown().isPresent) 1 else 0) + (if (postalCode.asKnown().isPresent) 1 else 0) + - (if (sourceId.asKnown().isPresent) 1 else 0) + - (if (state.asKnown().isPresent) 1 else 0) + (if (state.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (sourceId.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Location && city == other.city && country == other.country && line1 == other.line1 && line2 == other.line2 && name == other.name && postalCode == other.postalCode && sourceId == other.sourceId && state == other.state && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Location && city == other.city && country == other.country && line1 == other.line1 && line2 == other.line2 && postalCode == other.postalCode && state == other.state && name == other.name && sourceId == other.sourceId && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(city, country, line1, line2, name, postalCode, sourceId, state, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(city, country, line1, line2, postalCode, state, name, sourceId, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Location{city=$city, country=$country, line1=$line1, line2=$line2, name=$name, postalCode=$postalCode, sourceId=$sourceId, state=$state, additionalProperties=$additionalProperties}" + "Location{city=$city, country=$country, line1=$line1, line2=$line2, postalCode=$postalCode, state=$state, name=$name, sourceId=$sourceId, additionalProperties=$additionalProperties}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Paging.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Paging.kt index c7cc6fb4..afaf3a26 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Paging.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Paging.kt @@ -10,6 +10,7 @@ import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonField import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects @@ -17,16 +18,24 @@ import java.util.Optional class Paging private constructor( - private val count: JsonField, private val offset: JsonField, + private val count: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("count") @ExcludeMissing count: JsonField = JsonMissing.of(), @JsonProperty("offset") @ExcludeMissing offset: JsonField = JsonMissing.of(), - ) : this(count, offset, mutableMapOf()) + @JsonProperty("count") @ExcludeMissing count: JsonField = JsonMissing.of(), + ) : this(offset, count, mutableMapOf()) + + /** + * The current start index of the returned list of elements + * + * @throws FinchInvalidDataException 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 offset(): Long = offset.getRequired("offset") /** * The total number of elements for the entire query (not just the given page) @@ -37,12 +46,11 @@ private constructor( fun count(): Optional = count.getOptional("count") /** - * The current start index of the returned list of elements + * Returns the raw JSON value of [offset]. * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * Unlike [offset], this method doesn't throw if the JSON field has an unexpected type. */ - fun offset(): Optional = offset.getOptional("offset") + @JsonProperty("offset") @ExcludeMissing fun _offset(): JsonField = offset /** * Returns the raw JSON value of [count]. @@ -51,13 +59,6 @@ private constructor( */ @JsonProperty("count") @ExcludeMissing fun _count(): JsonField = count - /** - * Returns the raw JSON value of [offset]. - * - * Unlike [offset], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("offset") @ExcludeMissing fun _offset(): JsonField = offset - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -72,45 +73,52 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Paging]. */ + /** + * Returns a mutable builder for constructing an instance of [Paging]. + * + * The following fields are required: + * ```java + * .offset() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Paging]. */ class Builder internal constructor() { + private var offset: JsonField? = null private var count: JsonField = JsonMissing.of() - private var offset: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(paging: Paging) = apply { - count = paging.count offset = paging.offset + count = paging.count additionalProperties = paging.additionalProperties.toMutableMap() } - /** The total number of elements for the entire query (not just the given page) */ - fun count(count: Long) = count(JsonField.of(count)) + /** The current start index of the returned list of elements */ + fun offset(offset: Long) = offset(JsonField.of(offset)) /** - * Sets [Builder.count] to an arbitrary JSON value. + * Sets [Builder.offset] to an arbitrary JSON value. * - * You should usually call [Builder.count] with a well-typed [Long] value instead. This + * You should usually call [Builder.offset] with a well-typed [Long] value instead. This * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun count(count: JsonField) = apply { this.count = count } + fun offset(offset: JsonField) = apply { this.offset = offset } - /** The current start index of the returned list of elements */ - fun offset(offset: Long) = offset(JsonField.of(offset)) + /** The total number of elements for the entire query (not just the given page) */ + fun count(count: Long) = count(JsonField.of(count)) /** - * Sets [Builder.offset] to an arbitrary JSON value. + * Sets [Builder.count] to an arbitrary JSON value. * - * You should usually call [Builder.offset] with a well-typed [Long] value instead. This + * You should usually call [Builder.count] with a well-typed [Long] value instead. This * method is primarily for setting the field to an undocumented or not yet supported value. */ - fun offset(offset: JsonField) = apply { this.offset = offset } + fun count(count: JsonField) = apply { this.count = count } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -135,8 +143,16 @@ private constructor( * Returns an immutable instance of [Paging]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .offset() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Paging = Paging(count, offset, additionalProperties.toMutableMap()) + fun build(): Paging = + Paging(checkRequired("offset", offset), count, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -146,8 +162,8 @@ private constructor( return@apply } - count() offset() + count() validated = true } @@ -166,22 +182,22 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (count.asKnown().isPresent) 1 else 0) + (if (offset.asKnown().isPresent) 1 else 0) + (if (offset.asKnown().isPresent) 1 else 0) + (if (count.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is Paging && count == other.count && offset == other.offset && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Paging && offset == other.offset && count == other.count && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(count, offset, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(offset, count, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Paging{count=$count, offset=$offset, additionalProperties=$additionalProperties}" + "Paging{offset=$offset, count=$count, additionalProperties=$additionalProperties}" } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyBenefitTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyBenefitTest.kt index b4ec445b..7f4ae9bc 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyBenefitTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyBenefitTest.kt @@ -14,12 +14,35 @@ internal class CompanyBenefitTest { val companyBenefit = CompanyBenefit.builder() .benefitId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .companyContribution( + CompanyBenefit.BenefitCompanyMatchContribution.builder() + .addTier( + CompanyBenefit.BenefitCompanyMatchContribution.Tier.builder() + .match(1L) + .threshold(1L) + .build() + ) + .type(CompanyBenefit.BenefitCompanyMatchContribution.Type.MATCH) + .build() + ) .description("description") .frequency(BenefitFrequency.ONE_TIME) .type(BenefitType._401K) .build() assertThat(companyBenefit.benefitId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + assertThat(companyBenefit.companyContribution()) + .contains( + CompanyBenefit.BenefitCompanyMatchContribution.builder() + .addTier( + CompanyBenefit.BenefitCompanyMatchContribution.Tier.builder() + .match(1L) + .threshold(1L) + .build() + ) + .type(CompanyBenefit.BenefitCompanyMatchContribution.Type.MATCH) + .build() + ) assertThat(companyBenefit.description()).contains("description") assertThat(companyBenefit.frequency()).contains(BenefitFrequency.ONE_TIME) assertThat(companyBenefit.type()).contains(BenefitType._401K) @@ -31,6 +54,17 @@ internal class CompanyBenefitTest { val companyBenefit = CompanyBenefit.builder() .benefitId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .companyContribution( + CompanyBenefit.BenefitCompanyMatchContribution.builder() + .addTier( + CompanyBenefit.BenefitCompanyMatchContribution.Tier.builder() + .match(1L) + .threshold(1L) + .build() + ) + .type(CompanyBenefit.BenefitCompanyMatchContribution.Type.MATCH) + .build() + ) .description("description") .frequency(BenefitFrequency.ONE_TIME) .type(BenefitType._401K) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyTest.kt index ec22941d..90087323 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyTest.kt @@ -44,10 +44,10 @@ internal class CompanyTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .primaryEmail("dev@stainless.com") @@ -88,10 +88,10 @@ internal class CompanyTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) assertThat(company.primaryEmail()).contains("dev@stainless.com") @@ -133,10 +133,10 @@ internal class CompanyTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .primaryEmail("dev@stainless.com") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyUpdateResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyUpdateResponseTest.kt index 40d8cb6b..3b710600 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyUpdateResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/CompanyUpdateResponseTest.kt @@ -45,10 +45,10 @@ internal class CompanyUpdateResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .primaryEmail("dev@stainless.com") @@ -88,10 +88,10 @@ internal class CompanyUpdateResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) assertThat(companyUpdateResponse.primaryEmail()).contains("dev@stainless.com") @@ -134,10 +134,10 @@ internal class CompanyUpdateResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .primaryEmail("dev@stainless.com") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/DocumentListResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/DocumentListResponseTest.kt index a92d7839..3656298e 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/DocumentListResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/DocumentListResponseTest.kt @@ -22,7 +22,7 @@ internal class DocumentListResponseTest { .year(0.0) .build() ) - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .build() assertThat(documentListResponse.documents()) @@ -36,7 +36,7 @@ internal class DocumentListResponseTest { .build() ) assertThat(documentListResponse.paging()) - .isEqualTo(Paging.builder().count(0L).offset(0L).build()) + .isEqualTo(Paging.builder().offset(0L).count(0L).build()) } @Test @@ -53,7 +53,7 @@ internal class DocumentListResponseTest { .year(0.0) .build() ) - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .build() val roundtrippedDocumentListResponse = diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentDataResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentDataResponseTest.kt index eb681174..c113d875 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentDataResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentDataResponseTest.kt @@ -3,7 +3,6 @@ package com.tryfinch.api.models import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.jsonMapper import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -15,25 +14,52 @@ internal class EmploymentDataResponseTest { val employmentDataResponse = EmploymentDataResponse.builder() .body( - EmploymentData.builder() + EmploymentData.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .classCode("class_code") .addCustomField( - EmploymentData.CustomField.builder() + EmploymentData.UnionMember0.CustomField.builder() .name("name") - .value(JsonValue.from(mapOf())) + .value("string") .build() ) - .department(EmploymentData.Department.builder().name("name").build()) + .department( + EmploymentData.UnionMember0.Department.builder().name("name").build() + ) .employment( - EmploymentData.Employment.builder() - .subtype(EmploymentData.Employment.Subtype.FULL_TIME) - .type(EmploymentData.Employment.Type.EMPLOYEE) + EmploymentData.UnionMember0.Employment.builder() + .subtype(EmploymentData.UnionMember0.Employment.Subtype.FULL_TIME) + .type(EmploymentData.UnionMember0.Employment.Type.EMPLOYEE) .build() ) - .employmentStatus(EmploymentData.EmploymentStatus.ACTIVE) + .employmentStatus(EmploymentData.UnionMember0.EmploymentStatus.ACTIVE) .endDate("end_date") .firstName("first_name") + .isActive(true) + .lastName("last_name") + .latestRehireDate("latest_rehire_date") + .location( + Location.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .name("name") + .sourceId("source_id") + .build() + ) + .manager( + EmploymentData.UnionMember0.Manager.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .middleName("middle_name") + .sourceId("source_id") + .startDate("start_date") + .title("title") + .workId("work_id") .income( Income.builder() .amount(0L) @@ -50,6 +76,36 @@ internal class EmploymentDataResponseTest { .unit(Income.Unit.YEARLY) .build() ) + .build() + ) + .code(0L) + .individualId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + + assertThat(employmentDataResponse.body()) + .isEqualTo( + EmploymentData.ofUnionMember0( + EmploymentData.UnionMember0.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .classCode("class_code") + .addCustomField( + EmploymentData.UnionMember0.CustomField.builder() + .name("name") + .value("string") + .build() + ) + .department( + EmploymentData.UnionMember0.Department.builder().name("name").build() + ) + .employment( + EmploymentData.UnionMember0.Employment.builder() + .subtype(EmploymentData.UnionMember0.Employment.Subtype.FULL_TIME) + .type(EmploymentData.UnionMember0.Employment.Type.EMPLOYEE) + .build() + ) + .employmentStatus(EmploymentData.UnionMember0.EmploymentStatus.ACTIVE) + .endDate("end_date") + .firstName("first_name") .isActive(true) .lastName("last_name") .latestRehireDate("latest_rehire_date") @@ -59,14 +115,14 @@ internal class EmploymentDataResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( - EmploymentData.Manager.builder() + EmploymentData.UnionMember0.Manager.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) @@ -75,79 +131,28 @@ internal class EmploymentDataResponseTest { .startDate("start_date") .title("title") .workId("work_id") + .income( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) + .addIncomeHistory( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) .build() ) - .code(0L) - .individualId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - - assertThat(employmentDataResponse.body()) - .contains( - EmploymentData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .classCode("class_code") - .addCustomField( - EmploymentData.CustomField.builder() - .name("name") - .value(JsonValue.from(mapOf())) - .build() - ) - .department(EmploymentData.Department.builder().name("name").build()) - .employment( - EmploymentData.Employment.builder() - .subtype(EmploymentData.Employment.Subtype.FULL_TIME) - .type(EmploymentData.Employment.Type.EMPLOYEE) - .build() - ) - .employmentStatus(EmploymentData.EmploymentStatus.ACTIVE) - .endDate("end_date") - .firstName("first_name") - .income( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) - .addIncomeHistory( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) - .isActive(true) - .lastName("last_name") - .latestRehireDate("latest_rehire_date") - .location( - Location.builder() - .city("city") - .country("country") - .line1("line1") - .line2("line2") - .name("name") - .postalCode("postal_code") - .sourceId("source_id") - .state("state") - .build() - ) - .manager( - EmploymentData.Manager.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) - .middleName("middle_name") - .sourceId("source_id") - .startDate("start_date") - .title("title") - .workId("work_id") - .build() ) - assertThat(employmentDataResponse.code()).contains(0L) + assertThat(employmentDataResponse.code()).isEqualTo(0L) assertThat(employmentDataResponse.individualId()) - .contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") } @Test @@ -156,41 +161,27 @@ internal class EmploymentDataResponseTest { val employmentDataResponse = EmploymentDataResponse.builder() .body( - EmploymentData.builder() + EmploymentData.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .classCode("class_code") .addCustomField( - EmploymentData.CustomField.builder() + EmploymentData.UnionMember0.CustomField.builder() .name("name") - .value(JsonValue.from(mapOf())) + .value("string") .build() ) - .department(EmploymentData.Department.builder().name("name").build()) + .department( + EmploymentData.UnionMember0.Department.builder().name("name").build() + ) .employment( - EmploymentData.Employment.builder() - .subtype(EmploymentData.Employment.Subtype.FULL_TIME) - .type(EmploymentData.Employment.Type.EMPLOYEE) + EmploymentData.UnionMember0.Employment.builder() + .subtype(EmploymentData.UnionMember0.Employment.Subtype.FULL_TIME) + .type(EmploymentData.UnionMember0.Employment.Type.EMPLOYEE) .build() ) - .employmentStatus(EmploymentData.EmploymentStatus.ACTIVE) + .employmentStatus(EmploymentData.UnionMember0.EmploymentStatus.ACTIVE) .endDate("end_date") .firstName("first_name") - .income( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) - .addIncomeHistory( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) .isActive(true) .lastName("last_name") .latestRehireDate("latest_rehire_date") @@ -200,14 +191,14 @@ internal class EmploymentDataResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( - EmploymentData.Manager.builder() + EmploymentData.UnionMember0.Manager.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) @@ -216,6 +207,22 @@ internal class EmploymentDataResponseTest { .startDate("start_date") .title("title") .workId("work_id") + .income( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) + .addIncomeHistory( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) .build() ) .code(0L) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentDataTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentDataTest.kt index 1cd072e8..740c8a9d 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentDataTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentDataTest.kt @@ -5,50 +5,37 @@ package com.tryfinch.api.models import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.jsonMapper -import kotlin.jvm.optionals.getOrNull +import com.tryfinch.api.errors.FinchInvalidDataException import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource internal class EmploymentDataTest { @Test - fun create() { - val employmentData = - EmploymentData.builder() + fun ofUnionMember0() { + val unionMember0 = + EmploymentData.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .classCode("class_code") .addCustomField( - EmploymentData.CustomField.builder() + EmploymentData.UnionMember0.CustomField.builder() .name("name") - .value(JsonValue.from(mapOf())) + .value("string") .build() ) - .department(EmploymentData.Department.builder().name("name").build()) + .department(EmploymentData.UnionMember0.Department.builder().name("name").build()) .employment( - EmploymentData.Employment.builder() - .subtype(EmploymentData.Employment.Subtype.FULL_TIME) - .type(EmploymentData.Employment.Type.EMPLOYEE) + EmploymentData.UnionMember0.Employment.builder() + .subtype(EmploymentData.UnionMember0.Employment.Subtype.FULL_TIME) + .type(EmploymentData.UnionMember0.Employment.Type.EMPLOYEE) .build() ) - .employmentStatus(EmploymentData.EmploymentStatus.ACTIVE) + .employmentStatus(EmploymentData.UnionMember0.EmploymentStatus.ACTIVE) .endDate("end_date") .firstName("first_name") - .income( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) - .addIncomeHistory( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) .isActive(true) .lastName("last_name") .latestRehireDate("latest_rehire_date") @@ -58,14 +45,14 @@ internal class EmploymentDataTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( - EmploymentData.Manager.builder() + EmploymentData.UnionMember0.Manager.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) @@ -74,98 +61,6 @@ internal class EmploymentDataTest { .startDate("start_date") .title("title") .workId("work_id") - .build() - - assertThat(employmentData.id()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - assertThat(employmentData.classCode()).contains("class_code") - assertThat(employmentData.customFields().getOrNull()) - .containsExactly( - EmploymentData.CustomField.builder() - .name("name") - .value(JsonValue.from(mapOf())) - .build() - ) - assertThat(employmentData.department()) - .contains(EmploymentData.Department.builder().name("name").build()) - assertThat(employmentData.employment()) - .contains( - EmploymentData.Employment.builder() - .subtype(EmploymentData.Employment.Subtype.FULL_TIME) - .type(EmploymentData.Employment.Type.EMPLOYEE) - .build() - ) - assertThat(employmentData.employmentStatus()) - .contains(EmploymentData.EmploymentStatus.ACTIVE) - assertThat(employmentData.endDate()).contains("end_date") - assertThat(employmentData.firstName()).contains("first_name") - assertThat(employmentData.income()) - .contains( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) - assertThat(employmentData.incomeHistory().getOrNull()) - .containsExactly( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) - assertThat(employmentData.isActive()).contains(true) - assertThat(employmentData.lastName()).contains("last_name") - assertThat(employmentData.latestRehireDate()).contains("latest_rehire_date") - assertThat(employmentData.location()) - .contains( - Location.builder() - .city("city") - .country("country") - .line1("line1") - .line2("line2") - .name("name") - .postalCode("postal_code") - .sourceId("source_id") - .state("state") - .build() - ) - assertThat(employmentData.manager()) - .contains( - EmploymentData.Manager.builder().id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e").build() - ) - assertThat(employmentData.middleName()).contains("middle_name") - assertThat(employmentData.sourceId()).contains("source_id") - assertThat(employmentData.startDate()).contains("start_date") - assertThat(employmentData.title()).contains("title") - assertThat(employmentData.workId()).contains("work_id") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val employmentData = - EmploymentData.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .classCode("class_code") - .addCustomField( - EmploymentData.CustomField.builder() - .name("name") - .value(JsonValue.from(mapOf())) - .build() - ) - .department(EmploymentData.Department.builder().name("name").build()) - .employment( - EmploymentData.Employment.builder() - .subtype(EmploymentData.Employment.Subtype.FULL_TIME) - .type(EmploymentData.Employment.Type.EMPLOYEE) - .build() - ) - .employmentStatus(EmploymentData.EmploymentStatus.ACTIVE) - .endDate("end_date") - .firstName("first_name") .income( Income.builder() .amount(0L) @@ -182,33 +77,84 @@ internal class EmploymentDataTest { .unit(Income.Unit.YEARLY) .build() ) - .isActive(true) - .lastName("last_name") - .latestRehireDate("latest_rehire_date") - .location( - Location.builder() - .city("city") - .country("country") - .line1("line1") - .line2("line2") - .name("name") - .postalCode("postal_code") - .sourceId("source_id") - .state("state") - .build() - ) - .manager( - EmploymentData.Manager.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .build() - ) - .middleName("middle_name") - .sourceId("source_id") - .startDate("start_date") - .title("title") - .workId("work_id") .build() + val employmentData = EmploymentData.ofUnionMember0(unionMember0) + + assertThat(employmentData.unionMember0()).contains(unionMember0) + assertThat(employmentData.batchError()).isEmpty + } + + @Test + fun ofUnionMember0Roundtrip() { + val jsonMapper = jsonMapper() + val employmentData = + EmploymentData.ofUnionMember0( + EmploymentData.UnionMember0.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .classCode("class_code") + .addCustomField( + EmploymentData.UnionMember0.CustomField.builder() + .name("name") + .value("string") + .build() + ) + .department( + EmploymentData.UnionMember0.Department.builder().name("name").build() + ) + .employment( + EmploymentData.UnionMember0.Employment.builder() + .subtype(EmploymentData.UnionMember0.Employment.Subtype.FULL_TIME) + .type(EmploymentData.UnionMember0.Employment.Type.EMPLOYEE) + .build() + ) + .employmentStatus(EmploymentData.UnionMember0.EmploymentStatus.ACTIVE) + .endDate("end_date") + .firstName("first_name") + .isActive(true) + .lastName("last_name") + .latestRehireDate("latest_rehire_date") + .location( + Location.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .name("name") + .sourceId("source_id") + .build() + ) + .manager( + EmploymentData.UnionMember0.Manager.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .build() + ) + .middleName("middle_name") + .sourceId("source_id") + .startDate("start_date") + .title("title") + .workId("work_id") + .income( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) + .addIncomeHistory( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) + .build() + ) + val roundtrippedEmploymentData = jsonMapper.readValue( jsonMapper.writeValueAsString(employmentData), @@ -217,4 +163,60 @@ internal class EmploymentDataTest { assertThat(roundtrippedEmploymentData).isEqualTo(employmentData) } + + @Test + fun ofBatchError() { + val batchError = + EmploymentData.BatchError.builder() + .code(0.0) + .message("message") + .name("name") + .finchCode("finch_code") + .build() + + val employmentData = EmploymentData.ofBatchError(batchError) + + assertThat(employmentData.unionMember0()).isEmpty + assertThat(employmentData.batchError()).contains(batchError) + } + + @Test + fun ofBatchErrorRoundtrip() { + val jsonMapper = jsonMapper() + val employmentData = + EmploymentData.ofBatchError( + EmploymentData.BatchError.builder() + .code(0.0) + .message("message") + .name("name") + .finchCode("finch_code") + .build() + ) + + val roundtrippedEmploymentData = + jsonMapper.readValue( + jsonMapper.writeValueAsString(employmentData), + jacksonTypeRef(), + ) + + assertThat(roundtrippedEmploymentData).isEqualTo(employmentData) + } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val employmentData = + jsonMapper().convertValue(testCase.value, jacksonTypeRef()) + + val e = assertThrows { employmentData.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentUpdateResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentUpdateResponseTest.kt index 36d22b27..2b9c3056 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentUpdateResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/EmploymentUpdateResponseTest.kt @@ -58,10 +58,10 @@ internal class EmploymentUpdateResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( @@ -125,10 +125,10 @@ internal class EmploymentUpdateResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) assertThat(employmentUpdateResponse.manager()) @@ -191,10 +191,10 @@ internal class EmploymentUpdateResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisBenefitCreateParamsTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisBenefitCreateParamsTest.kt index fea44e47..d16fa73a 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisBenefitCreateParamsTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisBenefitCreateParamsTest.kt @@ -10,6 +10,17 @@ internal class HrisBenefitCreateParamsTest { @Test fun create() { HrisBenefitCreateParams.builder() + .companyContribution( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.builder() + .addTier( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.Tier.builder() + .match(1L) + .threshold(1L) + .build() + ) + .type(HrisBenefitCreateParams.BenefitCompanyMatchContribution.Type.MATCH) + .build() + ) .description("description") .frequency(BenefitFrequency.ONE_TIME) .type(BenefitType._401K) @@ -20,6 +31,17 @@ internal class HrisBenefitCreateParamsTest { fun body() { val params = HrisBenefitCreateParams.builder() + .companyContribution( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.builder() + .addTier( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.Tier.builder() + .match(1L) + .threshold(1L) + .build() + ) + .type(HrisBenefitCreateParams.BenefitCompanyMatchContribution.Type.MATCH) + .build() + ) .description("description") .frequency(BenefitFrequency.ONE_TIME) .type(BenefitType._401K) @@ -27,6 +49,18 @@ internal class HrisBenefitCreateParamsTest { val body = params._body() + assertThat(body.companyContribution()) + .contains( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.builder() + .addTier( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.Tier.builder() + .match(1L) + .threshold(1L) + .build() + ) + .type(HrisBenefitCreateParams.BenefitCompanyMatchContribution.Type.MATCH) + .build() + ) assertThat(body.description()).contains("description") assertThat(body.frequency()).contains(BenefitFrequency.ONE_TIME) assertThat(body.type()).contains(BenefitType._401K) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageResponseTest.kt index 6c4a338d..ba984c74 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageResponseTest.kt @@ -28,7 +28,7 @@ internal class HrisDirectoryListIndividualsPageResponseTest { .middleName("middle_name") .build() ) - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .build() assertThat(hrisDirectoryListIndividualsPageResponse.individuals()) @@ -48,7 +48,7 @@ internal class HrisDirectoryListIndividualsPageResponseTest { .build() ) assertThat(hrisDirectoryListIndividualsPageResponse.paging()) - .isEqualTo(Paging.builder().count(0L).offset(0L).build()) + .isEqualTo(Paging.builder().offset(0L).count(0L).build()) } @Test @@ -71,7 +71,7 @@ internal class HrisDirectoryListIndividualsPageResponseTest { .middleName("middle_name") .build() ) - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .build() val roundtrippedHrisDirectoryListIndividualsPageResponse = diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisDirectoryListPageResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisDirectoryListPageResponseTest.kt index 5149910b..81d6003e 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisDirectoryListPageResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisDirectoryListPageResponseTest.kt @@ -28,7 +28,7 @@ internal class HrisDirectoryListPageResponseTest { .middleName("middle_name") .build() ) - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .build() assertThat(hrisDirectoryListPageResponse.individuals()) @@ -48,7 +48,7 @@ internal class HrisDirectoryListPageResponseTest { .build() ) assertThat(hrisDirectoryListPageResponse.paging()) - .isEqualTo(Paging.builder().count(0L).offset(0L).build()) + .isEqualTo(Paging.builder().offset(0L).count(0L).build()) } @Test @@ -71,7 +71,7 @@ internal class HrisDirectoryListPageResponseTest { .middleName("middle_name") .build() ) - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .build() val roundtrippedHrisDirectoryListPageResponse = diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageResponseTest.kt index 21c2d616..28f9e30b 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageResponseTest.kt @@ -3,7 +3,6 @@ package com.tryfinch.api.models import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.jsonMapper import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -17,43 +16,33 @@ internal class HrisEmploymentRetrieveManyPageResponseTest { .addResponse( EmploymentDataResponse.builder() .body( - EmploymentData.builder() + EmploymentData.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .classCode("class_code") .addCustomField( - EmploymentData.CustomField.builder() + EmploymentData.UnionMember0.CustomField.builder() .name("name") - .value(JsonValue.from(mapOf())) + .value("string") .build() ) .department( - EmploymentData.Department.builder().name("name").build() + EmploymentData.UnionMember0.Department.builder() + .name("name") + .build() ) .employment( - EmploymentData.Employment.builder() - .subtype(EmploymentData.Employment.Subtype.FULL_TIME) - .type(EmploymentData.Employment.Type.EMPLOYEE) + EmploymentData.UnionMember0.Employment.builder() + .subtype( + EmploymentData.UnionMember0.Employment.Subtype.FULL_TIME + ) + .type(EmploymentData.UnionMember0.Employment.Type.EMPLOYEE) .build() ) - .employmentStatus(EmploymentData.EmploymentStatus.ACTIVE) + .employmentStatus( + EmploymentData.UnionMember0.EmploymentStatus.ACTIVE + ) .endDate("end_date") .firstName("first_name") - .income( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) - .addIncomeHistory( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) .isActive(true) .lastName("last_name") .latestRehireDate("latest_rehire_date") @@ -63,14 +52,14 @@ internal class HrisEmploymentRetrieveManyPageResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( - EmploymentData.Manager.builder() + EmploymentData.UnionMember0.Manager.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) @@ -79,6 +68,22 @@ internal class HrisEmploymentRetrieveManyPageResponseTest { .startDate("start_date") .title("title") .workId("work_id") + .income( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) + .addIncomeHistory( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) .build() ) .code(0L) @@ -91,41 +96,31 @@ internal class HrisEmploymentRetrieveManyPageResponseTest { .containsExactly( EmploymentDataResponse.builder() .body( - EmploymentData.builder() + EmploymentData.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .classCode("class_code") .addCustomField( - EmploymentData.CustomField.builder() + EmploymentData.UnionMember0.CustomField.builder() + .name("name") + .value("string") + .build() + ) + .department( + EmploymentData.UnionMember0.Department.builder() .name("name") - .value(JsonValue.from(mapOf())) .build() ) - .department(EmploymentData.Department.builder().name("name").build()) .employment( - EmploymentData.Employment.builder() - .subtype(EmploymentData.Employment.Subtype.FULL_TIME) - .type(EmploymentData.Employment.Type.EMPLOYEE) + EmploymentData.UnionMember0.Employment.builder() + .subtype( + EmploymentData.UnionMember0.Employment.Subtype.FULL_TIME + ) + .type(EmploymentData.UnionMember0.Employment.Type.EMPLOYEE) .build() ) - .employmentStatus(EmploymentData.EmploymentStatus.ACTIVE) + .employmentStatus(EmploymentData.UnionMember0.EmploymentStatus.ACTIVE) .endDate("end_date") .firstName("first_name") - .income( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) - .addIncomeHistory( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) .isActive(true) .lastName("last_name") .latestRehireDate("latest_rehire_date") @@ -135,14 +130,14 @@ internal class HrisEmploymentRetrieveManyPageResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( - EmploymentData.Manager.builder() + EmploymentData.UnionMember0.Manager.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) @@ -151,6 +146,22 @@ internal class HrisEmploymentRetrieveManyPageResponseTest { .startDate("start_date") .title("title") .workId("work_id") + .income( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) + .addIncomeHistory( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) .build() ) .code(0L) @@ -167,43 +178,33 @@ internal class HrisEmploymentRetrieveManyPageResponseTest { .addResponse( EmploymentDataResponse.builder() .body( - EmploymentData.builder() + EmploymentData.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .classCode("class_code") .addCustomField( - EmploymentData.CustomField.builder() + EmploymentData.UnionMember0.CustomField.builder() .name("name") - .value(JsonValue.from(mapOf())) + .value("string") .build() ) .department( - EmploymentData.Department.builder().name("name").build() + EmploymentData.UnionMember0.Department.builder() + .name("name") + .build() ) .employment( - EmploymentData.Employment.builder() - .subtype(EmploymentData.Employment.Subtype.FULL_TIME) - .type(EmploymentData.Employment.Type.EMPLOYEE) + EmploymentData.UnionMember0.Employment.builder() + .subtype( + EmploymentData.UnionMember0.Employment.Subtype.FULL_TIME + ) + .type(EmploymentData.UnionMember0.Employment.Type.EMPLOYEE) .build() ) - .employmentStatus(EmploymentData.EmploymentStatus.ACTIVE) + .employmentStatus( + EmploymentData.UnionMember0.EmploymentStatus.ACTIVE + ) .endDate("end_date") .firstName("first_name") - .income( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) - .addIncomeHistory( - Income.builder() - .amount(0L) - .currency("currency") - .effectiveDate("effective_date") - .unit(Income.Unit.YEARLY) - .build() - ) .isActive(true) .lastName("last_name") .latestRehireDate("latest_rehire_date") @@ -213,14 +214,14 @@ internal class HrisEmploymentRetrieveManyPageResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( - EmploymentData.Manager.builder() + EmploymentData.UnionMember0.Manager.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() ) @@ -229,6 +230,22 @@ internal class HrisEmploymentRetrieveManyPageResponseTest { .startDate("start_date") .title("title") .workId("work_id") + .income( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) + .addIncomeHistory( + Income.builder() + .amount(0L) + .currency("currency") + .effectiveDate("effective_date") + .unit(Income.Unit.YEARLY) + .build() + ) .build() ) .code(0L) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageResponseTest.kt index 4b16d20c..28194510 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageResponseTest.kt @@ -16,25 +16,18 @@ internal class HrisIndividualRetrieveManyPageResponseTest { .addResponse( IndividualResponse.builder() .body( - Individual.builder() + Individual.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .dob("dob") - .addEmail( - Individual.Email.builder() - .data("data") - .type(Individual.Email.Type.WORK) - .build() - ) - .encryptedSsn("encrypted_ssn") - .ethnicity(Individual.Ethnicity.ASIAN) + .ethnicity(Individual.UnionMember0.Ethnicity.ASIAN) .firstName("first_name") - .gender(Individual.Gender.FEMALE) + .gender(Individual.UnionMember0.Gender.FEMALE) .lastName("last_name") .middleName("middle_name") .addPhoneNumber( - Individual.PhoneNumber.builder() + Individual.UnionMember0.PhoneNumber.builder() .data("data") - .type(Individual.PhoneNumber.Type.WORK) + .type(Individual.UnionMember0.PhoneNumber.Type.WORK) .build() ) .preferredName("preferred_name") @@ -44,12 +37,19 @@ internal class HrisIndividualRetrieveManyPageResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) + .addEmail( + Individual.UnionMember0.Email.builder() + .data("data") + .type(Individual.UnionMember0.Email.Type.WORK) + .build() + ) + .encryptedSsn("encrypted_ssn") .ssn("ssn") .build() ) @@ -63,25 +63,18 @@ internal class HrisIndividualRetrieveManyPageResponseTest { .containsExactly( IndividualResponse.builder() .body( - Individual.builder() + Individual.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .dob("dob") - .addEmail( - Individual.Email.builder() - .data("data") - .type(Individual.Email.Type.WORK) - .build() - ) - .encryptedSsn("encrypted_ssn") - .ethnicity(Individual.Ethnicity.ASIAN) + .ethnicity(Individual.UnionMember0.Ethnicity.ASIAN) .firstName("first_name") - .gender(Individual.Gender.FEMALE) + .gender(Individual.UnionMember0.Gender.FEMALE) .lastName("last_name") .middleName("middle_name") .addPhoneNumber( - Individual.PhoneNumber.builder() + Individual.UnionMember0.PhoneNumber.builder() .data("data") - .type(Individual.PhoneNumber.Type.WORK) + .type(Individual.UnionMember0.PhoneNumber.Type.WORK) .build() ) .preferredName("preferred_name") @@ -91,12 +84,19 @@ internal class HrisIndividualRetrieveManyPageResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") + .build() + ) + .addEmail( + Individual.UnionMember0.Email.builder() + .data("data") + .type(Individual.UnionMember0.Email.Type.WORK) .build() ) + .encryptedSsn("encrypted_ssn") .ssn("ssn") .build() ) @@ -114,25 +114,18 @@ internal class HrisIndividualRetrieveManyPageResponseTest { .addResponse( IndividualResponse.builder() .body( - Individual.builder() + Individual.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .dob("dob") - .addEmail( - Individual.Email.builder() - .data("data") - .type(Individual.Email.Type.WORK) - .build() - ) - .encryptedSsn("encrypted_ssn") - .ethnicity(Individual.Ethnicity.ASIAN) + .ethnicity(Individual.UnionMember0.Ethnicity.ASIAN) .firstName("first_name") - .gender(Individual.Gender.FEMALE) + .gender(Individual.UnionMember0.Gender.FEMALE) .lastName("last_name") .middleName("middle_name") .addPhoneNumber( - Individual.PhoneNumber.builder() + Individual.UnionMember0.PhoneNumber.builder() .data("data") - .type(Individual.PhoneNumber.Type.WORK) + .type(Individual.UnionMember0.PhoneNumber.Type.WORK) .build() ) .preferredName("preferred_name") @@ -142,12 +135,19 @@ internal class HrisIndividualRetrieveManyPageResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) + .addEmail( + Individual.UnionMember0.Email.builder() + .data("data") + .type(Individual.UnionMember0.Email.Type.WORK) + .build() + ) + .encryptedSsn("encrypted_ssn") .ssn("ssn") .build() ) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageResponseTest.kt index 0ce7087a..21ccd032 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageResponseTest.kt @@ -18,7 +18,7 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( @@ -36,7 +36,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -69,7 +71,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -103,7 +107,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -139,7 +145,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -170,7 +178,7 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( @@ -188,7 +196,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -219,7 +229,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -251,7 +263,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -284,7 +298,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -319,7 +335,7 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( @@ -337,7 +353,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -370,7 +388,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -404,7 +424,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -440,7 +462,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualInDirectoryTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualInDirectoryTest.kt index dc8f18ea..c8509609 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualInDirectoryTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualInDirectoryTest.kt @@ -26,7 +26,7 @@ internal class IndividualInDirectoryTest { .middleName("middle_name") .build() - assertThat(individualInDirectory.id()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + assertThat(individualInDirectory.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(individualInDirectory.department()) .contains(IndividualInDirectory.Department.builder().name("name").build()) assertThat(individualInDirectory.firstName()).contains("first_name") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualResponseTest.kt index 1f022127..3f480bc3 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualResponseTest.kt @@ -14,25 +14,18 @@ internal class IndividualResponseTest { val individualResponse = IndividualResponse.builder() .body( - Individual.builder() + Individual.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .dob("dob") - .addEmail( - Individual.Email.builder() - .data("data") - .type(Individual.Email.Type.WORK) - .build() - ) - .encryptedSsn("encrypted_ssn") - .ethnicity(Individual.Ethnicity.ASIAN) + .ethnicity(Individual.UnionMember0.Ethnicity.ASIAN) .firstName("first_name") - .gender(Individual.Gender.FEMALE) + .gender(Individual.UnionMember0.Gender.FEMALE) .lastName("last_name") .middleName("middle_name") .addPhoneNumber( - Individual.PhoneNumber.builder() + Individual.UnionMember0.PhoneNumber.builder() .data("data") - .type(Individual.PhoneNumber.Type.WORK) + .type(Individual.UnionMember0.PhoneNumber.Type.WORK) .build() ) .preferredName("preferred_name") @@ -42,12 +35,19 @@ internal class IndividualResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) + .addEmail( + Individual.UnionMember0.Email.builder() + .data("data") + .type(Individual.UnionMember0.Email.Type.WORK) + .build() + ) + .encryptedSsn("encrypted_ssn") .ssn("ssn") .build() ) @@ -56,46 +56,48 @@ internal class IndividualResponseTest { .build() assertThat(individualResponse.body()) - .contains( - Individual.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .dob("dob") - .addEmail( - Individual.Email.builder() - .data("data") - .type(Individual.Email.Type.WORK) - .build() - ) - .encryptedSsn("encrypted_ssn") - .ethnicity(Individual.Ethnicity.ASIAN) - .firstName("first_name") - .gender(Individual.Gender.FEMALE) - .lastName("last_name") - .middleName("middle_name") - .addPhoneNumber( - Individual.PhoneNumber.builder() - .data("data") - .type(Individual.PhoneNumber.Type.WORK) - .build() - ) - .preferredName("preferred_name") - .residence( - Location.builder() - .city("city") - .country("country") - .line1("line1") - .line2("line2") - .name("name") - .postalCode("postal_code") - .sourceId("source_id") - .state("state") - .build() - ) - .ssn("ssn") - .build() + .isEqualTo( + Individual.ofUnionMember0( + Individual.UnionMember0.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .dob("dob") + .ethnicity(Individual.UnionMember0.Ethnicity.ASIAN) + .firstName("first_name") + .gender(Individual.UnionMember0.Gender.FEMALE) + .lastName("last_name") + .middleName("middle_name") + .addPhoneNumber( + Individual.UnionMember0.PhoneNumber.builder() + .data("data") + .type(Individual.UnionMember0.PhoneNumber.Type.WORK) + .build() + ) + .preferredName("preferred_name") + .residence( + Location.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .name("name") + .sourceId("source_id") + .build() + ) + .addEmail( + Individual.UnionMember0.Email.builder() + .data("data") + .type(Individual.UnionMember0.Email.Type.WORK) + .build() + ) + .encryptedSsn("encrypted_ssn") + .ssn("ssn") + .build() + ) ) - assertThat(individualResponse.code()).contains(0L) - assertThat(individualResponse.individualId()).contains("individual_id") + assertThat(individualResponse.code()).isEqualTo(0L) + assertThat(individualResponse.individualId()).isEqualTo("individual_id") } @Test @@ -104,25 +106,18 @@ internal class IndividualResponseTest { val individualResponse = IndividualResponse.builder() .body( - Individual.builder() + Individual.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .dob("dob") - .addEmail( - Individual.Email.builder() - .data("data") - .type(Individual.Email.Type.WORK) - .build() - ) - .encryptedSsn("encrypted_ssn") - .ethnicity(Individual.Ethnicity.ASIAN) + .ethnicity(Individual.UnionMember0.Ethnicity.ASIAN) .firstName("first_name") - .gender(Individual.Gender.FEMALE) + .gender(Individual.UnionMember0.Gender.FEMALE) .lastName("last_name") .middleName("middle_name") .addPhoneNumber( - Individual.PhoneNumber.builder() + Individual.UnionMember0.PhoneNumber.builder() .data("data") - .type(Individual.PhoneNumber.Type.WORK) + .type(Individual.UnionMember0.PhoneNumber.Type.WORK) .build() ) .preferredName("preferred_name") @@ -132,12 +127,19 @@ internal class IndividualResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) + .addEmail( + Individual.UnionMember0.Email.builder() + .data("data") + .type(Individual.UnionMember0.Email.Type.WORK) + .build() + ) + .encryptedSsn("encrypted_ssn") .ssn("ssn") .build() ) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualTest.kt index e8760c8f..b6ae2c0f 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualTest.kt @@ -3,32 +3,32 @@ package com.tryfinch.api.models import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.jsonMapper -import kotlin.jvm.optionals.getOrNull +import com.tryfinch.api.errors.FinchInvalidDataException import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource internal class IndividualTest { @Test - fun create() { - val individual = - Individual.builder() + fun ofUnionMember0() { + val unionMember0 = + Individual.UnionMember0.builder() .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .dob("dob") - .addEmail( - Individual.Email.builder().data("data").type(Individual.Email.Type.WORK).build() - ) - .encryptedSsn("encrypted_ssn") - .ethnicity(Individual.Ethnicity.ASIAN) + .ethnicity(Individual.UnionMember0.Ethnicity.ASIAN) .firstName("first_name") - .gender(Individual.Gender.FEMALE) + .gender(Individual.UnionMember0.Gender.FEMALE) .lastName("last_name") .middleName("middle_name") .addPhoneNumber( - Individual.PhoneNumber.builder() + Individual.UnionMember0.PhoneNumber.builder() .data("data") - .type(Individual.PhoneNumber.Type.WORK) + .type(Individual.UnionMember0.PhoneNumber.Type.WORK) .build() ) .preferredName("preferred_name") @@ -38,88 +38,108 @@ internal class IndividualTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") + .build() + ) + .addEmail( + Individual.UnionMember0.Email.builder() + .data("data") + .type(Individual.UnionMember0.Email.Type.WORK) .build() ) + .encryptedSsn("encrypted_ssn") .ssn("ssn") .build() - assertThat(individual.id()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - assertThat(individual.dob()).contains("dob") - assertThat(individual.emails().getOrNull()) - .containsExactly( - Individual.Email.builder().data("data").type(Individual.Email.Type.WORK).build() - ) - assertThat(individual.encryptedSsn()).contains("encrypted_ssn") - assertThat(individual.ethnicity()).contains(Individual.Ethnicity.ASIAN) - assertThat(individual.firstName()).contains("first_name") - assertThat(individual.gender()).contains(Individual.Gender.FEMALE) - assertThat(individual.lastName()).contains("last_name") - assertThat(individual.middleName()).contains("middle_name") - assertThat(individual.phoneNumbers().getOrNull()) - .containsExactly( - Individual.PhoneNumber.builder() - .data("data") - .type(Individual.PhoneNumber.Type.WORK) + val individual = Individual.ofUnionMember0(unionMember0) + + assertThat(individual.unionMember0()).contains(unionMember0) + assertThat(individual.batchError()).isEmpty + } + + @Test + fun ofUnionMember0Roundtrip() { + val jsonMapper = jsonMapper() + val individual = + Individual.ofUnionMember0( + Individual.UnionMember0.builder() + .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + .dob("dob") + .ethnicity(Individual.UnionMember0.Ethnicity.ASIAN) + .firstName("first_name") + .gender(Individual.UnionMember0.Gender.FEMALE) + .lastName("last_name") + .middleName("middle_name") + .addPhoneNumber( + Individual.UnionMember0.PhoneNumber.builder() + .data("data") + .type(Individual.UnionMember0.PhoneNumber.Type.WORK) + .build() + ) + .preferredName("preferred_name") + .residence( + Location.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .name("name") + .sourceId("source_id") + .build() + ) + .addEmail( + Individual.UnionMember0.Email.builder() + .data("data") + .type(Individual.UnionMember0.Email.Type.WORK) + .build() + ) + .encryptedSsn("encrypted_ssn") + .ssn("ssn") .build() ) - assertThat(individual.preferredName()).contains("preferred_name") - assertThat(individual.residence()) - .contains( - Location.builder() - .city("city") - .country("country") - .line1("line1") - .line2("line2") - .name("name") - .postalCode("postal_code") - .sourceId("source_id") - .state("state") - .build() + + val roundtrippedIndividual = + jsonMapper.readValue( + jsonMapper.writeValueAsString(individual), + jacksonTypeRef(), ) - assertThat(individual.ssn()).contains("ssn") + + assertThat(roundtrippedIndividual).isEqualTo(individual) + } + + @Test + fun ofBatchError() { + val batchError = + Individual.BatchError.builder() + .code(0.0) + .message("message") + .name("name") + .finchCode("finch_code") + .build() + + val individual = Individual.ofBatchError(batchError) + + assertThat(individual.unionMember0()).isEmpty + assertThat(individual.batchError()).contains(batchError) } @Test - fun roundtrip() { + fun ofBatchErrorRoundtrip() { val jsonMapper = jsonMapper() val individual = - Individual.builder() - .id("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - .dob("dob") - .addEmail( - Individual.Email.builder().data("data").type(Individual.Email.Type.WORK).build() - ) - .encryptedSsn("encrypted_ssn") - .ethnicity(Individual.Ethnicity.ASIAN) - .firstName("first_name") - .gender(Individual.Gender.FEMALE) - .lastName("last_name") - .middleName("middle_name") - .addPhoneNumber( - Individual.PhoneNumber.builder() - .data("data") - .type(Individual.PhoneNumber.Type.WORK) - .build() - ) - .preferredName("preferred_name") - .residence( - Location.builder() - .city("city") - .country("country") - .line1("line1") - .line2("line2") - .name("name") - .postalCode("postal_code") - .sourceId("source_id") - .state("state") - .build() - ) - .ssn("ssn") - .build() + Individual.ofBatchError( + Individual.BatchError.builder() + .code(0.0) + .message("message") + .name("name") + .finchCode("finch_code") + .build() + ) val roundtrippedIndividual = jsonMapper.readValue( @@ -129,4 +149,21 @@ internal class IndividualTest { assertThat(roundtrippedIndividual).isEqualTo(individual) } + + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { + BOOLEAN(JsonValue.from(false)), + STRING(JsonValue.from("invalid")), + INTEGER(JsonValue.from(-1)), + FLOAT(JsonValue.from(3.14)), + ARRAY(JsonValue.from(listOf("invalid", "array"))), + } + + @ParameterizedTest + @EnumSource + fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) { + val individual = jsonMapper().convertValue(testCase.value, jacksonTypeRef()) + + val e = assertThrows { individual.validate() } + assertThat(e).hasMessageStartingWith("Unknown ") + } } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualUpdateResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualUpdateResponseTest.kt index d61dcf48..94683bcd 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualUpdateResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/IndividualUpdateResponseTest.kt @@ -41,10 +41,10 @@ internal class IndividualUpdateResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .ssn("ssn") @@ -82,10 +82,10 @@ internal class IndividualUpdateResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) assertThat(individualUpdateResponse.ssn()).contains("ssn") @@ -123,10 +123,10 @@ internal class IndividualUpdateResponseTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .ssn("ssn") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/JobAutomatedCreateParamsTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/JobAutomatedCreateParamsTest.kt index 8221c7e1..05ceffa7 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/JobAutomatedCreateParamsTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/JobAutomatedCreateParamsTest.kt @@ -10,36 +10,16 @@ internal class JobAutomatedCreateParamsTest { @Test fun create() { - JobAutomatedCreateParams.builder() - .body( - JobAutomatedCreateParams.Body.DataSyncAll.builder() - .type(JobAutomatedCreateParams.Body.DataSyncAll.Type.DATA_SYNC_ALL) - .build() - ) - .build() + JobAutomatedCreateParams.builder().bodyDataSyncAll().build() } @Test fun body() { - val params = - JobAutomatedCreateParams.builder() - .body( - JobAutomatedCreateParams.Body.DataSyncAll.builder() - .type(JobAutomatedCreateParams.Body.DataSyncAll.Type.DATA_SYNC_ALL) - .build() - ) - .build() + val params = JobAutomatedCreateParams.builder().bodyDataSyncAll().build() val body = params._body().getOrNull() - assertThat(body) - .isEqualTo( - JobAutomatedCreateParams.Body.ofDataSyncAll( - JobAutomatedCreateParams.Body.DataSyncAll.builder() - .type(JobAutomatedCreateParams.Body.DataSyncAll.Type.DATA_SYNC_ALL) - .build() - ) - ) + assertThat(body).isEqualTo(JobAutomatedCreateParams.Body.ofDataSyncAll()) } @Test diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/LocationTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/LocationTest.kt index 8dc6ed3d..7bdf33e7 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/LocationTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/LocationTest.kt @@ -17,20 +17,20 @@ internal class LocationTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() assertThat(location.city()).contains("city") assertThat(location.country()).contains("country") assertThat(location.line1()).contains("line1") assertThat(location.line2()).contains("line2") - assertThat(location.name()).contains("name") assertThat(location.postalCode()).contains("postal_code") - assertThat(location.sourceId()).contains("source_id") assertThat(location.state()).contains("state") + assertThat(location.name()).contains("name") + assertThat(location.sourceId()).contains("source_id") } @Test @@ -42,10 +42,10 @@ internal class LocationTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() val roundtrippedLocation = diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PagingTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PagingTest.kt index 0e455120..05e2b6ab 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PagingTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PagingTest.kt @@ -11,16 +11,16 @@ internal class PagingTest { @Test fun create() { - val paging = Paging.builder().count(0L).offset(0L).build() + val paging = Paging.builder().offset(0L).count(0L).build() + assertThat(paging.offset()).isEqualTo(0L) assertThat(paging.count()).contains(0L) - assertThat(paging.offset()).contains(0L) } @Test fun roundtrip() { val jsonMapper = jsonMapper() - val paging = Paging.builder().count(0L).offset(0L).build() + val paging = Paging.builder().offset(0L).count(0L).build() val roundtrippedPaging = jsonMapper.readValue(jsonMapper.writeValueAsString(paging), jacksonTypeRef()) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementResponseBodyTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementResponseBodyTest.kt index 1d1cb6f1..40b61151 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementResponseBodyTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementResponseBodyTest.kt @@ -15,7 +15,7 @@ internal class PayStatementResponseBodyTest { fun create() { val payStatementResponseBody = PayStatementResponseBody.builder() - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( @@ -31,7 +31,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -60,7 +60,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -89,7 +89,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -119,7 +119,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -140,7 +140,7 @@ internal class PayStatementResponseBodyTest { .build() assertThat(payStatementResponseBody.paging()) - .contains(Paging.builder().count(0L).offset(0L).build()) + .contains(Paging.builder().offset(0L).count(0L).build()) assertThat(payStatementResponseBody.payStatements().getOrNull()) .containsExactly( PayStatement.builder() @@ -157,7 +157,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -184,7 +184,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -213,7 +213,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -242,7 +242,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -267,7 +267,7 @@ internal class PayStatementResponseBodyTest { val jsonMapper = jsonMapper() val payStatementResponseBody = PayStatementResponseBody.builder() - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( @@ -283,7 +283,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -312,7 +312,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -341,7 +341,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -371,7 +371,7 @@ internal class PayStatementResponseBodyTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementResponseTest.kt index 7eaf287b..b436711a 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementResponseTest.kt @@ -16,7 +16,7 @@ internal class PayStatementResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( @@ -33,7 +33,9 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -64,7 +66,9 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -95,7 +99,9 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -125,7 +131,9 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -152,7 +160,7 @@ internal class PayStatementResponseTest { assertThat(payStatementResponse.body()) .contains( PayStatementResponseBody.builder() - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( @@ -168,7 +176,7 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -197,7 +205,7 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -227,7 +235,7 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -257,7 +265,7 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -288,7 +296,7 @@ internal class PayStatementResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging(Paging.builder().count(0L).offset(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( @@ -305,7 +313,9 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -336,7 +346,9 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -367,7 +379,9 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) @@ -397,7 +411,9 @@ internal class PayStatementResponseTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from( + mapOf() + ), ) .build() ) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementTest.kt index db400830..3724bb43 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementTest.kt @@ -25,7 +25,10 @@ internal class PayStatementTest { .metadata( PayStatement.Earning.Attributes.Metadata.InnerMetadata .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() @@ -49,7 +52,10 @@ internal class PayStatementTest { PayStatement.EmployeeDeduction.Attributes.Metadata .InnerMetadata .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() @@ -73,7 +79,10 @@ internal class PayStatementTest { PayStatement.EmployerContribution.Attributes.Metadata .InnerMetadata .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() @@ -99,7 +108,10 @@ internal class PayStatementTest { .metadata( PayStatement.Tax.Attributes.Metadata.InnerMetadata .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() @@ -127,7 +139,10 @@ internal class PayStatementTest { .metadata( PayStatement.Earning.Attributes.Metadata.InnerMetadata .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() @@ -152,7 +167,10 @@ internal class PayStatementTest { PayStatement.EmployeeDeduction.Attributes.Metadata .InnerMetadata .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() @@ -177,7 +195,10 @@ internal class PayStatementTest { PayStatement.EmployerContribution.Attributes.Metadata .InnerMetadata .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() @@ -205,7 +226,10 @@ internal class PayStatementTest { PayStatement.Tax.Attributes.Metadata.builder() .metadata( PayStatement.Tax.Attributes.Metadata.InnerMetadata.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() @@ -237,7 +261,10 @@ internal class PayStatementTest { .metadata( PayStatement.Earning.Attributes.Metadata.InnerMetadata .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() @@ -261,7 +288,10 @@ internal class PayStatementTest { PayStatement.EmployeeDeduction.Attributes.Metadata .InnerMetadata .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() @@ -285,7 +315,10 @@ internal class PayStatementTest { PayStatement.EmployerContribution.Attributes.Metadata .InnerMetadata .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() @@ -311,7 +344,10 @@ internal class PayStatementTest { .metadata( PayStatement.Tax.Attributes.Metadata.InnerMetadata .builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf()), + ) .build() ) .build() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxCompanyUpdateParamsTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxCompanyUpdateParamsTest.kt index 149dc4c6..317789e9 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxCompanyUpdateParamsTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxCompanyUpdateParamsTest.kt @@ -42,10 +42,10 @@ internal class SandboxCompanyUpdateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .primaryEmail("dev@stainless.com") @@ -90,10 +90,10 @@ internal class SandboxCompanyUpdateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .primaryEmail("dev@stainless.com") @@ -137,10 +137,10 @@ internal class SandboxCompanyUpdateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) assertThat(body.primaryEmail()).contains("dev@stainless.com") @@ -156,7 +156,16 @@ internal class SandboxCompanyUpdateParamsTest { .ein("ein") .entity(SandboxCompanyUpdateParams.Entity.builder().build()) .legalName("legal_name") - .addLocation(Location.builder().build()) + .addLocation( + Location.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) .primaryEmail("dev@stainless.com") .primaryPhoneNumber("primary_phone_number") .build() @@ -170,7 +179,17 @@ internal class SandboxCompanyUpdateParamsTest { assertThat(body.ein()).contains("ein") assertThat(body.entity()).contains(SandboxCompanyUpdateParams.Entity.builder().build()) assertThat(body.legalName()).contains("legal_name") - assertThat(body.locations().getOrNull()).containsExactly(Location.builder().build()) + assertThat(body.locations().getOrNull()) + .containsExactly( + Location.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) assertThat(body.primaryEmail()).contains("dev@stainless.com") assertThat(body.primaryPhoneNumber()).contains("primary_phone_number") } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxDirectoryCreateParamsTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxDirectoryCreateParamsTest.kt index b054e2fd..2cabe240 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxDirectoryCreateParamsTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxDirectoryCreateParamsTest.kt @@ -81,10 +81,10 @@ internal class SandboxDirectoryCreateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( @@ -109,10 +109,10 @@ internal class SandboxDirectoryCreateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .sourceId("source_id") @@ -203,10 +203,10 @@ internal class SandboxDirectoryCreateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( @@ -233,10 +233,10 @@ internal class SandboxDirectoryCreateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .sourceId("source_id") @@ -319,10 +319,10 @@ internal class SandboxDirectoryCreateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( @@ -347,10 +347,10 @@ internal class SandboxDirectoryCreateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .sourceId("source_id") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParamsTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParamsTest.kt index fbe2b905..5a5f9fab 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParamsTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParamsTest.kt @@ -55,10 +55,10 @@ internal class SandboxEmploymentUpdateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( @@ -129,10 +129,10 @@ internal class SandboxEmploymentUpdateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( @@ -197,10 +197,10 @@ internal class SandboxEmploymentUpdateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) assertThat(body.manager()) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParamsTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParamsTest.kt index 65df3b36..f1846ca4 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParamsTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParamsTest.kt @@ -38,10 +38,10 @@ internal class SandboxIndividualUpdateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .ssn("ssn") @@ -88,10 +88,10 @@ internal class SandboxIndividualUpdateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .ssn("ssn") @@ -128,10 +128,10 @@ internal class SandboxIndividualUpdateParamsTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) assertThat(body.ssn()).contains("ssn") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParamsTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParamsTest.kt index 68ea6c51..0f9cfcf9 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParamsTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParamsTest.kt @@ -32,7 +32,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -66,7 +66,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -101,7 +101,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -135,7 +135,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -183,7 +183,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -219,7 +219,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -255,7 +255,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -289,7 +289,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -333,7 +333,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -367,7 +367,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -402,7 +402,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -436,7 +436,7 @@ internal class SandboxPaymentCreateParamsTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncTest.kt index 93d19f5a..861af561 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncTest.kt @@ -27,6 +27,20 @@ internal class BenefitServiceAsyncTest { val createCompanyBenefitsResponseFuture = benefitServiceAsync.create( HrisBenefitCreateParams.builder() + .companyContribution( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.builder() + .addTier( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.Tier + .builder() + .match(1L) + .threshold(1L) + .build() + ) + .type( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.Type.MATCH + ) + .build() + ) .description("description") .frequency(BenefitFrequency.ONE_TIME) .type(BenefitType._401K) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncTest.kt index 8eea4c25..ac39efe6 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncTest.kt @@ -24,13 +24,7 @@ internal class AutomatedServiceAsyncTest { val automatedFuture = automatedServiceAsync.create( - JobAutomatedCreateParams.builder() - .body( - JobAutomatedCreateParams.Body.DataSyncAll.builder() - .type(JobAutomatedCreateParams.Body.DataSyncAll.Type.DATA_SYNC_ALL) - .build() - ) - .build() + JobAutomatedCreateParams.builder().bodyDataSyncAll().build() ) val automated = automatedFuture.get() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/CompanyServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/CompanyServiceAsyncTest.kt index 644fb0d1..91075126 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/CompanyServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/CompanyServiceAsyncTest.kt @@ -57,10 +57,10 @@ internal class CompanyServiceAsyncTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .primaryEmail("dev@stainless.com") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/DirectoryServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/DirectoryServiceAsyncTest.kt index 5572fa2d..ce338d43 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/DirectoryServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/DirectoryServiceAsyncTest.kt @@ -108,10 +108,10 @@ internal class DirectoryServiceAsyncTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( @@ -140,10 +140,10 @@ internal class DirectoryServiceAsyncTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .sourceId("source_id") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncTest.kt index e85386fd..8db4951b 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncTest.kt @@ -71,10 +71,10 @@ internal class EmploymentServiceAsyncTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncTest.kt index 7f489dbe..5ae62990 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncTest.kt @@ -51,10 +51,10 @@ internal class IndividualServiceAsyncTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .ssn("ssn") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/PaymentServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/PaymentServiceAsyncTest.kt index 1faf4d8a..fc235e7b 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/PaymentServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/sandbox/PaymentServiceAsyncTest.kt @@ -49,7 +49,7 @@ internal class PaymentServiceAsyncTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -87,7 +87,7 @@ internal class PaymentServiceAsyncTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -124,7 +124,7 @@ internal class PaymentServiceAsyncTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -162,7 +162,7 @@ internal class PaymentServiceAsyncTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceTest.kt index f04e7929..bdcc2d7f 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceTest.kt @@ -27,6 +27,20 @@ internal class BenefitServiceTest { val createCompanyBenefitsResponse = benefitService.create( HrisBenefitCreateParams.builder() + .companyContribution( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.builder() + .addTier( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.Tier + .builder() + .match(1L) + .threshold(1L) + .build() + ) + .type( + HrisBenefitCreateParams.BenefitCompanyMatchContribution.Type.MATCH + ) + .build() + ) .description("description") .frequency(BenefitFrequency.ONE_TIME) .type(BenefitType._401K) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceTest.kt index 226173ab..e6ff60ac 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceTest.kt @@ -23,15 +23,7 @@ internal class AutomatedServiceTest { val automatedService = client.jobs().automated() val automated = - automatedService.create( - JobAutomatedCreateParams.builder() - .body( - JobAutomatedCreateParams.Body.DataSyncAll.builder() - .type(JobAutomatedCreateParams.Body.DataSyncAll.Type.DATA_SYNC_ALL) - .build() - ) - .build() - ) + automatedService.create(JobAutomatedCreateParams.builder().bodyDataSyncAll().build()) automated.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/CompanyServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/CompanyServiceTest.kt index 092485b9..8212b1f9 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/CompanyServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/CompanyServiceTest.kt @@ -57,10 +57,10 @@ internal class CompanyServiceTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .primaryEmail("dev@stainless.com") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/DirectoryServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/DirectoryServiceTest.kt index dc3d0a26..2e1068ba 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/DirectoryServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/DirectoryServiceTest.kt @@ -108,10 +108,10 @@ internal class DirectoryServiceTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( @@ -140,10 +140,10 @@ internal class DirectoryServiceTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .sourceId("source_id") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceTest.kt index a14004ae..c372d897 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceTest.kt @@ -71,10 +71,10 @@ internal class EmploymentServiceTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .manager( diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceTest.kt index d4138d0c..2c097a2e 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceTest.kt @@ -51,10 +51,10 @@ internal class IndividualServiceTest { .country("country") .line1("line1") .line2("line2") - .name("name") .postalCode("postal_code") - .sourceId("source_id") .state("state") + .name("name") + .sourceId("source_id") .build() ) .ssn("ssn") diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/PaymentServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/PaymentServiceTest.kt index 3d67e68e..1a8dba8b 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/PaymentServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/sandbox/PaymentServiceTest.kt @@ -49,7 +49,7 @@ internal class PaymentServiceTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -87,7 +87,7 @@ internal class PaymentServiceTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -124,7 +124,7 @@ internal class PaymentServiceTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() ) @@ -162,7 +162,7 @@ internal class PaymentServiceTest { .builder() .putAdditionalProperty( "foo", - JsonValue.from("bar"), + JsonValue.from(mapOf()), ) .build() )