From ec6fa40e9be337318708f336e853b3f9e551dd47 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 8 May 2025 22:09:22 +0000 Subject: [PATCH 1/6] feat(client): allow providing some params positionally --- .../kotlin/com/tryfinch/api/core/Check.kt | 3 + .../HrisBenefitIndividualEnrolledIdsParams.kt | 30 +-- ...fitIndividualRetrieveManyBenefitsParams.kt | 28 +-- ...HrisBenefitIndividualUnenrollManyParams.kt | 28 +-- .../api/models/HrisBenefitRetrieveParams.kt | 30 +-- .../api/models/HrisBenefitUpdateParams.kt | 33 +-- ...CompanyPayStatementItemRuleDeleteParams.kt | 29 +-- ...CompanyPayStatementItemRuleUpdateParams.kt | 30 +-- .../api/models/HrisDocumentRetreiveParams.kt | 30 +-- .../api/models/JobAutomatedRetrieveParams.kt | 30 +-- .../api/models/JobManualRetrieveParams.kt | 38 ++- .../models/PayrollPayGroupRetrieveParams.kt | 30 +-- .../models/SandboxEmploymentUpdateParams.kt | 28 +-- .../models/SandboxIndividualUpdateParams.kt | 28 +-- .../async/hris/BenefitServiceAsync.kt | 129 +++++++++- .../async/hris/BenefitServiceAsyncImpl.kt | 8 + .../async/hris/DocumentServiceAsync.kt | 66 +++++- .../async/hris/DocumentServiceAsyncImpl.kt | 5 + .../hris/benefits/IndividualServiceAsync.kt | 220 +++++++++++++++++- .../benefits/IndividualServiceAsyncImpl.kt | 11 + .../payStatementItem/RuleServiceAsync.kt | 134 ++++++++++- .../payStatementItem/RuleServiceAsyncImpl.kt | 8 + .../async/jobs/AutomatedServiceAsync.kt | 63 ++++- .../async/jobs/AutomatedServiceAsyncImpl.kt | 5 + .../services/async/jobs/ManualServiceAsync.kt | 60 ++++- .../async/jobs/ManualServiceAsyncImpl.kt | 5 + .../async/payroll/PayGroupServiceAsync.kt | 66 +++++- .../async/payroll/PayGroupServiceAsyncImpl.kt | 5 + .../async/sandbox/EmploymentServiceAsync.kt | 66 +++++- .../sandbox/EmploymentServiceAsyncImpl.kt | 5 + .../async/sandbox/IndividualServiceAsync.kt | 66 +++++- .../sandbox/IndividualServiceAsyncImpl.kt | 5 + .../services/blocking/hris/BenefitService.kt | 118 +++++++++- .../blocking/hris/BenefitServiceImpl.kt | 8 + .../services/blocking/hris/DocumentService.kt | 60 ++++- .../blocking/hris/DocumentServiceImpl.kt | 5 + .../hris/benefits/IndividualService.kt | 212 ++++++++++++++++- .../hris/benefits/IndividualServiceImpl.kt | 11 + .../company/payStatementItem/RuleService.kt | 124 +++++++++- .../payStatementItem/RuleServiceImpl.kt | 8 + .../blocking/jobs/AutomatedService.kt | 58 ++++- .../blocking/jobs/AutomatedServiceImpl.kt | 5 + .../services/blocking/jobs/ManualService.kt | 57 ++++- .../blocking/jobs/ManualServiceImpl.kt | 5 + .../blocking/payroll/PayGroupService.kt | 60 ++++- .../blocking/payroll/PayGroupServiceImpl.kt | 5 + .../blocking/sandbox/EmploymentService.kt | 60 ++++- .../blocking/sandbox/EmploymentServiceImpl.kt | 5 + .../blocking/sandbox/IndividualService.kt | 60 ++++- .../blocking/sandbox/IndividualServiceImpl.kt | 5 + .../async/hris/BenefitServiceAsyncTest.kt | 6 +- .../async/hris/DocumentServiceAsyncTest.kt | 6 +- .../benefits/IndividualServiceAsyncTest.kt | 14 +- .../payStatementItem/RuleServiceAsyncTest.kt | 6 +- .../async/jobs/AutomatedServiceAsyncTest.kt | 6 +- .../async/jobs/ManualServiceAsyncTest.kt | 4 +- .../async/payroll/PayGroupServiceAsyncTest.kt | 6 +- .../blocking/hris/BenefitServiceTest.kt | 6 +- .../blocking/hris/DocumentServiceTest.kt | 6 +- .../hris/benefits/IndividualServiceTest.kt | 14 +- .../payStatementItem/RuleServiceTest.kt | 6 +- .../blocking/jobs/AutomatedServiceTest.kt | 4 +- .../blocking/jobs/ManualServiceTest.kt | 4 +- .../blocking/payroll/PayGroupServiceTest.kt | 6 +- 64 files changed, 1856 insertions(+), 426 deletions(-) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Check.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Check.kt index b228e69d..817890bb 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Check.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Check.kt @@ -5,6 +5,9 @@ package com.tryfinch.api.core import com.fasterxml.jackson.core.Version import com.fasterxml.jackson.core.util.VersionUtil +fun checkRequired(name: String, condition: Boolean) = + check(condition) { "`$name` is required, but was not set" } + fun checkRequired(name: String, value: T?): T = checkNotNull(value) { "`$name` is required, but was not set" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualEnrolledIdsParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualEnrolledIdsParams.kt index ed8fb88a..bdd47916 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualEnrolledIdsParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualEnrolledIdsParams.kt @@ -3,20 +3,21 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Lists individuals currently enrolled in a given deduction. */ class HrisBenefitIndividualEnrolledIdsParams private constructor( - private val benefitId: String, + private val benefitId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun benefitId(): String = benefitId + fun benefitId(): Optional = Optional.ofNullable(benefitId) fun _additionalHeaders(): Headers = additionalHeaders @@ -26,14 +27,11 @@ private constructor( companion object { + @JvmStatic fun none(): HrisBenefitIndividualEnrolledIdsParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [HrisBenefitIndividualEnrolledIdsParams]. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -55,7 +53,10 @@ private constructor( hrisBenefitIndividualEnrolledIdsParams.additionalQueryParams.toBuilder() } - fun benefitId(benefitId: String) = apply { this.benefitId = benefitId } + fun benefitId(benefitId: String?) = apply { this.benefitId = benefitId } + + /** Alias for calling [Builder.benefitId] with `benefitId.orElse(null)`. */ + fun benefitId(benefitId: Optional) = benefitId(benefitId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -159,17 +160,10 @@ private constructor( * Returns an immutable instance of [HrisBenefitIndividualEnrolledIdsParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisBenefitIndividualEnrolledIdsParams = HrisBenefitIndividualEnrolledIdsParams( - checkRequired("benefitId", benefitId), + benefitId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -177,7 +171,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> benefitId + 0 -> benefitId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsParams.kt index dd2e70a8..7c6e196e 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsParams.kt @@ -3,7 +3,6 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects @@ -13,13 +12,13 @@ import kotlin.jvm.optionals.getOrNull /** Get enrollment information for the given individuals. */ class HrisBenefitIndividualRetrieveManyBenefitsParams private constructor( - private val benefitId: String, + private val benefitId: String?, private val individualIds: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun benefitId(): String = benefitId + fun benefitId(): Optional = Optional.ofNullable(benefitId) /** * comma-delimited list of stable Finch uuids for each individual. If empty, defaults to all @@ -35,14 +34,11 @@ private constructor( companion object { + @JvmStatic fun none(): HrisBenefitIndividualRetrieveManyBenefitsParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [HrisBenefitIndividualRetrieveManyBenefitsParams]. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -68,7 +64,10 @@ private constructor( hrisBenefitIndividualRetrieveManyBenefitsParams.additionalQueryParams.toBuilder() } - fun benefitId(benefitId: String) = apply { this.benefitId = benefitId } + fun benefitId(benefitId: String?) = apply { this.benefitId = benefitId } + + /** Alias for calling [Builder.benefitId] with `benefitId.orElse(null)`. */ + fun benefitId(benefitId: Optional) = benefitId(benefitId.getOrNull()) /** * comma-delimited list of stable Finch uuids for each individual. If empty, defaults to all @@ -182,17 +181,10 @@ private constructor( * Returns an immutable instance of [HrisBenefitIndividualRetrieveManyBenefitsParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisBenefitIndividualRetrieveManyBenefitsParams = HrisBenefitIndividualRetrieveManyBenefitsParams( - checkRequired("benefitId", benefitId), + benefitId, individualIds, additionalHeaders.build(), additionalQueryParams.build(), @@ -201,7 +193,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> benefitId + 0 -> benefitId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualUnenrollManyParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualUnenrollManyParams.kt index da3f66cd..45431317 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualUnenrollManyParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualUnenrollManyParams.kt @@ -12,7 +12,6 @@ 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.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.core.toImmutable @@ -25,13 +24,13 @@ import kotlin.jvm.optionals.getOrNull /** Unenroll individuals from a deduction or contribution */ class HrisBenefitIndividualUnenrollManyParams private constructor( - private val benefitId: String, + private val benefitId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun benefitId(): String = benefitId + fun benefitId(): Optional = Optional.ofNullable(benefitId) /** * Array of individual_ids to unenroll. @@ -58,14 +57,11 @@ private constructor( companion object { + @JvmStatic fun none(): HrisBenefitIndividualUnenrollManyParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [HrisBenefitIndividualUnenrollManyParams]. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -90,7 +86,10 @@ private constructor( hrisBenefitIndividualUnenrollManyParams.additionalQueryParams.toBuilder() } - fun benefitId(benefitId: String) = apply { this.benefitId = benefitId } + fun benefitId(benefitId: String?) = apply { this.benefitId = benefitId } + + /** Alias for calling [Builder.benefitId] with `benefitId.orElse(null)`. */ + fun benefitId(benefitId: Optional) = benefitId(benefitId.getOrNull()) /** * Sets the entire request body. @@ -243,17 +242,10 @@ private constructor( * Returns an immutable instance of [HrisBenefitIndividualUnenrollManyParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisBenefitIndividualUnenrollManyParams = HrisBenefitIndividualUnenrollManyParams( - checkRequired("benefitId", benefitId), + benefitId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -264,7 +256,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> benefitId + 0 -> benefitId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitRetrieveParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitRetrieveParams.kt index 0167113d..c6fa8c33 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitRetrieveParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitRetrieveParams.kt @@ -3,20 +3,21 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Lists deductions and contributions information for a given item */ class HrisBenefitRetrieveParams private constructor( - private val benefitId: String, + private val benefitId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun benefitId(): String = benefitId + fun benefitId(): Optional = Optional.ofNullable(benefitId) fun _additionalHeaders(): Headers = additionalHeaders @@ -26,13 +27,10 @@ private constructor( companion object { + @JvmStatic fun none(): HrisBenefitRetrieveParams = builder().build() + /** * Returns a mutable builder for constructing an instance of [HrisBenefitRetrieveParams]. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -51,7 +49,10 @@ private constructor( additionalQueryParams = hrisBenefitRetrieveParams.additionalQueryParams.toBuilder() } - fun benefitId(benefitId: String) = apply { this.benefitId = benefitId } + fun benefitId(benefitId: String?) = apply { this.benefitId = benefitId } + + /** Alias for calling [Builder.benefitId] with `benefitId.orElse(null)`. */ + fun benefitId(benefitId: Optional) = benefitId(benefitId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -155,17 +156,10 @@ private constructor( * Returns an immutable instance of [HrisBenefitRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisBenefitRetrieveParams = HrisBenefitRetrieveParams( - checkRequired("benefitId", benefitId), + benefitId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -173,7 +167,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> benefitId + 0 -> benefitId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitUpdateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitUpdateParams.kt index 91bc5f13..90b691f3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitUpdateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitUpdateParams.kt @@ -11,24 +11,24 @@ 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.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Updates an existing company-wide deduction or contribution */ class HrisBenefitUpdateParams private constructor( - private val benefitId: String, + private val benefitId: String?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun benefitId(): String = benefitId + fun benefitId(): Optional = Optional.ofNullable(benefitId) /** * Updated name or description. @@ -55,14 +55,9 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [HrisBenefitUpdateParams]. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - */ + @JvmStatic fun none(): HrisBenefitUpdateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [HrisBenefitUpdateParams]. */ @JvmStatic fun builder() = Builder() } @@ -82,7 +77,10 @@ private constructor( additionalQueryParams = hrisBenefitUpdateParams.additionalQueryParams.toBuilder() } - fun benefitId(benefitId: String) = apply { this.benefitId = benefitId } + fun benefitId(benefitId: String?) = apply { this.benefitId = benefitId } + + /** Alias for calling [Builder.benefitId] with `benefitId.orElse(null)`. */ + fun benefitId(benefitId: Optional) = benefitId(benefitId.getOrNull()) /** * Sets the entire request body. @@ -226,17 +224,10 @@ private constructor( * Returns an immutable instance of [HrisBenefitUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .benefitId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisBenefitUpdateParams = HrisBenefitUpdateParams( - checkRequired("benefitId", benefitId), + benefitId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -247,7 +238,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> benefitId + 0 -> benefitId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleDeleteParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleDeleteParams.kt index a9f7f64d..1f47cbe2 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleDeleteParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleDeleteParams.kt @@ -4,12 +4,12 @@ package com.tryfinch.api.models import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.core.toImmutable import java.util.Objects import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical @@ -17,13 +17,13 @@ import java.util.Optional */ class HrisCompanyPayStatementItemRuleDeleteParams private constructor( - private val ruleId: String, + private val ruleId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) : Params { - fun ruleId(): String = ruleId + fun ruleId(): Optional = Optional.ofNullable(ruleId) fun _additionalBodyProperties(): Map = additionalBodyProperties @@ -35,14 +35,11 @@ private constructor( companion object { + @JvmStatic fun none(): HrisCompanyPayStatementItemRuleDeleteParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [HrisCompanyPayStatementItemRuleDeleteParams]. - * - * The following fields are required: - * ```java - * .ruleId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -68,7 +65,10 @@ private constructor( hrisCompanyPayStatementItemRuleDeleteParams.additionalBodyProperties.toMutableMap() } - fun ruleId(ruleId: String) = apply { this.ruleId = ruleId } + fun ruleId(ruleId: String?) = apply { this.ruleId = ruleId } + + /** Alias for calling [Builder.ruleId] with `ruleId.orElse(null)`. */ + fun ruleId(ruleId: Optional) = ruleId(ruleId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -194,17 +194,10 @@ private constructor( * Returns an immutable instance of [HrisCompanyPayStatementItemRuleDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .ruleId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisCompanyPayStatementItemRuleDeleteParams = HrisCompanyPayStatementItemRuleDeleteParams( - checkRequired("ruleId", ruleId), + ruleId, additionalHeaders.build(), additionalQueryParams.build(), additionalBodyProperties.toImmutable(), @@ -216,7 +209,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> ruleId + 0 -> ruleId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleUpdateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleUpdateParams.kt index 0ec80b82..e509e8bf 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleUpdateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleUpdateParams.kt @@ -10,12 +10,13 @@ import com.tryfinch.api.core.ExcludeMissing import com.tryfinch.api.core.JsonMissing import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical @@ -23,13 +24,13 @@ import java.util.Objects */ class HrisCompanyPayStatementItemRuleUpdateParams private constructor( - private val ruleId: String, + private val ruleId: String?, private val body: UpdateRuleRequest, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun ruleId(): String = ruleId + fun ruleId(): Optional = Optional.ofNullable(ruleId) fun _optionalProperty(): JsonValue = body._optionalProperty() @@ -43,14 +44,11 @@ private constructor( companion object { + @JvmStatic fun none(): HrisCompanyPayStatementItemRuleUpdateParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [HrisCompanyPayStatementItemRuleUpdateParams]. - * - * The following fields are required: - * ```java - * .ruleId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -75,7 +73,10 @@ private constructor( hrisCompanyPayStatementItemRuleUpdateParams.additionalQueryParams.toBuilder() } - fun ruleId(ruleId: String) = apply { this.ruleId = ruleId } + fun ruleId(ruleId: String?) = apply { this.ruleId = ruleId } + + /** Alias for calling [Builder.ruleId] with `ruleId.orElse(null)`. */ + fun ruleId(ruleId: Optional) = ruleId(ruleId.getOrNull()) /** * Sets the entire request body. @@ -211,17 +212,10 @@ private constructor( * Returns an immutable instance of [HrisCompanyPayStatementItemRuleUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .ruleId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisCompanyPayStatementItemRuleUpdateParams = HrisCompanyPayStatementItemRuleUpdateParams( - checkRequired("ruleId", ruleId), + ruleId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -232,7 +226,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> ruleId + 0 -> ruleId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDocumentRetreiveParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDocumentRetreiveParams.kt index 5de75843..c0d046d1 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDocumentRetreiveParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDocumentRetreiveParams.kt @@ -3,10 +3,11 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** * **Beta:** This endpoint is in beta and may change. Retrieve details of a specific document by its @@ -14,12 +15,12 @@ import java.util.Objects */ class HrisDocumentRetreiveParams private constructor( - private val documentId: String, + private val documentId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun documentId(): String = documentId + fun documentId(): Optional = Optional.ofNullable(documentId) fun _additionalHeaders(): Headers = additionalHeaders @@ -29,13 +30,10 @@ private constructor( companion object { + @JvmStatic fun none(): HrisDocumentRetreiveParams = builder().build() + /** * Returns a mutable builder for constructing an instance of [HrisDocumentRetreiveParams]. - * - * The following fields are required: - * ```java - * .documentId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -54,7 +52,10 @@ private constructor( additionalQueryParams = hrisDocumentRetreiveParams.additionalQueryParams.toBuilder() } - fun documentId(documentId: String) = apply { this.documentId = documentId } + fun documentId(documentId: String?) = apply { this.documentId = documentId } + + /** Alias for calling [Builder.documentId] with `documentId.orElse(null)`. */ + fun documentId(documentId: Optional) = documentId(documentId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -158,17 +159,10 @@ private constructor( * Returns an immutable instance of [HrisDocumentRetreiveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .documentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): HrisDocumentRetreiveParams = HrisDocumentRetreiveParams( - checkRequired("documentId", documentId), + documentId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -176,7 +170,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> documentId + 0 -> documentId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedRetrieveParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedRetrieveParams.kt index ac519b49..220a5b3b 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedRetrieveParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobAutomatedRetrieveParams.kt @@ -3,20 +3,21 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Get an automated job by `job_id`. */ class JobAutomatedRetrieveParams private constructor( - private val jobId: String, + private val jobId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun jobId(): String = jobId + fun jobId(): Optional = Optional.ofNullable(jobId) fun _additionalHeaders(): Headers = additionalHeaders @@ -26,13 +27,10 @@ private constructor( companion object { + @JvmStatic fun none(): JobAutomatedRetrieveParams = builder().build() + /** * Returns a mutable builder for constructing an instance of [JobAutomatedRetrieveParams]. - * - * The following fields are required: - * ```java - * .jobId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -51,7 +49,10 @@ private constructor( additionalQueryParams = jobAutomatedRetrieveParams.additionalQueryParams.toBuilder() } - fun jobId(jobId: String) = apply { this.jobId = jobId } + fun jobId(jobId: String?) = apply { this.jobId = jobId } + + /** Alias for calling [Builder.jobId] with `jobId.orElse(null)`. */ + fun jobId(jobId: Optional) = jobId(jobId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -155,17 +156,10 @@ private constructor( * Returns an immutable instance of [JobAutomatedRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .jobId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): JobAutomatedRetrieveParams = JobAutomatedRetrieveParams( - checkRequired("jobId", jobId), + jobId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -173,7 +167,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> jobId + 0 -> jobId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobManualRetrieveParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobManualRetrieveParams.kt index a1833b8c..0ec08bb9 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobManualRetrieveParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/JobManualRetrieveParams.kt @@ -3,10 +3,11 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** * Get a manual job by `job_id`. Manual jobs are completed by a human and include Assisted Benefits @@ -14,12 +15,12 @@ import java.util.Objects */ class JobManualRetrieveParams private constructor( - private val jobId: String, + private val jobId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun jobId(): String = jobId + fun jobId(): Optional = Optional.ofNullable(jobId) fun _additionalHeaders(): Headers = additionalHeaders @@ -29,14 +30,9 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [JobManualRetrieveParams]. - * - * The following fields are required: - * ```java - * .jobId() - * ``` - */ + @JvmStatic fun none(): JobManualRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [JobManualRetrieveParams]. */ @JvmStatic fun builder() = Builder() } @@ -54,7 +50,10 @@ private constructor( additionalQueryParams = jobManualRetrieveParams.additionalQueryParams.toBuilder() } - fun jobId(jobId: String) = apply { this.jobId = jobId } + fun jobId(jobId: String?) = apply { this.jobId = jobId } + + /** Alias for calling [Builder.jobId] with `jobId.orElse(null)`. */ + fun jobId(jobId: Optional) = jobId(jobId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -158,25 +157,14 @@ private constructor( * Returns an immutable instance of [JobManualRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .jobId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): JobManualRetrieveParams = - JobManualRetrieveParams( - checkRequired("jobId", jobId), - additionalHeaders.build(), - additionalQueryParams.build(), - ) + JobManualRetrieveParams(jobId, additionalHeaders.build(), additionalQueryParams.build()) } fun _pathParam(index: Int): String = when (index) { - 0 -> jobId + 0 -> jobId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupRetrieveParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupRetrieveParams.kt index 129a9287..f64580b6 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupRetrieveParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupRetrieveParams.kt @@ -3,20 +3,21 @@ package com.tryfinch.api.models import com.tryfinch.api.core.Params -import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull /** Read information from a single pay group */ class PayrollPayGroupRetrieveParams private constructor( - private val payGroupId: String, + private val payGroupId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun payGroupId(): String = payGroupId + fun payGroupId(): Optional = Optional.ofNullable(payGroupId) fun _additionalHeaders(): Headers = additionalHeaders @@ -26,14 +27,11 @@ private constructor( companion object { + @JvmStatic fun none(): PayrollPayGroupRetrieveParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [PayrollPayGroupRetrieveParams]. - * - * The following fields are required: - * ```java - * .payGroupId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -52,7 +50,10 @@ private constructor( additionalQueryParams = payrollPayGroupRetrieveParams.additionalQueryParams.toBuilder() } - fun payGroupId(payGroupId: String) = apply { this.payGroupId = payGroupId } + fun payGroupId(payGroupId: String?) = apply { this.payGroupId = payGroupId } + + /** Alias for calling [Builder.payGroupId] with `payGroupId.orElse(null)`. */ + fun payGroupId(payGroupId: Optional) = payGroupId(payGroupId.getOrNull()) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -156,17 +157,10 @@ private constructor( * Returns an immutable instance of [PayrollPayGroupRetrieveParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .payGroupId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams( - checkRequired("payGroupId", payGroupId), + payGroupId, additionalHeaders.build(), additionalQueryParams.build(), ) @@ -174,7 +168,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> payGroupId + 0 -> payGroupId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParams.kt index ef2be056..ce9ed3e1 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxEmploymentUpdateParams.kt @@ -13,7 +13,6 @@ 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.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.core.toImmutable @@ -26,13 +25,13 @@ import kotlin.jvm.optionals.getOrNull /** Update sandbox employment */ class SandboxEmploymentUpdateParams private constructor( - private val individualId: String, + private val individualId: String?, private val body: EmploymentWithoutId, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun individualId(): String = individualId + fun individualId(): Optional = Optional.ofNullable(individualId) /** * Worker's compensation classification code for this employee @@ -311,14 +310,11 @@ private constructor( companion object { + @JvmStatic fun none(): SandboxEmploymentUpdateParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [SandboxEmploymentUpdateParams]. - * - * The following fields are required: - * ```java - * .individualId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -339,7 +335,10 @@ private constructor( additionalQueryParams = sandboxEmploymentUpdateParams.additionalQueryParams.toBuilder() } - fun individualId(individualId: String) = apply { this.individualId = individualId } + fun individualId(individualId: String?) = apply { this.individualId = individualId } + + /** Alias for calling [Builder.individualId] with `individualId.orElse(null)`. */ + fun individualId(individualId: Optional) = individualId(individualId.getOrNull()) /** * Sets the entire request body. @@ -777,17 +776,10 @@ private constructor( * Returns an immutable instance of [SandboxEmploymentUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .individualId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams( - checkRequired("individualId", individualId), + individualId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -798,7 +790,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> individualId + 0 -> individualId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParams.kt index 8349ea86..7d886f90 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxIndividualUpdateParams.kt @@ -13,7 +13,6 @@ 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.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.core.toImmutable @@ -26,13 +25,13 @@ import kotlin.jvm.optionals.getOrNull /** Update sandbox individual */ class SandboxIndividualUpdateParams private constructor( - private val individualId: String, + private val individualId: String?, private val body: IndividualWithoutId, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { - fun individualId(): String = individualId + fun individualId(): Optional = Optional.ofNullable(individualId) /** * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -220,14 +219,11 @@ private constructor( companion object { + @JvmStatic fun none(): SandboxIndividualUpdateParams = builder().build() + /** * Returns a mutable builder for constructing an instance of * [SandboxIndividualUpdateParams]. - * - * The following fields are required: - * ```java - * .individualId() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -248,7 +244,10 @@ private constructor( additionalQueryParams = sandboxIndividualUpdateParams.additionalQueryParams.toBuilder() } - fun individualId(individualId: String) = apply { this.individualId = individualId } + fun individualId(individualId: String?) = apply { this.individualId = individualId } + + /** Alias for calling [Builder.individualId] with `individualId.orElse(null)`. */ + fun individualId(individualId: Optional) = individualId(individualId.getOrNull()) /** * Sets the entire request body. @@ -589,17 +588,10 @@ private constructor( * Returns an immutable instance of [SandboxIndividualUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .individualId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): SandboxIndividualUpdateParams = SandboxIndividualUpdateParams( - checkRequired("individualId", individualId), + individualId, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -610,7 +602,7 @@ private constructor( fun _pathParam(index: Int): String = when (index) { - 0 -> individualId + 0 -> individualId ?: "" else -> "" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsync.kt index 0ebd8f70..78490ed2 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsync.kt @@ -50,8 +50,22 @@ interface BenefitServiceAsync { create(HrisBenefitCreateParams.none(), requestOptions) /** Lists deductions and contributions information for a given item */ - fun retrieve(params: HrisBenefitRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(benefitId: String): CompletableFuture = + retrieve(benefitId, HrisBenefitRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + ): CompletableFuture = retrieve(benefitId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -59,9 +73,35 @@ interface BenefitServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retrieve] */ + fun retrieve(params: HrisBenefitRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(benefitId, HrisBenefitRetrieveParams.none(), requestOptions) + /** Updates an existing company-wide deduction or contribution */ - fun update(params: HrisBenefitUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(benefitId: String): CompletableFuture = + update(benefitId, HrisBenefitUpdateParams.none()) + + /** @see [update] */ + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [update] */ + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + ): CompletableFuture = + update(benefitId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -69,6 +109,17 @@ interface BenefitServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [update] */ + fun update(params: HrisBenefitUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(benefitId, HrisBenefitUpdateParams.none(), requestOptions) + /** List all company-wide deductions and contributions. */ fun list(): CompletableFuture = list(HrisBenefitListParams.none()) @@ -152,10 +203,25 @@ interface BenefitServiceAsync { * the same as [BenefitServiceAsync.retrieve]. */ @MustBeClosed + fun retrieve(benefitId: String): CompletableFuture> = + retrieve(benefitId, HrisBenefitRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed fun retrieve( - params: HrisBenefitRetrieveParams + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - retrieve(params, RequestOptions.none()) + retrieve(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + ): CompletableFuture> = + retrieve(benefitId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -164,15 +230,47 @@ interface BenefitServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + params: HrisBenefitRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(benefitId, HrisBenefitRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /employer/benefits/{benefit_id}`, but is otherwise * the same as [BenefitServiceAsync.update]. */ @MustBeClosed fun update( - params: HrisBenefitUpdateParams + benefitId: String ): CompletableFuture> = - update(params, RequestOptions.none()) + update(benefitId, HrisBenefitUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + ): CompletableFuture> = + update(benefitId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -181,6 +279,21 @@ interface BenefitServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [update] */ + @MustBeClosed + fun update( + params: HrisBenefitUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(benefitId, HrisBenefitUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/benefits`, but is otherwise the same as * [BenefitServiceAsync.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt index 3eefa17d..5f6007c2 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.hris import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -30,6 +31,7 @@ import com.tryfinch.api.services.async.hris.benefits.IndividualServiceAsync import com.tryfinch.api.services.async.hris.benefits.IndividualServiceAsyncImpl import java.util.Optional import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class BenefitServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : BenefitServiceAsync { @@ -130,6 +132,9 @@ class BenefitServiceAsyncImpl internal constructor(private val clientOptions: Cl params: HrisBenefitRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -160,6 +165,9 @@ class BenefitServiceAsyncImpl internal constructor(private val clientOptions: Cl params: HrisBenefitUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsync.kt index a25175a1..5688823e 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsync.kt @@ -42,8 +42,23 @@ interface DocumentServiceAsync { * **Beta:** This endpoint is in beta and may change. Retrieve details of a specific document by * its ID. */ - fun retreive(params: HrisDocumentRetreiveParams): CompletableFuture = - retreive(params, RequestOptions.none()) + fun retreive(documentId: String): CompletableFuture = + retreive(documentId, HrisDocumentRetreiveParams.none()) + + /** @see [retreive] */ + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retreive(params.toBuilder().documentId(documentId).build(), requestOptions) + + /** @see [retreive] */ + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + ): CompletableFuture = + retreive(documentId, params, RequestOptions.none()) /** @see [retreive] */ fun retreive( @@ -51,6 +66,17 @@ interface DocumentServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retreive] */ + fun retreive(params: HrisDocumentRetreiveParams): CompletableFuture = + retreive(params, RequestOptions.none()) + + /** @see [retreive] */ + fun retreive( + documentId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retreive(documentId, HrisDocumentRetreiveParams.none(), requestOptions) + /** * A view of [DocumentServiceAsync] that provides access to raw HTTP responses for each method. */ @@ -91,9 +117,26 @@ interface DocumentServiceAsync { */ @MustBeClosed fun retreive( - params: HrisDocumentRetreiveParams + documentId: String ): CompletableFuture> = - retreive(params, RequestOptions.none()) + retreive(documentId, HrisDocumentRetreiveParams.none()) + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retreive(params.toBuilder().documentId(documentId).build(), requestOptions) + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + ): CompletableFuture> = + retreive(documentId, params, RequestOptions.none()) /** @see [retreive] */ @MustBeClosed @@ -101,5 +144,20 @@ interface DocumentServiceAsync { params: HrisDocumentRetreiveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + params: HrisDocumentRetreiveParams + ): CompletableFuture> = + retreive(params, RequestOptions.none()) + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + documentId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retreive(documentId, HrisDocumentRetreiveParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncImpl.kt index 7f6e4636..cd75084e 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.hris import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -19,6 +20,7 @@ import com.tryfinch.api.models.DocumentRetreiveResponse import com.tryfinch.api.models.HrisDocumentListParams import com.tryfinch.api.models.HrisDocumentRetreiveParams import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class DocumentServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : DocumentServiceAsync { @@ -86,6 +88,9 @@ class DocumentServiceAsyncImpl internal constructor(private val clientOptions: C params: HrisDocumentRetreiveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("documentId", params.documentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsync.kt index 5999c68e..12b6ea0f 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsync.kt @@ -21,9 +21,25 @@ interface IndividualServiceAsync { fun withRawResponse(): WithRawResponse /** Lists individuals currently enrolled in a given deduction. */ + fun enrolledIds(benefitId: String): CompletableFuture = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none()) + + /** @see [enrolledIds] */ fun enrolledIds( - params: HrisBenefitIndividualEnrolledIdsParams - ): CompletableFuture = enrolledIds(params, RequestOptions.none()) + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + enrolledIds(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [enrolledIds] */ + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + ): CompletableFuture = + enrolledIds(benefitId, params, RequestOptions.none()) /** @see [enrolledIds] */ fun enrolledIds( @@ -31,11 +47,40 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [enrolledIds] */ + fun enrolledIds( + params: HrisBenefitIndividualEnrolledIdsParams + ): CompletableFuture = enrolledIds(params, RequestOptions.none()) + + /** @see [enrolledIds] */ + fun enrolledIds( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none(), requestOptions) + /** Get enrollment information for the given individuals. */ fun retrieveManyBenefits( - params: HrisBenefitIndividualRetrieveManyBenefitsParams + benefitId: String ): CompletableFuture = - retrieveManyBenefits(params, RequestOptions.none()) + retrieveManyBenefits(benefitId, HrisBenefitIndividualRetrieveManyBenefitsParams.none()) + + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieveManyBenefits(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + ): CompletableFuture = + retrieveManyBenefits(benefitId, params, RequestOptions.none()) /** @see [retrieveManyBenefits] */ fun retrieveManyBenefits( @@ -43,11 +88,43 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + params: HrisBenefitIndividualRetrieveManyBenefitsParams + ): CompletableFuture = + retrieveManyBenefits(params, RequestOptions.none()) + + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieveManyBenefits( + benefitId, + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions, + ) + /** Unenroll individuals from a deduction or contribution */ + fun unenrollMany(benefitId: String): CompletableFuture = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none()) + + /** @see [unenrollMany] */ fun unenrollMany( - params: HrisBenefitIndividualUnenrollManyParams + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture = - unenrollMany(params, RequestOptions.none()) + unenrollMany(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [unenrollMany] */ + fun unenrollMany( + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + ): CompletableFuture = + unenrollMany(benefitId, params, RequestOptions.none()) /** @see [unenrollMany] */ fun unenrollMany( @@ -55,6 +132,19 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [unenrollMany] */ + fun unenrollMany( + params: HrisBenefitIndividualUnenrollManyParams + ): CompletableFuture = + unenrollMany(params, RequestOptions.none()) + + /** @see [unenrollMany] */ + fun unenrollMany( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none(), requestOptions) + /** * A view of [IndividualServiceAsync] that provides access to raw HTTP responses for each * method. @@ -67,9 +157,28 @@ interface IndividualServiceAsync { */ @MustBeClosed fun enrolledIds( - params: HrisBenefitIndividualEnrolledIdsParams + benefitId: String ): CompletableFuture> = - enrolledIds(params, RequestOptions.none()) + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none()) + + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + enrolledIds(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + ): CompletableFuture> = + enrolledIds(benefitId, params, RequestOptions.none()) /** @see [enrolledIds] */ @MustBeClosed @@ -78,15 +187,49 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + params: HrisBenefitIndividualEnrolledIdsParams + ): CompletableFuture> = + enrolledIds(params, RequestOptions.none()) + + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/benefits/{benefit_id}/individuals`, but is * otherwise the same as [IndividualServiceAsync.retrieveManyBenefits]. */ @MustBeClosed fun retrieveManyBenefits( - params: HrisBenefitIndividualRetrieveManyBenefitsParams + benefitId: String ): CompletableFuture> = - retrieveManyBenefits(params, RequestOptions.none()) + retrieveManyBenefits(benefitId, HrisBenefitIndividualRetrieveManyBenefitsParams.none()) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieveManyBenefits(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + ): CompletableFuture> = + retrieveManyBenefits(benefitId, params, RequestOptions.none()) /** @see [retrieveManyBenefits] */ @MustBeClosed @@ -95,15 +238,53 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + params: HrisBenefitIndividualRetrieveManyBenefitsParams + ): CompletableFuture> = + retrieveManyBenefits(params, RequestOptions.none()) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieveManyBenefits( + benefitId, + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions, + ) + /** * Returns a raw HTTP response for `delete /employer/benefits/{benefit_id}/individuals`, but * is otherwise the same as [IndividualServiceAsync.unenrollMany]. */ @MustBeClosed fun unenrollMany( - params: HrisBenefitIndividualUnenrollManyParams + benefitId: String ): CompletableFuture> = - unenrollMany(params, RequestOptions.none()) + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none()) + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + unenrollMany(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + ): CompletableFuture> = + unenrollMany(benefitId, params, RequestOptions.none()) /** @see [unenrollMany] */ @MustBeClosed @@ -111,5 +292,20 @@ interface IndividualServiceAsync { params: HrisBenefitIndividualUnenrollManyParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + params: HrisBenefitIndividualUnenrollManyParams + ): CompletableFuture> = + unenrollMany(params, RequestOptions.none()) + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + benefitId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt index 0fa6358a..a7509390 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.hris.benefits import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -23,6 +24,7 @@ import com.tryfinch.api.models.IndividualBenefit import com.tryfinch.api.models.IndividualEnrolledIdsResponse import com.tryfinch.api.models.UnenrolledIndividualBenefitResponse import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class IndividualServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : IndividualServiceAsync { @@ -67,6 +69,9 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: params: HrisBenefitIndividualEnrolledIdsParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -97,6 +102,9 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: params: HrisBenefitIndividualRetrieveManyBenefitsParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -134,6 +142,9 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: params: HrisBenefitIndividualUnenrollManyParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsync.kt index e19add98..613b9577 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsync.kt @@ -53,9 +53,24 @@ interface RuleServiceAsync { * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon Update a rule for a pay statement item. */ + fun update(ruleId: String): CompletableFuture = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none()) + + /** @see [update] */ fun update( - params: HrisCompanyPayStatementItemRuleUpdateParams - ): CompletableFuture = update(params, RequestOptions.none()) + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [update] */ + fun update( + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + ): CompletableFuture = update(ruleId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -63,6 +78,18 @@ interface RuleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [update] */ + fun update( + params: HrisCompanyPayStatementItemRuleUpdateParams + ): CompletableFuture = update(params, RequestOptions.none()) + + /** @see [update] */ + fun update( + ruleId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none(), requestOptions) + /** * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon List all rules of a connection account. @@ -94,9 +121,24 @@ interface RuleServiceAsync { * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon Delete a rule for a pay statement item. */ + fun delete(ruleId: String): CompletableFuture = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none()) + + /** @see [delete] */ fun delete( - params: HrisCompanyPayStatementItemRuleDeleteParams - ): CompletableFuture = delete(params, RequestOptions.none()) + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + delete(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [delete] */ + fun delete( + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + ): CompletableFuture = delete(ruleId, params, RequestOptions.none()) /** @see [delete] */ fun delete( @@ -104,6 +146,18 @@ interface RuleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [delete] */ + fun delete( + params: HrisCompanyPayStatementItemRuleDeleteParams + ): CompletableFuture = delete(params, RequestOptions.none()) + + /** @see [delete] */ + fun delete( + ruleId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none(), requestOptions) + /** A view of [RuleServiceAsync] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -143,10 +197,27 @@ interface RuleServiceAsync { * otherwise the same as [RuleServiceAsync.update]. */ @MustBeClosed + fun update(ruleId: String): CompletableFuture> = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed fun update( - params: HrisCompanyPayStatementItemRuleUpdateParams + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - update(params, RequestOptions.none()) + update(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + ): CompletableFuture> = + update(ruleId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -155,6 +226,21 @@ interface RuleServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [update] */ + @MustBeClosed + fun update( + params: HrisCompanyPayStatementItemRuleUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + ruleId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/pay-statement-item/rule`, but is otherwise * the same as [RuleServiceAsync.list]. @@ -192,10 +278,27 @@ interface RuleServiceAsync { * is otherwise the same as [RuleServiceAsync.delete]. */ @MustBeClosed + fun delete(ruleId: String): CompletableFuture> = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none()) + + /** @see [delete] */ + @MustBeClosed fun delete( - params: HrisCompanyPayStatementItemRuleDeleteParams + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - delete(params, RequestOptions.none()) + delete(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [delete] */ + @MustBeClosed + fun delete( + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + ): CompletableFuture> = + delete(ruleId, params, RequestOptions.none()) /** @see [delete] */ @MustBeClosed @@ -203,5 +306,20 @@ interface RuleServiceAsync { params: HrisCompanyPayStatementItemRuleDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [delete] */ + @MustBeClosed + fun delete( + params: HrisCompanyPayStatementItemRuleDeleteParams + ): CompletableFuture> = + delete(params, RequestOptions.none()) + + /** @see [delete] */ + @MustBeClosed + fun delete( + ruleId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt index 3d5e6225..d967e16f 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.hris.company.payStatementItem import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -25,6 +26,7 @@ import com.tryfinch.api.models.RuleCreateResponse import com.tryfinch.api.models.RuleDeleteResponse import com.tryfinch.api.models.RuleUpdateResponse import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class RuleServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : RuleServiceAsync { @@ -105,6 +107,9 @@ class RuleServiceAsyncImpl internal constructor(private val clientOptions: Clien params: HrisCompanyPayStatementItemRuleUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("ruleId", params.ruleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) @@ -172,6 +177,9 @@ class RuleServiceAsyncImpl internal constructor(private val clientOptions: Clien params: HrisCompanyPayStatementItemRuleDeleteParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("ruleId", params.ruleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsync.kt index 374f8672..90fc195c 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsync.kt @@ -54,8 +54,22 @@ interface AutomatedServiceAsync { create(JobAutomatedCreateParams.none(), requestOptions) /** Get an automated job by `job_id`. */ - fun retrieve(params: JobAutomatedRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): CompletableFuture = + retrieve(jobId, JobAutomatedRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + ): CompletableFuture = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -63,6 +77,17 @@ interface AutomatedServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retrieve] */ + fun retrieve(params: JobAutomatedRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(jobId, JobAutomatedRetrieveParams.none(), requestOptions) + /** * Get all automated jobs. Automated jobs are completed by a machine. By default, jobs are * sorted in descending order by submission time. For scheduled jobs such as data syncs, only @@ -124,10 +149,25 @@ interface AutomatedServiceAsync { * as [AutomatedServiceAsync.retrieve]. */ @MustBeClosed + fun retrieve(jobId: String): CompletableFuture> = + retrieve(jobId, JobAutomatedRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed fun retrieve( - params: JobAutomatedRetrieveParams + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - retrieve(params, RequestOptions.none()) + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + ): CompletableFuture> = + retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -136,6 +176,21 @@ interface AutomatedServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + params: JobAutomatedRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(jobId, JobAutomatedRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /jobs/automated`, but is otherwise the same as * [AutomatedServiceAsync.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncImpl.kt index 486c207e..77de2441 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/AutomatedServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.jobs import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -22,6 +23,7 @@ import com.tryfinch.api.models.JobAutomatedCreateParams import com.tryfinch.api.models.JobAutomatedListParams import com.tryfinch.api.models.JobAutomatedRetrieveParams import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class AutomatedServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : AutomatedServiceAsync { @@ -96,6 +98,9 @@ class AutomatedServiceAsyncImpl internal constructor(private val clientOptions: params: JobAutomatedRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsync.kt index 0d51c731..9d131db4 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsync.kt @@ -20,8 +20,22 @@ interface ManualServiceAsync { * Get a manual job by `job_id`. Manual jobs are completed by a human and include Assisted * Benefits jobs. */ - fun retrieve(params: JobManualRetrieveParams): CompletableFuture = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): CompletableFuture = + retrieve(jobId, JobManualRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + ): CompletableFuture = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -29,6 +43,14 @@ interface ManualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retrieve] */ + fun retrieve(params: JobManualRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve(jobId: String, requestOptions: RequestOptions): CompletableFuture = + retrieve(jobId, JobManualRetrieveParams.none(), requestOptions) + /** * A view of [ManualServiceAsync] that provides access to raw HTTP responses for each method. */ @@ -39,10 +61,25 @@ interface ManualServiceAsync { * [ManualServiceAsync.retrieve]. */ @MustBeClosed + fun retrieve(jobId: String): CompletableFuture> = + retrieve(jobId, JobManualRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed fun retrieve( - params: JobManualRetrieveParams + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> = - retrieve(params, RequestOptions.none()) + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + ): CompletableFuture> = + retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -50,5 +87,20 @@ interface ManualServiceAsync { params: JobManualRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + params: JobManualRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(jobId, JobManualRetrieveParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncImpl.kt index 29425dfd..f52bfd4e 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.jobs import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -17,6 +18,7 @@ import com.tryfinch.api.core.prepareAsync import com.tryfinch.api.models.JobManualRetrieveParams import com.tryfinch.api.models.ManualAsyncJob import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class ManualServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : ManualServiceAsync { @@ -46,6 +48,9 @@ class ManualServiceAsyncImpl internal constructor(private val clientOptions: Cli params: JobManualRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsync.kt index 837276f5..303f01d7 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsync.kt @@ -19,9 +19,23 @@ interface PayGroupServiceAsync { fun withRawResponse(): WithRawResponse /** Read information from a single pay group */ + fun retrieve(payGroupId: String): CompletableFuture = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none()) + + /** @see [retrieve] */ fun retrieve( - params: PayrollPayGroupRetrieveParams - ): CompletableFuture = retrieve(params, RequestOptions.none()) + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().payGroupId(payGroupId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + ): CompletableFuture = + retrieve(payGroupId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -29,6 +43,18 @@ interface PayGroupServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [retrieve] */ + fun retrieve( + params: PayrollPayGroupRetrieveParams + ): CompletableFuture = retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve( + payGroupId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none(), requestOptions) + /** Read company pay groups and frequencies */ fun list(): CompletableFuture = list(PayrollPayGroupListParams.none()) @@ -59,9 +85,26 @@ interface PayGroupServiceAsync { */ @MustBeClosed fun retrieve( - params: PayrollPayGroupRetrieveParams + payGroupId: String ): CompletableFuture> = - retrieve(params, RequestOptions.none()) + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().payGroupId(payGroupId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + ): CompletableFuture> = + retrieve(payGroupId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -70,6 +113,21 @@ interface PayGroupServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + params: PayrollPayGroupRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + payGroupId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/pay-groups`, but is otherwise the same as * [PayGroupServiceAsync.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt index 1807f79b..0b42404d 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.payroll import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -20,6 +21,7 @@ import com.tryfinch.api.models.PayrollPayGroupListPageAsync import com.tryfinch.api.models.PayrollPayGroupListParams import com.tryfinch.api.models.PayrollPayGroupRetrieveParams import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class PayGroupServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : PayGroupServiceAsync { @@ -57,6 +59,9 @@ class PayGroupServiceAsyncImpl internal constructor(private val clientOptions: C params: PayrollPayGroupRetrieveParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("payGroupId", params.payGroupId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsync.kt index ad8fabfa..1828a047 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsync.kt @@ -17,8 +17,23 @@ interface EmploymentServiceAsync { fun withRawResponse(): WithRawResponse /** Update sandbox employment */ - fun update(params: SandboxEmploymentUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(individualId: String): CompletableFuture = + update(individualId, SandboxEmploymentUpdateParams.none()) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + ): CompletableFuture = + update(individualId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -26,6 +41,17 @@ interface EmploymentServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [update] */ + fun update(params: SandboxEmploymentUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update( + individualId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(individualId, SandboxEmploymentUpdateParams.none(), requestOptions) + /** * A view of [EmploymentServiceAsync] that provides access to raw HTTP responses for each * method. @@ -38,9 +64,26 @@ interface EmploymentServiceAsync { */ @MustBeClosed fun update( - params: SandboxEmploymentUpdateParams + individualId: String ): CompletableFuture> = - update(params, RequestOptions.none()) + update(individualId, SandboxEmploymentUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + ): CompletableFuture> = + update(individualId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -48,5 +91,20 @@ interface EmploymentServiceAsync { params: SandboxEmploymentUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [update] */ + @MustBeClosed + fun update( + params: SandboxEmploymentUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(individualId, SandboxEmploymentUpdateParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncImpl.kt index 212d7652..9534d121 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/EmploymentServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.sandbox import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -18,6 +19,7 @@ import com.tryfinch.api.core.prepareAsync import com.tryfinch.api.models.EmploymentUpdateResponse import com.tryfinch.api.models.SandboxEmploymentUpdateParams import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class EmploymentServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : EmploymentServiceAsync { @@ -48,6 +50,9 @@ class EmploymentServiceAsyncImpl internal constructor(private val clientOptions: params: SandboxEmploymentUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("individualId", params.individualId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsync.kt index 47d38c4e..74ba9437 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsync.kt @@ -17,8 +17,23 @@ interface IndividualServiceAsync { fun withRawResponse(): WithRawResponse /** Update sandbox individual */ - fun update(params: SandboxIndividualUpdateParams): CompletableFuture = - update(params, RequestOptions.none()) + fun update(individualId: String): CompletableFuture = + update(individualId, SandboxIndividualUpdateParams.none()) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + ): CompletableFuture = + update(individualId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -26,6 +41,17 @@ interface IndividualServiceAsync { requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture + /** @see [update] */ + fun update(params: SandboxIndividualUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update( + individualId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + update(individualId, SandboxIndividualUpdateParams.none(), requestOptions) + /** * A view of [IndividualServiceAsync] that provides access to raw HTTP responses for each * method. @@ -38,9 +64,26 @@ interface IndividualServiceAsync { */ @MustBeClosed fun update( - params: SandboxIndividualUpdateParams + individualId: String ): CompletableFuture> = - update(params, RequestOptions.none()) + update(individualId, SandboxIndividualUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + ): CompletableFuture> = + update(individualId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -48,5 +91,20 @@ interface IndividualServiceAsync { params: SandboxIndividualUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> + + /** @see [update] */ + @MustBeClosed + fun update( + params: SandboxIndividualUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + update(individualId, SandboxIndividualUpdateParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncImpl.kt index 7cdca716..fca58ca0 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/sandbox/IndividualServiceAsyncImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.async.sandbox import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -18,6 +19,7 @@ import com.tryfinch.api.core.prepareAsync import com.tryfinch.api.models.IndividualUpdateResponse import com.tryfinch.api.models.SandboxIndividualUpdateParams import java.util.concurrent.CompletableFuture +import kotlin.jvm.optionals.getOrNull class IndividualServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : IndividualServiceAsync { @@ -48,6 +50,9 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: params: SandboxIndividualUpdateParams, requestOptions: RequestOptions, ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("individualId", params.individualId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitService.kt index 0625d51a..43c93d72 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitService.kt @@ -48,8 +48,21 @@ interface BenefitService { create(HrisBenefitCreateParams.none(), requestOptions) /** Lists deductions and contributions information for a given item */ - fun retrieve(params: HrisBenefitRetrieveParams): CompanyBenefit = - retrieve(params, RequestOptions.none()) + fun retrieve(benefitId: String): CompanyBenefit = + retrieve(benefitId, HrisBenefitRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompanyBenefit = retrieve(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + ): CompanyBenefit = retrieve(benefitId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -57,9 +70,31 @@ interface BenefitService { requestOptions: RequestOptions = RequestOptions.none(), ): CompanyBenefit + /** @see [retrieve] */ + fun retrieve(params: HrisBenefitRetrieveParams): CompanyBenefit = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve(benefitId: String, requestOptions: RequestOptions): CompanyBenefit = + retrieve(benefitId, HrisBenefitRetrieveParams.none(), requestOptions) + /** Updates an existing company-wide deduction or contribution */ - fun update(params: HrisBenefitUpdateParams): UpdateCompanyBenefitResponse = - update(params, RequestOptions.none()) + fun update(benefitId: String): UpdateCompanyBenefitResponse = + update(benefitId, HrisBenefitUpdateParams.none()) + + /** @see [update] */ + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): UpdateCompanyBenefitResponse = + update(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [update] */ + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + ): UpdateCompanyBenefitResponse = update(benefitId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -67,6 +102,14 @@ interface BenefitService { requestOptions: RequestOptions = RequestOptions.none(), ): UpdateCompanyBenefitResponse + /** @see [update] */ + fun update(params: HrisBenefitUpdateParams): UpdateCompanyBenefitResponse = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update(benefitId: String, requestOptions: RequestOptions): UpdateCompanyBenefitResponse = + update(benefitId, HrisBenefitUpdateParams.none(), requestOptions) + /** List all company-wide deductions and contributions. */ fun list(): HrisBenefitListPage = list(HrisBenefitListParams.none()) @@ -143,8 +186,24 @@ interface BenefitService { * the same as [BenefitService.retrieve]. */ @MustBeClosed - fun retrieve(params: HrisBenefitRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(benefitId: String): HttpResponseFor = + retrieve(benefitId, HrisBenefitRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + benefitId: String, + params: HrisBenefitRetrieveParams = HrisBenefitRetrieveParams.none(), + ): HttpResponseFor = retrieve(benefitId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -153,13 +212,43 @@ interface BenefitService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [retrieve] */ + @MustBeClosed + fun retrieve(params: HrisBenefitRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + benefitId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(benefitId, HrisBenefitRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `post /employer/benefits/{benefit_id}`, but is otherwise * the same as [BenefitService.update]. */ @MustBeClosed - fun update(params: HrisBenefitUpdateParams): HttpResponseFor = - update(params, RequestOptions.none()) + fun update(benefitId: String): HttpResponseFor = + update(benefitId, HrisBenefitUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + params: HrisBenefitUpdateParams = HrisBenefitUpdateParams.none(), + ): HttpResponseFor = + update(benefitId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -168,6 +257,19 @@ interface BenefitService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [update] */ + @MustBeClosed + fun update(params: HrisBenefitUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + benefitId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(benefitId, HrisBenefitUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/benefits`, but is otherwise the same as * [BenefitService.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceImpl.kt index 98cd9792..3fc43430 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/BenefitServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.hris import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -29,6 +30,7 @@ import com.tryfinch.api.models.UpdateCompanyBenefitResponse import com.tryfinch.api.services.blocking.hris.benefits.IndividualService import com.tryfinch.api.services.blocking.hris.benefits.IndividualServiceImpl import java.util.Optional +import kotlin.jvm.optionals.getOrNull class BenefitServiceImpl internal constructor(private val clientOptions: ClientOptions) : BenefitService { @@ -124,6 +126,9 @@ class BenefitServiceImpl internal constructor(private val clientOptions: ClientO params: HrisBenefitRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -151,6 +156,9 @@ class BenefitServiceImpl internal constructor(private val clientOptions: ClientO params: HrisBenefitUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.POST) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentService.kt index 2688fe07..0fb3dc39 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentService.kt @@ -40,8 +40,22 @@ interface DocumentService { * **Beta:** This endpoint is in beta and may change. Retrieve details of a specific document by * its ID. */ - fun retreive(params: HrisDocumentRetreiveParams): DocumentRetreiveResponse = - retreive(params, RequestOptions.none()) + fun retreive(documentId: String): DocumentRetreiveResponse = + retreive(documentId, HrisDocumentRetreiveParams.none()) + + /** @see [retreive] */ + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): DocumentRetreiveResponse = + retreive(params.toBuilder().documentId(documentId).build(), requestOptions) + + /** @see [retreive] */ + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + ): DocumentRetreiveResponse = retreive(documentId, params, RequestOptions.none()) /** @see [retreive] */ fun retreive( @@ -49,6 +63,14 @@ interface DocumentService { requestOptions: RequestOptions = RequestOptions.none(), ): DocumentRetreiveResponse + /** @see [retreive] */ + fun retreive(params: HrisDocumentRetreiveParams): DocumentRetreiveResponse = + retreive(params, RequestOptions.none()) + + /** @see [retreive] */ + fun retreive(documentId: String, requestOptions: RequestOptions): DocumentRetreiveResponse = + retreive(documentId, HrisDocumentRetreiveParams.none(), requestOptions) + /** A view of [DocumentService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -82,9 +104,25 @@ interface DocumentService { * the same as [DocumentService.retreive]. */ @MustBeClosed + fun retreive(documentId: String): HttpResponseFor = + retreive(documentId, HrisDocumentRetreiveParams.none()) + + /** @see [retreive] */ + @MustBeClosed fun retreive( - params: HrisDocumentRetreiveParams - ): HttpResponseFor = retreive(params, RequestOptions.none()) + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retreive(params.toBuilder().documentId(documentId).build(), requestOptions) + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + documentId: String, + params: HrisDocumentRetreiveParams = HrisDocumentRetreiveParams.none(), + ): HttpResponseFor = + retreive(documentId, params, RequestOptions.none()) /** @see [retreive] */ @MustBeClosed @@ -92,5 +130,19 @@ interface DocumentService { params: HrisDocumentRetreiveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + params: HrisDocumentRetreiveParams + ): HttpResponseFor = retreive(params, RequestOptions.none()) + + /** @see [retreive] */ + @MustBeClosed + fun retreive( + documentId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retreive(documentId, HrisDocumentRetreiveParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceImpl.kt index 8ddf997d..2f11fac7 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.hris import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -18,6 +19,7 @@ import com.tryfinch.api.models.DocumentListResponse import com.tryfinch.api.models.DocumentRetreiveResponse import com.tryfinch.api.models.HrisDocumentListParams import com.tryfinch.api.models.HrisDocumentRetreiveParams +import kotlin.jvm.optionals.getOrNull class DocumentServiceImpl internal constructor(private val clientOptions: ClientOptions) : DocumentService { @@ -82,6 +84,9 @@ class DocumentServiceImpl internal constructor(private val clientOptions: Client params: HrisDocumentRetreiveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("documentId", params.documentId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualService.kt index 5352666e..9a306ff3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualService.kt @@ -20,8 +20,24 @@ interface IndividualService { fun withRawResponse(): WithRawResponse /** Lists individuals currently enrolled in a given deduction. */ - fun enrolledIds(params: HrisBenefitIndividualEnrolledIdsParams): IndividualEnrolledIdsResponse = - enrolledIds(params, RequestOptions.none()) + fun enrolledIds(benefitId: String): IndividualEnrolledIdsResponse = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none()) + + /** @see [enrolledIds] */ + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): IndividualEnrolledIdsResponse = + enrolledIds(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [enrolledIds] */ + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + ): IndividualEnrolledIdsResponse = enrolledIds(benefitId, params, RequestOptions.none()) /** @see [enrolledIds] */ fun enrolledIds( @@ -29,11 +45,37 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): IndividualEnrolledIdsResponse + /** @see [enrolledIds] */ + fun enrolledIds(params: HrisBenefitIndividualEnrolledIdsParams): IndividualEnrolledIdsResponse = + enrolledIds(params, RequestOptions.none()) + + /** @see [enrolledIds] */ + fun enrolledIds( + benefitId: String, + requestOptions: RequestOptions, + ): IndividualEnrolledIdsResponse = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none(), requestOptions) + /** Get enrollment information for the given individuals. */ + fun retrieveManyBenefits(benefitId: String): HrisBenefitIndividualRetrieveManyBenefitsPage = + retrieveManyBenefits(benefitId, HrisBenefitIndividualRetrieveManyBenefitsParams.none()) + + /** @see [retrieveManyBenefits] */ fun retrieveManyBenefits( - params: HrisBenefitIndividualRetrieveManyBenefitsParams + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): HrisBenefitIndividualRetrieveManyBenefitsPage = - retrieveManyBenefits(params, RequestOptions.none()) + retrieveManyBenefits(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + ): HrisBenefitIndividualRetrieveManyBenefitsPage = + retrieveManyBenefits(benefitId, params, RequestOptions.none()) /** @see [retrieveManyBenefits] */ fun retrieveManyBenefits( @@ -41,10 +83,42 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): HrisBenefitIndividualRetrieveManyBenefitsPage + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + params: HrisBenefitIndividualRetrieveManyBenefitsParams + ): HrisBenefitIndividualRetrieveManyBenefitsPage = + retrieveManyBenefits(params, RequestOptions.none()) + + /** @see [retrieveManyBenefits] */ + fun retrieveManyBenefits( + benefitId: String, + requestOptions: RequestOptions, + ): HrisBenefitIndividualRetrieveManyBenefitsPage = + retrieveManyBenefits( + benefitId, + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions, + ) + /** Unenroll individuals from a deduction or contribution */ + fun unenrollMany(benefitId: String): UnenrolledIndividualBenefitResponse = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none()) + + /** @see [unenrollMany] */ fun unenrollMany( - params: HrisBenefitIndividualUnenrollManyParams - ): UnenrolledIndividualBenefitResponse = unenrollMany(params, RequestOptions.none()) + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): UnenrolledIndividualBenefitResponse = + unenrollMany(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [unenrollMany] */ + fun unenrollMany( + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + ): UnenrolledIndividualBenefitResponse = unenrollMany(benefitId, params, RequestOptions.none()) /** @see [unenrollMany] */ fun unenrollMany( @@ -52,6 +126,18 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): UnenrolledIndividualBenefitResponse + /** @see [unenrollMany] */ + fun unenrollMany( + params: HrisBenefitIndividualUnenrollManyParams + ): UnenrolledIndividualBenefitResponse = unenrollMany(params, RequestOptions.none()) + + /** @see [unenrollMany] */ + fun unenrollMany( + benefitId: String, + requestOptions: RequestOptions, + ): UnenrolledIndividualBenefitResponse = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none(), requestOptions) + /** A view of [IndividualService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -60,10 +146,27 @@ interface IndividualService { * otherwise the same as [IndividualService.enrolledIds]. */ @MustBeClosed + fun enrolledIds(benefitId: String): HttpResponseFor = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none()) + + /** @see [enrolledIds] */ + @MustBeClosed fun enrolledIds( - params: HrisBenefitIndividualEnrolledIdsParams + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor = - enrolledIds(params, RequestOptions.none()) + enrolledIds(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + benefitId: String, + params: HrisBenefitIndividualEnrolledIdsParams = + HrisBenefitIndividualEnrolledIdsParams.none(), + ): HttpResponseFor = + enrolledIds(benefitId, params, RequestOptions.none()) /** @see [enrolledIds] */ @MustBeClosed @@ -72,15 +175,49 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + params: HrisBenefitIndividualEnrolledIdsParams + ): HttpResponseFor = + enrolledIds(params, RequestOptions.none()) + + /** @see [enrolledIds] */ + @MustBeClosed + fun enrolledIds( + benefitId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + enrolledIds(benefitId, HrisBenefitIndividualEnrolledIdsParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/benefits/{benefit_id}/individuals`, but is * otherwise the same as [IndividualService.retrieveManyBenefits]. */ @MustBeClosed fun retrieveManyBenefits( - params: HrisBenefitIndividualRetrieveManyBenefitsParams + benefitId: String ): HttpResponseFor = - retrieveManyBenefits(params, RequestOptions.none()) + retrieveManyBenefits(benefitId, HrisBenefitIndividualRetrieveManyBenefitsParams.none()) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieveManyBenefits(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + params: HrisBenefitIndividualRetrieveManyBenefitsParams = + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + ): HttpResponseFor = + retrieveManyBenefits(benefitId, params, RequestOptions.none()) /** @see [retrieveManyBenefits] */ @MustBeClosed @@ -89,15 +226,51 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + params: HrisBenefitIndividualRetrieveManyBenefitsParams + ): HttpResponseFor = + retrieveManyBenefits(params, RequestOptions.none()) + + /** @see [retrieveManyBenefits] */ + @MustBeClosed + fun retrieveManyBenefits( + benefitId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieveManyBenefits( + benefitId, + HrisBenefitIndividualRetrieveManyBenefitsParams.none(), + requestOptions, + ) + /** * Returns a raw HTTP response for `delete /employer/benefits/{benefit_id}/individuals`, but * is otherwise the same as [IndividualService.unenrollMany]. */ @MustBeClosed + fun unenrollMany(benefitId: String): HttpResponseFor = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none()) + + /** @see [unenrollMany] */ + @MustBeClosed fun unenrollMany( - params: HrisBenefitIndividualUnenrollManyParams + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor = - unenrollMany(params, RequestOptions.none()) + unenrollMany(params.toBuilder().benefitId(benefitId).build(), requestOptions) + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + benefitId: String, + params: HrisBenefitIndividualUnenrollManyParams = + HrisBenefitIndividualUnenrollManyParams.none(), + ): HttpResponseFor = + unenrollMany(benefitId, params, RequestOptions.none()) /** @see [unenrollMany] */ @MustBeClosed @@ -105,5 +278,20 @@ interface IndividualService { params: HrisBenefitIndividualUnenrollManyParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + params: HrisBenefitIndividualUnenrollManyParams + ): HttpResponseFor = + unenrollMany(params, RequestOptions.none()) + + /** @see [unenrollMany] */ + @MustBeClosed + fun unenrollMany( + benefitId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + unenrollMany(benefitId, HrisBenefitIndividualUnenrollManyParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceImpl.kt index 403030dd..9fc38484 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.hris.benefits import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -22,6 +23,7 @@ import com.tryfinch.api.models.HrisBenefitIndividualUnenrollManyParams import com.tryfinch.api.models.IndividualBenefit import com.tryfinch.api.models.IndividualEnrolledIdsResponse import com.tryfinch.api.models.UnenrolledIndividualBenefitResponse +import kotlin.jvm.optionals.getOrNull class IndividualServiceImpl internal constructor(private val clientOptions: ClientOptions) : IndividualService { @@ -66,6 +68,9 @@ class IndividualServiceImpl internal constructor(private val clientOptions: Clie params: HrisBenefitIndividualEnrolledIdsParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -93,6 +98,9 @@ class IndividualServiceImpl internal constructor(private val clientOptions: Clie params: HrisBenefitIndividualRetrieveManyBenefitsParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) @@ -127,6 +135,9 @@ class IndividualServiceImpl internal constructor(private val clientOptions: Clie params: HrisBenefitIndividualUnenrollManyParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("benefitId", params.benefitId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleService.kt index 34a2124d..288e3791 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleService.kt @@ -51,8 +51,23 @@ interface RuleService { * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon Update a rule for a pay statement item. */ - fun update(params: HrisCompanyPayStatementItemRuleUpdateParams): RuleUpdateResponse = - update(params, RequestOptions.none()) + fun update(ruleId: String): RuleUpdateResponse = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none()) + + /** @see [update] */ + fun update( + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): RuleUpdateResponse = update(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [update] */ + fun update( + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + ): RuleUpdateResponse = update(ruleId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -60,6 +75,14 @@ interface RuleService { requestOptions: RequestOptions = RequestOptions.none(), ): RuleUpdateResponse + /** @see [update] */ + fun update(params: HrisCompanyPayStatementItemRuleUpdateParams): RuleUpdateResponse = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update(ruleId: String, requestOptions: RequestOptions): RuleUpdateResponse = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none(), requestOptions) + /** * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon List all rules of a connection account. @@ -88,8 +111,23 @@ interface RuleService { * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical * support will be added soon Delete a rule for a pay statement item. */ - fun delete(params: HrisCompanyPayStatementItemRuleDeleteParams): RuleDeleteResponse = - delete(params, RequestOptions.none()) + fun delete(ruleId: String): RuleDeleteResponse = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none()) + + /** @see [delete] */ + fun delete( + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): RuleDeleteResponse = delete(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [delete] */ + fun delete( + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + ): RuleDeleteResponse = delete(ruleId, params, RequestOptions.none()) /** @see [delete] */ fun delete( @@ -97,6 +135,14 @@ interface RuleService { requestOptions: RequestOptions = RequestOptions.none(), ): RuleDeleteResponse + /** @see [delete] */ + fun delete(params: HrisCompanyPayStatementItemRuleDeleteParams): RuleDeleteResponse = + delete(params, RequestOptions.none()) + + /** @see [delete] */ + fun delete(ruleId: String, requestOptions: RequestOptions): RuleDeleteResponse = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none(), requestOptions) + /** A view of [RuleService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -133,9 +179,26 @@ interface RuleService { * otherwise the same as [RuleService.update]. */ @MustBeClosed + fun update(ruleId: String): HttpResponseFor = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed fun update( - params: HrisCompanyPayStatementItemRuleUpdateParams - ): HttpResponseFor = update(params, RequestOptions.none()) + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + ruleId: String, + params: HrisCompanyPayStatementItemRuleUpdateParams = + HrisCompanyPayStatementItemRuleUpdateParams.none(), + ): HttpResponseFor = update(ruleId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -144,6 +207,20 @@ interface RuleService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [update] */ + @MustBeClosed + fun update( + params: HrisCompanyPayStatementItemRuleUpdateParams + ): HttpResponseFor = update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + ruleId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(ruleId, HrisCompanyPayStatementItemRuleUpdateParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/pay-statement-item/rule`, but is otherwise * the same as [RuleService.list]. @@ -180,9 +257,26 @@ interface RuleService { * is otherwise the same as [RuleService.delete]. */ @MustBeClosed + fun delete(ruleId: String): HttpResponseFor = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none()) + + /** @see [delete] */ + @MustBeClosed fun delete( - params: HrisCompanyPayStatementItemRuleDeleteParams - ): HttpResponseFor = delete(params, RequestOptions.none()) + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + delete(params.toBuilder().ruleId(ruleId).build(), requestOptions) + + /** @see [delete] */ + @MustBeClosed + fun delete( + ruleId: String, + params: HrisCompanyPayStatementItemRuleDeleteParams = + HrisCompanyPayStatementItemRuleDeleteParams.none(), + ): HttpResponseFor = delete(ruleId, params, RequestOptions.none()) /** @see [delete] */ @MustBeClosed @@ -190,5 +284,19 @@ interface RuleService { params: HrisCompanyPayStatementItemRuleDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [delete] */ + @MustBeClosed + fun delete( + params: HrisCompanyPayStatementItemRuleDeleteParams + ): HttpResponseFor = delete(params, RequestOptions.none()) + + /** @see [delete] */ + @MustBeClosed + fun delete( + ruleId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + delete(ruleId, HrisCompanyPayStatementItemRuleDeleteParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceImpl.kt index 370263d4..c829f537 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.hris.company.payStatementItem import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -24,6 +25,7 @@ import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleUpdateParams import com.tryfinch.api.models.RuleCreateResponse import com.tryfinch.api.models.RuleDeleteResponse import com.tryfinch.api.models.RuleUpdateResponse +import kotlin.jvm.optionals.getOrNull class RuleServiceImpl internal constructor(private val clientOptions: ClientOptions) : RuleService { @@ -100,6 +102,9 @@ class RuleServiceImpl internal constructor(private val clientOptions: ClientOpti params: HrisCompanyPayStatementItemRuleUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("ruleId", params.ruleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) @@ -161,6 +166,9 @@ class RuleServiceImpl internal constructor(private val clientOptions: ClientOpti params: HrisCompanyPayStatementItemRuleDeleteParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("ruleId", params.ruleId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.DELETE) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedService.kt index fafcfff9..4bc55fe3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedService.kt @@ -52,8 +52,21 @@ interface AutomatedService { create(JobAutomatedCreateParams.none(), requestOptions) /** Get an automated job by `job_id`. */ - fun retrieve(params: JobAutomatedRetrieveParams): AutomatedAsyncJob = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): AutomatedAsyncJob = + retrieve(jobId, JobAutomatedRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): AutomatedAsyncJob = retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + ): AutomatedAsyncJob = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -61,6 +74,14 @@ interface AutomatedService { requestOptions: RequestOptions = RequestOptions.none(), ): AutomatedAsyncJob + /** @see [retrieve] */ + fun retrieve(params: JobAutomatedRetrieveParams): AutomatedAsyncJob = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve(jobId: String, requestOptions: RequestOptions): AutomatedAsyncJob = + retrieve(jobId, JobAutomatedRetrieveParams.none(), requestOptions) + /** * Get all automated jobs. Automated jobs are completed by a machine. By default, jobs are * sorted in descending order by submission time. For scheduled jobs such as data syncs, only @@ -117,8 +138,24 @@ interface AutomatedService { * as [AutomatedService.retrieve]. */ @MustBeClosed - fun retrieve(params: JobAutomatedRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): HttpResponseFor = + retrieve(jobId, JobAutomatedRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobAutomatedRetrieveParams = JobAutomatedRetrieveParams.none(), + ): HttpResponseFor = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -127,6 +164,19 @@ interface AutomatedService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [retrieve] */ + @MustBeClosed + fun retrieve(params: JobAutomatedRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(jobId, JobAutomatedRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /jobs/automated`, but is otherwise the same as * [AutomatedService.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceImpl.kt index 3d20fb5e..87e961d5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/AutomatedServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.jobs import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -21,6 +22,7 @@ import com.tryfinch.api.models.AutomatedListResponse import com.tryfinch.api.models.JobAutomatedCreateParams import com.tryfinch.api.models.JobAutomatedListParams import com.tryfinch.api.models.JobAutomatedRetrieveParams +import kotlin.jvm.optionals.getOrNull class AutomatedServiceImpl internal constructor(private val clientOptions: ClientOptions) : AutomatedService { @@ -92,6 +94,9 @@ class AutomatedServiceImpl internal constructor(private val clientOptions: Clien params: JobAutomatedRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualService.kt index 66de50ae..4e0334df 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualService.kt @@ -19,8 +19,20 @@ interface ManualService { * Get a manual job by `job_id`. Manual jobs are completed by a human and include Assisted * Benefits jobs. */ - fun retrieve(params: JobManualRetrieveParams): ManualAsyncJob = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): ManualAsyncJob = retrieve(jobId, JobManualRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): ManualAsyncJob = retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + ): ManualAsyncJob = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -28,6 +40,14 @@ interface ManualService { requestOptions: RequestOptions = RequestOptions.none(), ): ManualAsyncJob + /** @see [retrieve] */ + fun retrieve(params: JobManualRetrieveParams): ManualAsyncJob = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve(jobId: String, requestOptions: RequestOptions): ManualAsyncJob = + retrieve(jobId, JobManualRetrieveParams.none(), requestOptions) + /** A view of [ManualService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -36,8 +56,24 @@ interface ManualService { * [ManualService.retrieve]. */ @MustBeClosed - fun retrieve(params: JobManualRetrieveParams): HttpResponseFor = - retrieve(params, RequestOptions.none()) + fun retrieve(jobId: String): HttpResponseFor = + retrieve(jobId, JobManualRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().jobId(jobId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + params: JobManualRetrieveParams = JobManualRetrieveParams.none(), + ): HttpResponseFor = retrieve(jobId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -45,5 +81,18 @@ interface ManualService { params: JobManualRetrieveParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve(params: JobManualRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + jobId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(jobId, JobManualRetrieveParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceImpl.kt index b055b8e6..373dabf5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.jobs import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -16,6 +17,7 @@ import com.tryfinch.api.core.http.parseable import com.tryfinch.api.core.prepare import com.tryfinch.api.models.JobManualRetrieveParams import com.tryfinch.api.models.ManualAsyncJob +import kotlin.jvm.optionals.getOrNull class ManualServiceImpl internal constructor(private val clientOptions: ClientOptions) : ManualService { @@ -45,6 +47,9 @@ class ManualServiceImpl internal constructor(private val clientOptions: ClientOp params: JobManualRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("jobId", params.jobId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupService.kt index dfbd5bb3..05717f0b 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupService.kt @@ -18,8 +18,22 @@ interface PayGroupService { fun withRawResponse(): WithRawResponse /** Read information from a single pay group */ - fun retrieve(params: PayrollPayGroupRetrieveParams): PayGroupRetrieveResponse = - retrieve(params, RequestOptions.none()) + fun retrieve(payGroupId: String): PayGroupRetrieveResponse = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none()) + + /** @see [retrieve] */ + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): PayGroupRetrieveResponse = + retrieve(params.toBuilder().payGroupId(payGroupId).build(), requestOptions) + + /** @see [retrieve] */ + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + ): PayGroupRetrieveResponse = retrieve(payGroupId, params, RequestOptions.none()) /** @see [retrieve] */ fun retrieve( @@ -27,6 +41,14 @@ interface PayGroupService { requestOptions: RequestOptions = RequestOptions.none(), ): PayGroupRetrieveResponse + /** @see [retrieve] */ + fun retrieve(params: PayrollPayGroupRetrieveParams): PayGroupRetrieveResponse = + retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + fun retrieve(payGroupId: String, requestOptions: RequestOptions): PayGroupRetrieveResponse = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none(), requestOptions) + /** Read company pay groups and frequencies */ fun list(): PayrollPayGroupListPage = list(PayrollPayGroupListParams.none()) @@ -53,9 +75,25 @@ interface PayGroupService { * otherwise the same as [PayGroupService.retrieve]. */ @MustBeClosed + fun retrieve(payGroupId: String): HttpResponseFor = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none()) + + /** @see [retrieve] */ + @MustBeClosed fun retrieve( - params: PayrollPayGroupRetrieveParams - ): HttpResponseFor = retrieve(params, RequestOptions.none()) + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().payGroupId(payGroupId).build(), requestOptions) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + payGroupId: String, + params: PayrollPayGroupRetrieveParams = PayrollPayGroupRetrieveParams.none(), + ): HttpResponseFor = + retrieve(payGroupId, params, RequestOptions.none()) /** @see [retrieve] */ @MustBeClosed @@ -64,6 +102,20 @@ interface PayGroupService { requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + params: PayrollPayGroupRetrieveParams + ): HttpResponseFor = retrieve(params, RequestOptions.none()) + + /** @see [retrieve] */ + @MustBeClosed + fun retrieve( + payGroupId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(payGroupId, PayrollPayGroupRetrieveParams.none(), requestOptions) + /** * Returns a raw HTTP response for `get /employer/pay-groups`, but is otherwise the same as * [PayGroupService.list]. diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceImpl.kt index 085c2bc4..fffb28b5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.payroll import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -19,6 +20,7 @@ import com.tryfinch.api.models.PayGroupRetrieveResponse import com.tryfinch.api.models.PayrollPayGroupListPage import com.tryfinch.api.models.PayrollPayGroupListParams import com.tryfinch.api.models.PayrollPayGroupRetrieveParams +import kotlin.jvm.optionals.getOrNull class PayGroupServiceImpl internal constructor(private val clientOptions: ClientOptions) : PayGroupService { @@ -56,6 +58,9 @@ class PayGroupServiceImpl internal constructor(private val clientOptions: Client params: PayrollPayGroupRetrieveParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("payGroupId", params.payGroupId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.GET) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentService.kt index d1af16fb..8c83ae62 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentService.kt @@ -16,8 +16,22 @@ interface EmploymentService { fun withRawResponse(): WithRawResponse /** Update sandbox employment */ - fun update(params: SandboxEmploymentUpdateParams): EmploymentUpdateResponse = - update(params, RequestOptions.none()) + fun update(individualId: String): EmploymentUpdateResponse = + update(individualId, SandboxEmploymentUpdateParams.none()) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): EmploymentUpdateResponse = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + ): EmploymentUpdateResponse = update(individualId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -25,6 +39,14 @@ interface EmploymentService { requestOptions: RequestOptions = RequestOptions.none(), ): EmploymentUpdateResponse + /** @see [update] */ + fun update(params: SandboxEmploymentUpdateParams): EmploymentUpdateResponse = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update(individualId: String, requestOptions: RequestOptions): EmploymentUpdateResponse = + update(individualId, SandboxEmploymentUpdateParams.none(), requestOptions) + /** A view of [EmploymentService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -33,9 +55,25 @@ interface EmploymentService { * otherwise the same as [EmploymentService.update]. */ @MustBeClosed + fun update(individualId: String): HttpResponseFor = + update(individualId, SandboxEmploymentUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed fun update( - params: SandboxEmploymentUpdateParams - ): HttpResponseFor = update(params, RequestOptions.none()) + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxEmploymentUpdateParams = SandboxEmploymentUpdateParams.none(), + ): HttpResponseFor = + update(individualId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -43,5 +81,19 @@ interface EmploymentService { params: SandboxEmploymentUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [update] */ + @MustBeClosed + fun update( + params: SandboxEmploymentUpdateParams + ): HttpResponseFor = update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(individualId, SandboxEmploymentUpdateParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceImpl.kt index da766444..e956fc67 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/EmploymentServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.sandbox import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -17,6 +18,7 @@ import com.tryfinch.api.core.http.parseable import com.tryfinch.api.core.prepare import com.tryfinch.api.models.EmploymentUpdateResponse import com.tryfinch.api.models.SandboxEmploymentUpdateParams +import kotlin.jvm.optionals.getOrNull class EmploymentServiceImpl internal constructor(private val clientOptions: ClientOptions) : EmploymentService { @@ -47,6 +49,9 @@ class EmploymentServiceImpl internal constructor(private val clientOptions: Clie params: SandboxEmploymentUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("individualId", params.individualId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualService.kt index 8be711cb..e8c5faef 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualService.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualService.kt @@ -16,8 +16,22 @@ interface IndividualService { fun withRawResponse(): WithRawResponse /** Update sandbox individual */ - fun update(params: SandboxIndividualUpdateParams): IndividualUpdateResponse = - update(params, RequestOptions.none()) + fun update(individualId: String): IndividualUpdateResponse = + update(individualId, SandboxIndividualUpdateParams.none()) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): IndividualUpdateResponse = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + ): IndividualUpdateResponse = update(individualId, params, RequestOptions.none()) /** @see [update] */ fun update( @@ -25,6 +39,14 @@ interface IndividualService { requestOptions: RequestOptions = RequestOptions.none(), ): IndividualUpdateResponse + /** @see [update] */ + fun update(params: SandboxIndividualUpdateParams): IndividualUpdateResponse = + update(params, RequestOptions.none()) + + /** @see [update] */ + fun update(individualId: String, requestOptions: RequestOptions): IndividualUpdateResponse = + update(individualId, SandboxIndividualUpdateParams.none(), requestOptions) + /** A view of [IndividualService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -33,9 +55,25 @@ interface IndividualService { * otherwise the same as [IndividualService.update]. */ @MustBeClosed + fun update(individualId: String): HttpResponseFor = + update(individualId, SandboxIndividualUpdateParams.none()) + + /** @see [update] */ + @MustBeClosed fun update( - params: SandboxIndividualUpdateParams - ): HttpResponseFor = update(params, RequestOptions.none()) + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().individualId(individualId).build(), requestOptions) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + params: SandboxIndividualUpdateParams = SandboxIndividualUpdateParams.none(), + ): HttpResponseFor = + update(individualId, params, RequestOptions.none()) /** @see [update] */ @MustBeClosed @@ -43,5 +81,19 @@ interface IndividualService { params: SandboxIndividualUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor + + /** @see [update] */ + @MustBeClosed + fun update( + params: SandboxIndividualUpdateParams + ): HttpResponseFor = update(params, RequestOptions.none()) + + /** @see [update] */ + @MustBeClosed + fun update( + individualId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + update(individualId, SandboxIndividualUpdateParams.none(), requestOptions) } } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceImpl.kt index 0570df24..df8ba4b5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/sandbox/IndividualServiceImpl.kt @@ -5,6 +5,7 @@ package com.tryfinch.api.services.blocking.sandbox import com.tryfinch.api.core.ClientOptions import com.tryfinch.api.core.JsonValue import com.tryfinch.api.core.RequestOptions +import com.tryfinch.api.core.checkRequired import com.tryfinch.api.core.handlers.errorHandler import com.tryfinch.api.core.handlers.jsonHandler import com.tryfinch.api.core.handlers.withErrorHandler @@ -17,6 +18,7 @@ import com.tryfinch.api.core.http.parseable import com.tryfinch.api.core.prepare import com.tryfinch.api.models.IndividualUpdateResponse import com.tryfinch.api.models.SandboxIndividualUpdateParams +import kotlin.jvm.optionals.getOrNull class IndividualServiceImpl internal constructor(private val clientOptions: ClientOptions) : IndividualService { @@ -47,6 +49,9 @@ class IndividualServiceImpl internal constructor(private val clientOptions: Clie params: SandboxIndividualUpdateParams, requestOptions: RequestOptions, ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("individualId", params.individualId().getOrNull()) val request = HttpRequest.builder() .method(HttpMethod.PUT) 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 861af561..9d4af287 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 @@ -7,7 +7,6 @@ import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync import com.tryfinch.api.models.BenefitFrequency import com.tryfinch.api.models.BenefitType import com.tryfinch.api.models.HrisBenefitCreateParams -import com.tryfinch.api.models.HrisBenefitRetrieveParams import com.tryfinch.api.models.HrisBenefitUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -60,10 +59,7 @@ internal class BenefitServiceAsyncTest { .build() val benefitServiceAsync = client.hris().benefits() - val companyBenefitFuture = - benefitServiceAsync.retrieve( - HrisBenefitRetrieveParams.builder().benefitId("benefit_id").build() - ) + val companyBenefitFuture = benefitServiceAsync.retrieve("benefit_id") val companyBenefit = companyBenefitFuture.get() companyBenefit.validate() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncTest.kt index 5dce15e3..f74a13f5 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncTest.kt @@ -5,7 +5,6 @@ package com.tryfinch.api.services.async.hris import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync import com.tryfinch.api.models.HrisDocumentListParams -import com.tryfinch.api.models.HrisDocumentRetreiveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -44,10 +43,7 @@ internal class DocumentServiceAsyncTest { .build() val documentServiceAsync = client.hris().documents() - val responseFuture = - documentServiceAsync.retreive( - HrisDocumentRetreiveParams.builder().documentId("document_id").build() - ) + val responseFuture = documentServiceAsync.retreive("document_id") val response = responseFuture.get() response.validate() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncTest.kt index 84962f36..f0b0c033 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncTest.kt @@ -4,8 +4,6 @@ package com.tryfinch.api.services.async.hris.benefits import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync -import com.tryfinch.api.models.HrisBenefitIndividualEnrolledIdsParams -import com.tryfinch.api.models.HrisBenefitIndividualRetrieveManyBenefitsParams import com.tryfinch.api.models.HrisBenefitIndividualUnenrollManyParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -22,10 +20,7 @@ internal class IndividualServiceAsyncTest { .build() val individualServiceAsync = client.hris().benefits().individuals() - val responseFuture = - individualServiceAsync.enrolledIds( - HrisBenefitIndividualEnrolledIdsParams.builder().benefitId("benefit_id").build() - ) + val responseFuture = individualServiceAsync.enrolledIds("benefit_id") val response = responseFuture.get() response.validate() @@ -40,12 +35,7 @@ internal class IndividualServiceAsyncTest { .build() val individualServiceAsync = client.hris().benefits().individuals() - val pageFuture = - individualServiceAsync.retrieveManyBenefits( - HrisBenefitIndividualRetrieveManyBenefitsParams.builder() - .benefitId("benefit_id") - .build() - ) + val pageFuture = individualServiceAsync.retrieveManyBenefits("benefit_id") val page = pageFuture.get() page.items().forEach { it.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncTest.kt index d2089357..6ffc6ebb 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncTest.kt @@ -6,7 +6,6 @@ import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync import com.tryfinch.api.core.JsonValue import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleCreateParams -import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleDeleteParams import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -103,10 +102,7 @@ internal class RuleServiceAsyncTest { .build() val ruleServiceAsync = client.hris().company().payStatementItem().rules() - val ruleFuture = - ruleServiceAsync.delete( - HrisCompanyPayStatementItemRuleDeleteParams.builder().ruleId("rule_id").build() - ) + val ruleFuture = ruleServiceAsync.delete("rule_id") val rule = ruleFuture.get() rule.validate() 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 ac39efe6..68909572 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 @@ -6,7 +6,6 @@ import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync import com.tryfinch.api.models.JobAutomatedCreateParams import com.tryfinch.api.models.JobAutomatedListParams -import com.tryfinch.api.models.JobAutomatedRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -40,10 +39,7 @@ internal class AutomatedServiceAsyncTest { .build() val automatedServiceAsync = client.jobs().automated() - val automatedAsyncJobFuture = - automatedServiceAsync.retrieve( - JobAutomatedRetrieveParams.builder().jobId("job_id").build() - ) + val automatedAsyncJobFuture = automatedServiceAsync.retrieve("job_id") val automatedAsyncJob = automatedAsyncJobFuture.get() automatedAsyncJob.validate() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncTest.kt index 5a095fad..87d73cfa 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/jobs/ManualServiceAsyncTest.kt @@ -4,7 +4,6 @@ package com.tryfinch.api.services.async.jobs import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync -import com.tryfinch.api.models.JobManualRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -20,8 +19,7 @@ internal class ManualServiceAsyncTest { .build() val manualServiceAsync = client.jobs().manual() - val manualAsyncJobFuture = - manualServiceAsync.retrieve(JobManualRetrieveParams.builder().jobId("job_id").build()) + val manualAsyncJobFuture = manualServiceAsync.retrieve("job_id") val manualAsyncJob = manualAsyncJobFuture.get() manualAsyncJob.validate() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncTest.kt index 6e52fb2f..c280c299 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncTest.kt @@ -4,7 +4,6 @@ package com.tryfinch.api.services.async.payroll import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClientAsync -import com.tryfinch.api.models.PayrollPayGroupRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -20,10 +19,7 @@ internal class PayGroupServiceAsyncTest { .build() val payGroupServiceAsync = client.payroll().payGroups() - val payGroupFuture = - payGroupServiceAsync.retrieve( - PayrollPayGroupRetrieveParams.builder().payGroupId("pay_group_id").build() - ) + val payGroupFuture = payGroupServiceAsync.retrieve("pay_group_id") val payGroup = payGroupFuture.get() payGroup.validate() 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 bdcc2d7f..ff54482a 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 @@ -7,7 +7,6 @@ import com.tryfinch.api.client.okhttp.FinchOkHttpClient import com.tryfinch.api.models.BenefitFrequency import com.tryfinch.api.models.BenefitType import com.tryfinch.api.models.HrisBenefitCreateParams -import com.tryfinch.api.models.HrisBenefitRetrieveParams import com.tryfinch.api.models.HrisBenefitUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -59,10 +58,7 @@ internal class BenefitServiceTest { .build() val benefitService = client.hris().benefits() - val companyBenefit = - benefitService.retrieve( - HrisBenefitRetrieveParams.builder().benefitId("benefit_id").build() - ) + val companyBenefit = benefitService.retrieve("benefit_id") companyBenefit.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceTest.kt index 4faa8f0a..b5a9adbe 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/DocumentServiceTest.kt @@ -5,7 +5,6 @@ package com.tryfinch.api.services.blocking.hris import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient import com.tryfinch.api.models.HrisDocumentListParams -import com.tryfinch.api.models.HrisDocumentRetreiveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -43,10 +42,7 @@ internal class DocumentServiceTest { .build() val documentService = client.hris().documents() - val response = - documentService.retreive( - HrisDocumentRetreiveParams.builder().documentId("document_id").build() - ) + val response = documentService.retreive("document_id") response.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceTest.kt index 911b8d1e..123e975c 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/benefits/IndividualServiceTest.kt @@ -4,8 +4,6 @@ package com.tryfinch.api.services.blocking.hris.benefits import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient -import com.tryfinch.api.models.HrisBenefitIndividualEnrolledIdsParams -import com.tryfinch.api.models.HrisBenefitIndividualRetrieveManyBenefitsParams import com.tryfinch.api.models.HrisBenefitIndividualUnenrollManyParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -22,10 +20,7 @@ internal class IndividualServiceTest { .build() val individualService = client.hris().benefits().individuals() - val response = - individualService.enrolledIds( - HrisBenefitIndividualEnrolledIdsParams.builder().benefitId("benefit_id").build() - ) + val response = individualService.enrolledIds("benefit_id") response.validate() } @@ -39,12 +34,7 @@ internal class IndividualServiceTest { .build() val individualService = client.hris().benefits().individuals() - val page = - individualService.retrieveManyBenefits( - HrisBenefitIndividualRetrieveManyBenefitsParams.builder() - .benefitId("benefit_id") - .build() - ) + val page = individualService.retrieveManyBenefits("benefit_id") page.items().forEach { it.validate() } } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceTest.kt index be36e133..079a3329 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/hris/company/payStatementItem/RuleServiceTest.kt @@ -6,7 +6,6 @@ import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient import com.tryfinch.api.core.JsonValue import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleCreateParams -import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleDeleteParams import com.tryfinch.api.models.HrisCompanyPayStatementItemRuleUpdateParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -100,10 +99,7 @@ internal class RuleServiceTest { .build() val ruleService = client.hris().company().payStatementItem().rules() - val rule = - ruleService.delete( - HrisCompanyPayStatementItemRuleDeleteParams.builder().ruleId("rule_id").build() - ) + val rule = ruleService.delete("rule_id") rule.validate() } 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 e6ff60ac..e4121bc5 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 @@ -6,7 +6,6 @@ import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient import com.tryfinch.api.models.JobAutomatedCreateParams import com.tryfinch.api.models.JobAutomatedListParams -import com.tryfinch.api.models.JobAutomatedRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -37,8 +36,7 @@ internal class AutomatedServiceTest { .build() val automatedService = client.jobs().automated() - val automatedAsyncJob = - automatedService.retrieve(JobAutomatedRetrieveParams.builder().jobId("job_id").build()) + val automatedAsyncJob = automatedService.retrieve("job_id") automatedAsyncJob.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceTest.kt index 3ad62102..3ee64260 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/jobs/ManualServiceTest.kt @@ -4,7 +4,6 @@ package com.tryfinch.api.services.blocking.jobs import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient -import com.tryfinch.api.models.JobManualRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -20,8 +19,7 @@ internal class ManualServiceTest { .build() val manualService = client.jobs().manual() - val manualAsyncJob = - manualService.retrieve(JobManualRetrieveParams.builder().jobId("job_id").build()) + val manualAsyncJob = manualService.retrieve("job_id") manualAsyncJob.validate() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceTest.kt index b64d3e99..f8581c22 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/payroll/PayGroupServiceTest.kt @@ -4,7 +4,6 @@ package com.tryfinch.api.services.blocking.payroll import com.tryfinch.api.TestServerExtension import com.tryfinch.api.client.okhttp.FinchOkHttpClient -import com.tryfinch.api.models.PayrollPayGroupRetrieveParams import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -20,10 +19,7 @@ internal class PayGroupServiceTest { .build() val payGroupService = client.payroll().payGroups() - val payGroup = - payGroupService.retrieve( - PayrollPayGroupRetrieveParams.builder().payGroupId("pay_group_id").build() - ) + val payGroup = payGroupService.retrieve("pay_group_id") payGroup.validate() } From c4a8874a3f7799b0d689beaafd00cf1a3727f0ea Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 8 May 2025 23:51:39 +0000 Subject: [PATCH 2/6] feat(client)!: extract auto pagination to shared classes refactor(client)!: refactor async auto-pagination refactor(client)!: rename `getNextPage{,Params}` to `nextPage{,Params}` refactor(client)!: swap `nextPage{,Params}` to return non-optional # Migration - If you were referencing the `AutoPager` class on a specific `*Page` or `*PageAsync` type, then you should instead reference the shared `AutoPager` and `AutoPagerAsync` types, under the `core` package - `AutoPagerAsync` now has different usage. You can call `.subscribe(...)` on the returned object instead to get called back each page item. You can also call `onCompleteFuture()` to get a future that completes when all items have been processed. Finally, you can call `.close()` on the returned object to stop auto-paginating early - If you were referencing `getNextPage` or `getNextPageParams`: - Swap to `nextPage()` and `nextPageParams()` - Note that these both now return non-optional types (use `hasNextPage()` before calling these, since they will throw if it's impossible to get another page) There are examples and further information about pagination in the readme. --- README.md | 84 ++++-- .../api/client/okhttp/FinchOkHttpClient.kt | 5 + .../client/okhttp/FinchOkHttpClientAsync.kt | 5 + .../kotlin/com/tryfinch/api/core/AutoPager.kt | 21 ++ .../com/tryfinch/api/core/AutoPagerAsync.kt | 88 ++++++ .../com/tryfinch/api/core/ClientOptions.kt | 26 ++ .../main/kotlin/com/tryfinch/api/core/Page.kt | 33 +++ .../kotlin/com/tryfinch/api/core/PageAsync.kt | 35 +++ .../api/core/http/AsyncStreamResponse.kt | 157 ++++++++++ ...ntomReachableClosingAsyncStreamResponse.kt | 56 ++++ .../PhantomReachableClosingStreamResponse.kt | 21 ++ .../tryfinch/api/core/http/StreamResponse.kt | 19 ++ ...nefitIndividualRetrieveManyBenefitsPage.kt | 42 +-- ...IndividualRetrieveManyBenefitsPageAsync.kt | 71 ++--- .../api/models/HrisBenefitListPage.kt | 38 +-- .../api/models/HrisBenefitListPageAsync.kt | 67 ++--- .../HrisBenefitListSupportedBenefitsPage.kt | 39 +-- ...isBenefitListSupportedBenefitsPageAsync.kt | 68 ++--- .../HrisCompanyPayStatementItemListPage.kt | 39 +-- ...risCompanyPayStatementItemListPageAsync.kt | 67 ++--- ...HrisCompanyPayStatementItemRuleListPage.kt | 40 +-- ...ompanyPayStatementItemRuleListPageAsync.kt | 68 ++--- .../HrisDirectoryListIndividualsPage.kt | 48 +--- .../HrisDirectoryListIndividualsPageAsync.kt | 75 ++--- .../api/models/HrisDirectoryListPage.kt | 47 +-- .../api/models/HrisDirectoryListPageAsync.kt | 75 ++--- .../models/HrisEmploymentRetrieveManyPage.kt | 39 +-- .../HrisEmploymentRetrieveManyPageAsync.kt | 67 ++--- .../models/HrisIndividualRetrieveManyPage.kt | 39 +-- .../HrisIndividualRetrieveManyPageAsync.kt | 67 ++--- .../HrisPayStatementRetrieveManyPage.kt | 40 +-- .../HrisPayStatementRetrieveManyPageAsync.kt | 67 ++--- .../api/models/HrisPaymentListPage.kt | 38 +-- .../api/models/HrisPaymentListPageAsync.kt | 63 ++-- .../api/models/PayrollPayGroupListPage.kt | 40 +-- .../models/PayrollPayGroupListPageAsync.kt | 67 ++--- .../tryfinch/api/models/ProviderListPage.kt | 38 +-- .../api/models/ProviderListPageAsync.kt | 63 ++-- .../async/ProviderServiceAsyncImpl.kt | 1 + .../async/hris/BenefitServiceAsyncImpl.kt | 2 + .../async/hris/DirectoryServiceAsyncImpl.kt | 2 + .../async/hris/EmploymentServiceAsyncImpl.kt | 1 + .../async/hris/IndividualServiceAsyncImpl.kt | 1 + .../hris/PayStatementServiceAsyncImpl.kt | 1 + .../async/hris/PaymentServiceAsyncImpl.kt | 1 + .../benefits/IndividualServiceAsyncImpl.kt | 1 + .../PayStatementItemServiceAsyncImpl.kt | 1 + .../payStatementItem/RuleServiceAsyncImpl.kt | 1 + .../async/payroll/PayGroupServiceAsyncImpl.kt | 1 + .../tryfinch/api/core/AutoPagerAsyncTest.kt | 182 ++++++++++++ .../com/tryfinch/api/core/AutoPagerTest.kt | 41 +++ .../api/core/http/AsyncStreamResponseTest.kt | 268 ++++++++++++++++++ 52 files changed, 1491 insertions(+), 975 deletions(-) create mode 100644 finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPager.kt create mode 100644 finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPagerAsync.kt create mode 100644 finch-java-core/src/main/kotlin/com/tryfinch/api/core/Page.kt create mode 100644 finch-java-core/src/main/kotlin/com/tryfinch/api/core/PageAsync.kt create mode 100644 finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/AsyncStreamResponse.kt create mode 100644 finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt create mode 100644 finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingStreamResponse.kt create mode 100644 finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/StreamResponse.kt create mode 100644 finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerAsyncTest.kt create mode 100644 finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerTest.kt create mode 100644 finch-java-core/src/test/kotlin/com/tryfinch/api/core/http/AsyncStreamResponseTest.kt diff --git a/README.md b/README.md index fe0a5e8d..73331d8e 100644 --- a/README.md +++ b/README.md @@ -219,53 +219,101 @@ The SDK throws custom unchecked exception types: ## Pagination -For methods that return a paginated list of results, this library provides convenient ways access the results either one page at a time, or item-by-item across all pages. +The SDK defines methods that return a paginated lists of results. It provides convenient ways to access the results either one page at a time or item-by-item across all pages. ### Auto-pagination -To iterate through all results across all pages, you can use `autoPager`, which automatically handles fetching more pages for you: +To iterate through all results across all pages, use the `autoPager()` method, which automatically fetches more pages as needed. -### Synchronous +When using the synchronous client, the method returns an [`Iterable`](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html) ```java import com.tryfinch.api.models.HrisDirectoryListPage; import com.tryfinch.api.models.IndividualInDirectory; -// As an Iterable: -HrisDirectoryListPage page = client.hris().directory().list(params); +HrisDirectoryListPage page = client.hris().directory().list(); + +// Process as an Iterable for (IndividualInDirectory directory : page.autoPager()) { System.out.println(directory); -}; +} -// As a Stream: -client.hris().directory().list(params).autoPager().stream() +// Process as a Stream +page.autoPager() + .stream() .limit(50) .forEach(directory -> System.out.println(directory)); ``` -### Asynchronous +When using the asynchronous client, the method returns an [`AsyncStreamResponse`](finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/AsyncStreamResponse.kt): ```java -// Using forEach, which returns CompletableFuture: -asyncClient.hris().directory().list(params).autoPager() - .forEach(directory -> System.out.println(directory), executor); +import com.tryfinch.api.core.http.AsyncStreamResponse; +import com.tryfinch.api.models.HrisDirectoryListPageAsync; +import com.tryfinch.api.models.IndividualInDirectory; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +CompletableFuture pageFuture = client.async().hris().directory().list(); + +pageFuture.thenRun(page -> page.autoPager().subscribe(directory -> { + System.out.println(directory); +})); + +// If you need to handle errors or completion of the stream +pageFuture.thenRun(page -> page.autoPager().subscribe(new AsyncStreamResponse.Handler<>() { + @Override + public void onNext(IndividualInDirectory directory) { + System.out.println(directory); + } + + @Override + public void onComplete(Optional error) { + if (error.isPresent()) { + System.out.println("Something went wrong!"); + throw new RuntimeException(error.get()); + } else { + System.out.println("No more!"); + } + } +})); + +// Or use futures +pageFuture.thenRun(page -> page.autoPager() + .subscribe(directory -> { + System.out.println(directory); + }) + .onCompleteFuture() + .whenComplete((unused, error) -> { + if (error != null) { + System.out.println("Something went wrong!"); + throw new RuntimeException(error); + } else { + System.out.println("No more!"); + } + })); ``` ### Manual pagination -If none of the above helpers meet your needs, you can also manually request pages one-by-one. A page of results has a `data()` method to fetch the list of objects, as well as top-level `response` and other methods to fetch top-level data about the page. It also has methods `hasNextPage`, `getNextPage`, and `getNextPageParams` methods to help with pagination. +To access individual page items and manually request the next page, use the `items()`, +`hasNextPage()`, and `nextPage()` methods: ```java import com.tryfinch.api.models.HrisDirectoryListPage; import com.tryfinch.api.models.IndividualInDirectory; -HrisDirectoryListPage page = client.hris().directory().list(params); -while (page != null) { - for (IndividualInDirectory directory : page.individuals()) { +HrisDirectoryListPage page = client.hris().directory().list(); +while (true) { + for (IndividualInDirectory directory : page.items()) { System.out.println(directory); } - page = page.getNextPage().orElse(null); + if (!page.hasNextPage()) { + break; + } + + page = page.nextPage(); } ``` @@ -343,7 +391,6 @@ To set a custom timeout, configure the method call using the `timeout` method: ```java import com.tryfinch.api.models.HrisDirectoryListPage; -import com.tryfinch.api.models.HrisDirectoryListParams; HrisDirectoryListPage page = client.hris().directory().list(RequestOptions.builder().timeout(Duration.ofSeconds(30)).build()); ``` @@ -573,7 +620,6 @@ Or configure the method call to validate the response using the `responseValidat ```java import com.tryfinch.api.models.HrisDirectoryListPage; -import com.tryfinch.api.models.HrisDirectoryListParams; HrisDirectoryListPage page = client.hris().directory().list(RequestOptions.builder().responseValidation(true).build()); ``` diff --git a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt index 625e6cac..21e1d896 100644 --- a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt +++ b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt @@ -13,6 +13,7 @@ import java.net.Proxy import java.time.Clock import java.time.Duration import java.util.Optional +import java.util.concurrent.Executor import kotlin.jvm.optionals.getOrNull class FinchOkHttpClient private constructor() { @@ -47,6 +48,10 @@ class FinchOkHttpClient private constructor() { fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + clientOptions.streamHandlerExecutor(streamHandlerExecutor) + } + fun clock(clock: Clock) = apply { clientOptions.clock(clock) } fun headers(headers: Headers) = apply { clientOptions.headers(headers) } diff --git a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt index b8aac548..ecfb663d 100644 --- a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt +++ b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt @@ -13,6 +13,7 @@ import java.net.Proxy import java.time.Clock import java.time.Duration import java.util.Optional +import java.util.concurrent.Executor import kotlin.jvm.optionals.getOrNull class FinchOkHttpClientAsync private constructor() { @@ -47,6 +48,10 @@ class FinchOkHttpClientAsync private constructor() { fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + clientOptions.streamHandlerExecutor(streamHandlerExecutor) + } + fun clock(clock: Clock) = apply { clientOptions.clock(clock) } fun headers(headers: Headers) = apply { clientOptions.headers(headers) } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPager.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPager.kt new file mode 100644 index 00000000..4ec6210a --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPager.kt @@ -0,0 +1,21 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +import java.util.stream.Stream +import java.util.stream.StreamSupport + +class AutoPager private constructor(private val firstPage: Page) : Iterable { + + companion object { + + fun from(firstPage: Page): AutoPager = AutoPager(firstPage) + } + + override fun iterator(): Iterator = + generateSequence(firstPage) { if (it.hasNextPage()) it.nextPage() else null } + .flatMap { it.items() } + .iterator() + + fun stream(): Stream = StreamSupport.stream(spliterator(), false) +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPagerAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPagerAsync.kt new file mode 100644 index 00000000..a2b37a0b --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/AutoPagerAsync.kt @@ -0,0 +1,88 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +import com.tryfinch.api.core.http.AsyncStreamResponse +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.CompletionException +import java.util.concurrent.Executor +import java.util.concurrent.atomic.AtomicReference + +class AutoPagerAsync +private constructor(private val firstPage: PageAsync, private val defaultExecutor: Executor) : + AsyncStreamResponse { + + companion object { + + fun from(firstPage: PageAsync, defaultExecutor: Executor): AutoPagerAsync = + AutoPagerAsync(firstPage, defaultExecutor) + } + + private val onCompleteFuture = CompletableFuture() + private val state = AtomicReference(State.NEW) + + override fun subscribe(handler: AsyncStreamResponse.Handler): AsyncStreamResponse = + subscribe(handler, defaultExecutor) + + override fun subscribe( + handler: AsyncStreamResponse.Handler, + executor: Executor, + ): AsyncStreamResponse = apply { + // TODO(JDK): Use `compareAndExchange` once targeting JDK 9. + check(state.compareAndSet(State.NEW, State.SUBSCRIBED)) { + if (state.get() == State.SUBSCRIBED) "Cannot subscribe more than once" + else "Cannot subscribe after the response is closed" + } + + fun PageAsync.handle(): CompletableFuture { + if (state.get() == State.CLOSED) { + return CompletableFuture.completedFuture(null) + } + + items().forEach { handler.onNext(it) } + return if (hasNextPage()) nextPage().thenCompose { it.handle() } + else CompletableFuture.completedFuture(null) + } + + executor.execute { + firstPage.handle().whenComplete { _, error -> + val actualError = + if (error is CompletionException && error.cause != null) error.cause else error + try { + handler.onComplete(Optional.ofNullable(actualError)) + } finally { + try { + if (actualError == null) { + onCompleteFuture.complete(null) + } else { + onCompleteFuture.completeExceptionally(actualError) + } + } finally { + close() + } + } + } + } + } + + override fun onCompleteFuture(): CompletableFuture = onCompleteFuture + + override fun close() { + val previousState = state.getAndSet(State.CLOSED) + if (previousState == State.CLOSED) { + return + } + + // When the stream is closed, we should always consider it closed. If it closed due + // to an error, then we will have already completed the future earlier, and this + // will be a no-op. + onCompleteFuture.complete(null) + } +} + +private enum class State { + NEW, + SUBSCRIBED, + CLOSED, +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt index 8a9abd9c..cfdb5e56 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt @@ -11,6 +11,10 @@ import com.tryfinch.api.core.http.RetryingHttpClient import java.time.Clock import java.util.Base64 import java.util.Optional +import java.util.concurrent.Executor +import java.util.concurrent.Executors +import java.util.concurrent.ThreadFactory +import java.util.concurrent.atomic.AtomicLong import kotlin.jvm.optionals.getOrNull class ClientOptions @@ -19,6 +23,7 @@ private constructor( @get:JvmName("httpClient") val httpClient: HttpClient, @get:JvmName("checkJacksonVersionCompatibility") val checkJacksonVersionCompatibility: Boolean, @get:JvmName("jsonMapper") val jsonMapper: JsonMapper, + @get:JvmName("streamHandlerExecutor") val streamHandlerExecutor: Executor, @get:JvmName("clock") val clock: Clock, @get:JvmName("baseUrl") val baseUrl: String, @get:JvmName("headers") val headers: Headers, @@ -71,6 +76,7 @@ private constructor( private var httpClient: HttpClient? = null private var checkJacksonVersionCompatibility: Boolean = true private var jsonMapper: JsonMapper = jsonMapper() + private var streamHandlerExecutor: Executor? = null private var clock: Clock = Clock.systemUTC() private var baseUrl: String = PRODUCTION_URL private var headers: Headers.Builder = Headers.builder() @@ -88,6 +94,7 @@ private constructor( httpClient = clientOptions.originalHttpClient checkJacksonVersionCompatibility = clientOptions.checkJacksonVersionCompatibility jsonMapper = clientOptions.jsonMapper + streamHandlerExecutor = clientOptions.streamHandlerExecutor clock = clientOptions.clock baseUrl = clientOptions.baseUrl headers = clientOptions.headers.toBuilder() @@ -109,6 +116,10 @@ private constructor( fun jsonMapper(jsonMapper: JsonMapper) = apply { this.jsonMapper = jsonMapper } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + fun clock(clock: Clock) = apply { this.clock = clock } fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl } @@ -285,6 +296,21 @@ private constructor( ), checkJacksonVersionCompatibility, jsonMapper, + streamHandlerExecutor + ?: Executors.newCachedThreadPool( + object : ThreadFactory { + + private val threadFactory: ThreadFactory = + Executors.defaultThreadFactory() + private val count = AtomicLong(0) + + override fun newThread(runnable: Runnable): Thread = + threadFactory.newThread(runnable).also { + it.name = + "finch-stream-handler-thread-${count.getAndIncrement()}" + } + } + ), clock, baseUrl, headers.build(), diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Page.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Page.kt new file mode 100644 index 00000000..456d2b6f --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/Page.kt @@ -0,0 +1,33 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +/** + * An interface representing a single page, with items of type [T], from a paginated endpoint + * response. + * + * Implementations of this interface are expected to request additional pages synchronously. For + * asynchronous pagination, see the [PageAsync] interface. + */ +interface Page { + + /** + * Returns whether there's another page after this one. + * + * The method generally doesn't make requests so the result depends entirely on the data in this + * page. If a significant amount of time has passed between requesting this page and calling + * this method, then the result could be stale. + */ + fun hasNextPage(): Boolean + + /** + * Returns the page after this one by making another request. + * + * @throws IllegalStateException if it's impossible to get the next page. This exception is + * avoidable by calling [hasNextPage] first. + */ + fun nextPage(): Page + + /** Returns the items in this page. */ + fun items(): List +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/PageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/PageAsync.kt new file mode 100644 index 00000000..366bfede --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/PageAsync.kt @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +import java.util.concurrent.CompletableFuture + +/** + * An interface representing a single page, with items of type [T], from a paginated endpoint + * response. + * + * Implementations of this interface are expected to request additional pages asynchronously. For + * synchronous pagination, see the [Page] interface. + */ +interface PageAsync { + + /** + * Returns whether there's another page after this one. + * + * The method generally doesn't make requests so the result depends entirely on the data in this + * page. If a significant amount of time has passed between requesting this page and calling + * this method, then the result could be stale. + */ + fun hasNextPage(): Boolean + + /** + * Returns the page after this one by making another request. + * + * @throws IllegalStateException if it's impossible to get the next page. This exception is + * avoidable by calling [hasNextPage] first. + */ + fun nextPage(): CompletableFuture> + + /** Returns the items in this page. */ + fun items(): List +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/AsyncStreamResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/AsyncStreamResponse.kt new file mode 100644 index 00000000..a86ddffd --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/AsyncStreamResponse.kt @@ -0,0 +1,157 @@ +package com.tryfinch.api.core.http + +import com.tryfinch.api.core.http.AsyncStreamResponse.Handler +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.concurrent.atomic.AtomicReference + +/** + * A class providing access to an API response as an asynchronous stream of chunks of type [T], + * where each chunk can be individually processed as soon as it arrives instead of waiting on the + * full response. + */ +interface AsyncStreamResponse { + + /** + * Registers [handler] to be called for events of this stream. + * + * [handler]'s methods will be called in the client's configured or default thread pool. + * + * @throws IllegalStateException if [subscribe] has already been called. + */ + fun subscribe(handler: Handler): AsyncStreamResponse + + /** + * Registers [handler] to be called for events of this stream. + * + * [handler]'s methods will be called in the given [executor]. + * + * @throws IllegalStateException if [subscribe] has already been called. + */ + fun subscribe(handler: Handler, executor: Executor): AsyncStreamResponse + + /** + * Returns a future that completes when a stream is fully consumed, errors, or gets closed + * early. + */ + fun onCompleteFuture(): CompletableFuture + + /** + * Closes this resource, relinquishing any underlying resources. + * + * This is purposefully not inherited from [AutoCloseable] because this response should not be + * synchronously closed via try-with-resources. + */ + fun close() + + /** A class for handling streaming events. */ + fun interface Handler { + + /** Called whenever a chunk is received. */ + fun onNext(value: T) + + /** + * Called when a stream is fully consumed, errors, or gets closed early. + * + * [onNext] will not be called once this method is called. + * + * @param error Non-empty if the stream completed due to an error. + */ + fun onComplete(error: Optional) {} + } +} + +@JvmSynthetic +internal fun CompletableFuture>.toAsync(streamHandlerExecutor: Executor) = + PhantomReachableClosingAsyncStreamResponse( + object : AsyncStreamResponse { + + private val onCompleteFuture = CompletableFuture() + private val state = AtomicReference(State.NEW) + + init { + this@toAsync.whenComplete { _, error -> + // If an error occurs from the original future, then we should resolve the + // `onCompleteFuture` even if `subscribe` has not been called. + error?.let(onCompleteFuture::completeExceptionally) + } + } + + override fun subscribe(handler: Handler): AsyncStreamResponse = + subscribe(handler, streamHandlerExecutor) + + override fun subscribe( + handler: Handler, + executor: Executor, + ): AsyncStreamResponse = apply { + // TODO(JDK): Use `compareAndExchange` once targeting JDK 9. + check(state.compareAndSet(State.NEW, State.SUBSCRIBED)) { + if (state.get() == State.SUBSCRIBED) "Cannot subscribe more than once" + else "Cannot subscribe after the response is closed" + } + + this@toAsync.whenCompleteAsync( + { streamResponse, futureError -> + if (state.get() == State.CLOSED) { + // Avoid doing any work if `close` was called before the future + // completed. + return@whenCompleteAsync + } + + if (futureError != null) { + // An error occurred before we started passing chunks to the handler. + handler.onComplete(Optional.of(futureError)) + return@whenCompleteAsync + } + + var streamError: Throwable? = null + try { + streamResponse.stream().forEach(handler::onNext) + } catch (e: Throwable) { + streamError = e + } + + try { + handler.onComplete(Optional.ofNullable(streamError)) + } finally { + try { + // Notify completion via the `onCompleteFuture` as well. This is in + // a separate `try-finally` block so that we still complete the + // future if `handler.onComplete` throws. + if (streamError == null) { + onCompleteFuture.complete(null) + } else { + onCompleteFuture.completeExceptionally(streamError) + } + } finally { + close() + } + } + }, + executor, + ) + } + + override fun onCompleteFuture(): CompletableFuture = onCompleteFuture + + override fun close() { + val previousState = state.getAndSet(State.CLOSED) + if (previousState == State.CLOSED) { + return + } + + this@toAsync.whenComplete { streamResponse, error -> streamResponse?.close() } + // When the stream is closed, we should always consider it closed. If it closed due + // to an error, then we will have already completed the future earlier, and this + // will be a no-op. + onCompleteFuture.complete(null) + } + } + ) + +private enum class State { + NEW, + SUBSCRIBED, + CLOSED, +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt new file mode 100644 index 00000000..deca7d02 --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt @@ -0,0 +1,56 @@ +package com.tryfinch.api.core.http + +import com.tryfinch.api.core.closeWhenPhantomReachable +import com.tryfinch.api.core.http.AsyncStreamResponse.Handler +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor + +/** + * A delegating wrapper around an `AsyncStreamResponse` that closes it once it's only phantom + * reachable. + * + * This class ensures the `AsyncStreamResponse` is closed even if the user forgets to close it. + */ +internal class PhantomReachableClosingAsyncStreamResponse( + private val asyncStreamResponse: AsyncStreamResponse +) : AsyncStreamResponse { + + /** + * An object used for keeping `asyncStreamResponse` open while the object is still reachable. + */ + private val reachabilityTracker = Object() + + init { + closeWhenPhantomReachable(reachabilityTracker, asyncStreamResponse::close) + } + + override fun subscribe(handler: Handler): AsyncStreamResponse = apply { + asyncStreamResponse.subscribe(TrackedHandler(handler, reachabilityTracker)) + } + + override fun subscribe(handler: Handler, executor: Executor): AsyncStreamResponse = + apply { + asyncStreamResponse.subscribe(TrackedHandler(handler, reachabilityTracker), executor) + } + + override fun onCompleteFuture(): CompletableFuture = + asyncStreamResponse.onCompleteFuture() + + override fun close() = asyncStreamResponse.close() +} + +/** + * A wrapper around a `Handler` that also references a `reachabilityTracker` object. + * + * Referencing the `reachabilityTracker` object prevents it from getting reclaimed while the handler + * is still reachable. + */ +private class TrackedHandler( + private val handler: Handler, + private val reachabilityTracker: Any, +) : Handler { + override fun onNext(value: T) = handler.onNext(value) + + override fun onComplete(error: Optional) = handler.onComplete(error) +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingStreamResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingStreamResponse.kt new file mode 100644 index 00000000..f23638aa --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/PhantomReachableClosingStreamResponse.kt @@ -0,0 +1,21 @@ +package com.tryfinch.api.core.http + +import com.tryfinch.api.core.closeWhenPhantomReachable +import java.util.stream.Stream + +/** + * A delegating wrapper around a `StreamResponse` that closes it once it's only phantom reachable. + * + * This class ensures the `StreamResponse` is closed even if the user forgets to close it. + */ +internal class PhantomReachableClosingStreamResponse( + private val streamResponse: StreamResponse +) : StreamResponse { + init { + closeWhenPhantomReachable(this, streamResponse) + } + + override fun stream(): Stream = streamResponse.stream() + + override fun close() = streamResponse.close() +} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/StreamResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/StreamResponse.kt new file mode 100644 index 00000000..89acf0ef --- /dev/null +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/StreamResponse.kt @@ -0,0 +1,19 @@ +package com.tryfinch.api.core.http + +import java.util.stream.Stream + +interface StreamResponse : AutoCloseable { + + fun stream(): Stream + + /** Overridden from [AutoCloseable] to not have a checked exception in its signature. */ + override fun close() +} + +@JvmSynthetic +internal fun StreamResponse.map(transform: (T) -> R): StreamResponse = + object : StreamResponse { + override fun stream(): Stream = this@map.stream().map(transform) + + override fun close() = this@map.close() + } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPage.kt index b5773d4e..dfc47dd0 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPage.kt @@ -2,13 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.benefits.IndividualService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport -import kotlin.jvm.optionals.getOrNull /** @see [IndividualService.retrieveManyBenefits] */ class HrisBenefitIndividualRetrieveManyBenefitsPage @@ -16,23 +14,23 @@ private constructor( private val service: IndividualService, private val params: HrisBenefitIndividualRetrieveManyBenefitsParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = - Optional.empty() + fun nextPageParams(): HrisBenefitIndividualRetrieveManyBenefitsParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = - getNextPageParams().map { service.retrieveManyBenefits(it) } + override fun nextPage(): HrisBenefitIndividualRetrieveManyBenefitsPage = + service.retrieveManyBenefits(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisBenefitIndividualRetrieveManyBenefitsParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -101,26 +99,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisBenefitIndividualRetrieveManyBenefitsPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPageAsync.kt index 1d164078..85f9ba74 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitIndividualRetrieveManyBenefitsPageAsync.kt @@ -2,40 +2,39 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.benefits.IndividualServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate /** @see [IndividualServiceAsync.retrieveManyBenefits] */ class HrisBenefitIndividualRetrieveManyBenefitsPageAsync private constructor( private val service: IndividualServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisBenefitIndividualRetrieveManyBenefitsParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = - Optional.empty() + fun nextPageParams(): HrisBenefitIndividualRetrieveManyBenefitsParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): - CompletableFuture> = - getNextPageParams() - .map { service.retrieveManyBenefits(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.retrieveManyBenefits(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisBenefitIndividualRetrieveManyBenefitsParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -48,6 +47,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -59,6 +59,7 @@ private constructor( class Builder internal constructor() { private var service: IndividualServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisBenefitIndividualRetrieveManyBenefitsParams? = null private var items: List? = null @@ -68,12 +69,18 @@ private constructor( HrisBenefitIndividualRetrieveManyBenefitsPageAsync ) = apply { service = hrisBenefitIndividualRetrieveManyBenefitsPageAsync.service + streamHandlerExecutor = + hrisBenefitIndividualRetrieveManyBenefitsPageAsync.streamHandlerExecutor params = hrisBenefitIndividualRetrieveManyBenefitsPageAsync.params items = hrisBenefitIndividualRetrieveManyBenefitsPageAsync.items } fun service(service: IndividualServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisBenefitIndividualRetrieveManyBenefitsParams) = apply { this.params = params @@ -90,6 +97,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -99,51 +107,22 @@ private constructor( fun build(): HrisBenefitIndividualRetrieveManyBenefitsPageAsync = HrisBenefitIndividualRetrieveManyBenefitsPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items), ) } - class AutoPager(private val firstPage: HrisBenefitIndividualRetrieveManyBenefitsPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture> - .forEach( - action: (IndividualBenefit) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisBenefitIndividualRetrieveManyBenefitsPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is HrisBenefitIndividualRetrieveManyBenefitsPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "HrisBenefitIndividualRetrieveManyBenefitsPageAsync{service=$service, params=$params, items=$items}" + "HrisBenefitIndividualRetrieveManyBenefitsPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPage.kt index 7b00ce90..fbcf2ff6 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPage.kt @@ -2,13 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.BenefitService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport -import kotlin.jvm.optionals.getOrNull /** @see [BenefitService.list] */ class HrisBenefitListPage @@ -16,21 +14,22 @@ private constructor( private val service: BenefitService, private val params: HrisBenefitListParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisBenefitListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): HrisBenefitListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisBenefitListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -93,25 +92,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisBenefitListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPageAsync.kt index f49f49a4..9cd78291 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListPageAsync.kt @@ -2,38 +2,39 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.BenefitServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate /** @see [BenefitServiceAsync.list] */ class HrisBenefitListPageAsync private constructor( private val service: BenefitServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisBenefitListParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisBenefitListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisBenefitListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -45,6 +46,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -56,18 +58,24 @@ private constructor( class Builder internal constructor() { private var service: BenefitServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisBenefitListParams? = null private var items: List? = null @JvmSynthetic internal fun from(hrisBenefitListPageAsync: HrisBenefitListPageAsync) = apply { service = hrisBenefitListPageAsync.service + streamHandlerExecutor = hrisBenefitListPageAsync.streamHandlerExecutor params = hrisBenefitListPageAsync.params items = hrisBenefitListPageAsync.items } fun service(service: BenefitServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisBenefitListParams) = apply { this.params = params } @@ -82,6 +90,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -91,50 +100,22 @@ private constructor( fun build(): HrisBenefitListPageAsync = HrisBenefitListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items), ) } - class AutoPager(private val firstPage: HrisBenefitListPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (CompanyBenefit) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisBenefitListPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is HrisBenefitListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "HrisBenefitListPageAsync{service=$service, params=$params, items=$items}" + "HrisBenefitListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPage.kt index 147d1698..3409c4b3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPage.kt @@ -2,12 +2,12 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.BenefitService import java.util.Objects import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [BenefitService.listSupportedBenefits] */ @@ -16,22 +16,23 @@ private constructor( private val service: BenefitService, private val params: HrisBenefitListSupportedBenefitsParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisBenefitListSupportedBenefitsParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = - getNextPageParams().map { service.listSupportedBenefits(it) } + override fun nextPage(): HrisBenefitListSupportedBenefitsPage = + service.listSupportedBenefits(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisBenefitListSupportedBenefitsParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -99,26 +100,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisBenefitListSupportedBenefitsPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPageAsync.kt index 859239d8..3f3abf51 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisBenefitListSupportedBenefitsPageAsync.kt @@ -2,39 +2,41 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.BenefitServiceAsync import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [BenefitServiceAsync.listSupportedBenefits] */ class HrisBenefitListSupportedBenefitsPageAsync private constructor( private val service: BenefitServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisBenefitListSupportedBenefitsParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisBenefitListSupportedBenefitsParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.listSupportedBenefits(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.listSupportedBenefits(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisBenefitListSupportedBenefitsParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -47,6 +49,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -58,6 +61,7 @@ private constructor( class Builder internal constructor() { private var service: BenefitServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisBenefitListSupportedBenefitsParams? = null private var items: Optional>? = null @@ -66,12 +70,17 @@ private constructor( hrisBenefitListSupportedBenefitsPageAsync: HrisBenefitListSupportedBenefitsPageAsync ) = apply { service = hrisBenefitListSupportedBenefitsPageAsync.service + streamHandlerExecutor = hrisBenefitListSupportedBenefitsPageAsync.streamHandlerExecutor params = hrisBenefitListSupportedBenefitsPageAsync.params items = Optional.of(hrisBenefitListSupportedBenefitsPageAsync.items) } fun service(service: BenefitServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisBenefitListSupportedBenefitsParams) = apply { this.params = params } @@ -88,6 +97,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -97,52 +107,22 @@ private constructor( fun build(): HrisBenefitListSupportedBenefitsPageAsync = HrisBenefitListSupportedBenefitsPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items).getOrNull() ?: emptyList(), ) } - class AutoPager(private val firstPage: HrisBenefitListSupportedBenefitsPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (BenefitListSupportedBenefitsResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList( - executor: Executor - ): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisBenefitListSupportedBenefitsPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is HrisBenefitListSupportedBenefitsPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "HrisBenefitListSupportedBenefitsPageAsync{service=$service, params=$params, items=$items}" + "HrisBenefitListSupportedBenefitsPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPage.kt index 00bcd8fa..823bce21 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPage.kt @@ -2,12 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.company.PayStatementItemService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [PayStatementItemService.list] */ @@ -16,7 +15,7 @@ private constructor( private val service: PayStatementItemService, private val params: HrisCompanyPayStatementItemListParams, private val response: HrisCompanyPayStatementItemListPageResponse, -) { +) : Page { /** * Delegates to [HrisCompanyPayStatementItemListPageResponse], but gracefully handles missing @@ -27,14 +26,16 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): Optional = - getNextPageParams().map { service.list(it) } + fun nextPageParams(): HrisCompanyPayStatementItemListParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): HrisCompanyPayStatementItemListPage = service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisCompanyPayStatementItemListParams = params @@ -108,26 +109,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisCompanyPayStatementItemListPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.responses().size) { - yield(page.responses()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageAsync.kt index 8a50507b..a39ed6ef 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageAsync.kt @@ -2,22 +2,23 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.company.PayStatementItemServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [PayStatementItemServiceAsync.list] */ class HrisCompanyPayStatementItemListPageAsync private constructor( private val service: PayStatementItemServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisCompanyPayStatementItemListParams, private val response: HrisCompanyPayStatementItemListPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisCompanyPayStatementItemListPageResponse], but gracefully handles missing @@ -28,16 +29,18 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + fun nextPageParams(): HrisCompanyPayStatementItemListParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisCompanyPayStatementItemListParams = params @@ -56,6 +59,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -67,6 +71,7 @@ private constructor( class Builder internal constructor() { private var service: PayStatementItemServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisCompanyPayStatementItemListParams? = null private var response: HrisCompanyPayStatementItemListPageResponse? = null @@ -75,12 +80,17 @@ private constructor( hrisCompanyPayStatementItemListPageAsync: HrisCompanyPayStatementItemListPageAsync ) = apply { service = hrisCompanyPayStatementItemListPageAsync.service + streamHandlerExecutor = hrisCompanyPayStatementItemListPageAsync.streamHandlerExecutor params = hrisCompanyPayStatementItemListPageAsync.params response = hrisCompanyPayStatementItemListPageAsync.response } fun service(service: PayStatementItemServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisCompanyPayStatementItemListParams) = apply { this.params = params } @@ -97,6 +107,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -106,50 +117,22 @@ private constructor( fun build(): HrisCompanyPayStatementItemListPageAsync = HrisCompanyPayStatementItemListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisCompanyPayStatementItemListPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (PayStatementItemListResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.responses().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisCompanyPayStatementItemListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisCompanyPayStatementItemListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisCompanyPayStatementItemListPageAsync{service=$service, params=$params, response=$response}" + "HrisCompanyPayStatementItemListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPage.kt index cb2c5147..580d9169 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPage.kt @@ -2,12 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.company.payStatementItem.RuleService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [RuleService.list] */ @@ -16,7 +15,7 @@ private constructor( private val service: RuleService, private val params: HrisCompanyPayStatementItemRuleListParams, private val response: HrisCompanyPayStatementItemRuleListPageResponse, -) { +) : Page { /** * Delegates to [HrisCompanyPayStatementItemRuleListPageResponse], but gracefully handles @@ -27,14 +26,17 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): Optional = - getNextPageParams().map { service.list(it) } + fun nextPageParams(): HrisCompanyPayStatementItemRuleListParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): HrisCompanyPayStatementItemRuleListPage = + service.list(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisCompanyPayStatementItemRuleListParams = params @@ -110,26 +112,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisCompanyPayStatementItemRuleListPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.responses().size) { - yield(page.responses()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPageAsync.kt index 269318ac..1a083316 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemRuleListPageAsync.kt @@ -2,22 +2,23 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.company.payStatementItem.RuleServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [RuleServiceAsync.list] */ class HrisCompanyPayStatementItemRuleListPageAsync private constructor( private val service: RuleServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisCompanyPayStatementItemRuleListParams, private val response: HrisCompanyPayStatementItemRuleListPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisCompanyPayStatementItemRuleListPageResponse], but gracefully handles @@ -28,16 +29,18 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + fun nextPageParams(): HrisCompanyPayStatementItemRuleListParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisCompanyPayStatementItemRuleListParams = params @@ -56,6 +59,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -67,6 +71,7 @@ private constructor( class Builder internal constructor() { private var service: RuleServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisCompanyPayStatementItemRuleListParams? = null private var response: HrisCompanyPayStatementItemRuleListPageResponse? = null @@ -76,12 +81,18 @@ private constructor( HrisCompanyPayStatementItemRuleListPageAsync ) = apply { service = hrisCompanyPayStatementItemRuleListPageAsync.service + streamHandlerExecutor = + hrisCompanyPayStatementItemRuleListPageAsync.streamHandlerExecutor params = hrisCompanyPayStatementItemRuleListPageAsync.params response = hrisCompanyPayStatementItemRuleListPageAsync.response } fun service(service: RuleServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisCompanyPayStatementItemRuleListParams) = apply { this.params = params @@ -100,6 +111,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -109,50 +121,22 @@ private constructor( fun build(): HrisCompanyPayStatementItemRuleListPageAsync = HrisCompanyPayStatementItemRuleListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisCompanyPayStatementItemRuleListPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (RuleListResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.responses().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisCompanyPayStatementItemRuleListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisCompanyPayStatementItemRuleListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisCompanyPayStatementItemRuleListPageAsync{service=$service, params=$params, response=$response}" + "HrisCompanyPayStatementItemRuleListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPage.kt index eeafc093..8f3c042a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPage.kt @@ -2,12 +2,12 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.DirectoryService import java.util.Objects import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrDefault import kotlin.jvm.optionals.getOrNull @@ -18,7 +18,7 @@ private constructor( private val service: DirectoryService, private val params: HrisDirectoryListIndividualsParams, private val response: HrisDirectoryListIndividualsPageResponse, -) { +) : Page { /** * Delegates to [HrisDirectoryListIndividualsPageResponse], but gracefully handles missing data. @@ -35,30 +35,28 @@ private constructor( */ fun paging(): Optional = response._paging().getOptional("paging") - fun hasNextPage(): Boolean { - if (individuals().isEmpty()) { + override fun items(): List = individuals() + + override fun hasNextPage(): Boolean { + if (items().isEmpty()) { return false } val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) val totalCount = paging().flatMap { it._count().getOptional("count") }.getOrDefault(Long.MAX_VALUE) - return offset + individuals().size < totalCount + return offset + items().size < totalCount } - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } - + fun nextPageParams(): HrisDirectoryListIndividualsParams { val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) - return Optional.of(params.toBuilder().offset(offset + individuals().size).build()) + return params.toBuilder().offset(offset + items().size).build() } - fun getNextPage(): Optional = - getNextPageParams().map { service.listIndividuals(it) } + override fun nextPage(): HrisDirectoryListIndividualsPage = + service.listIndividuals(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisDirectoryListIndividualsParams = params @@ -131,26 +129,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisDirectoryListIndividualsPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.individuals().size) { - yield(page.individuals()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageAsync.kt index e7480379..1a20863f 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListIndividualsPageAsync.kt @@ -2,13 +2,14 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.DirectoryServiceAsync import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrDefault import kotlin.jvm.optionals.getOrNull @@ -17,9 +18,10 @@ import kotlin.jvm.optionals.getOrNull class HrisDirectoryListIndividualsPageAsync private constructor( private val service: DirectoryServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisDirectoryListIndividualsParams, private val response: HrisDirectoryListIndividualsPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisDirectoryListIndividualsPageResponse], but gracefully handles missing data. @@ -36,32 +38,29 @@ private constructor( */ fun paging(): Optional = response._paging().getOptional("paging") - fun hasNextPage(): Boolean { - if (individuals().isEmpty()) { + override fun items(): List = individuals() + + override fun hasNextPage(): Boolean { + if (items().isEmpty()) { return false } val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) val totalCount = paging().flatMap { it._count().getOptional("count") }.getOrDefault(Long.MAX_VALUE) - return offset + individuals().size < totalCount + return offset + items().size < totalCount } - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } - + fun nextPageParams(): HrisDirectoryListIndividualsParams { val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) - return Optional.of(params.toBuilder().offset(offset + individuals().size).build()) + return params.toBuilder().offset(offset + items().size).build() } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.listIndividuals(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.listIndividuals(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisDirectoryListIndividualsParams = params @@ -80,6 +79,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -91,6 +91,7 @@ private constructor( class Builder internal constructor() { private var service: DirectoryServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisDirectoryListIndividualsParams? = null private var response: HrisDirectoryListIndividualsPageResponse? = null @@ -99,12 +100,17 @@ private constructor( hrisDirectoryListIndividualsPageAsync: HrisDirectoryListIndividualsPageAsync ) = apply { service = hrisDirectoryListIndividualsPageAsync.service + streamHandlerExecutor = hrisDirectoryListIndividualsPageAsync.streamHandlerExecutor params = hrisDirectoryListIndividualsPageAsync.params response = hrisDirectoryListIndividualsPageAsync.response } fun service(service: DirectoryServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisDirectoryListIndividualsParams) = apply { this.params = params } @@ -121,6 +127,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -130,50 +137,22 @@ private constructor( fun build(): HrisDirectoryListIndividualsPageAsync = HrisDirectoryListIndividualsPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisDirectoryListIndividualsPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (IndividualInDirectory) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.individuals().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisDirectoryListIndividualsPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisDirectoryListIndividualsPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisDirectoryListIndividualsPageAsync{service=$service, params=$params, response=$response}" + "HrisDirectoryListIndividualsPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPage.kt index 36eff6a0..f30e6e3c 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPage.kt @@ -2,12 +2,12 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.DirectoryService import java.util.Objects import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrDefault import kotlin.jvm.optionals.getOrNull @@ -17,7 +17,7 @@ private constructor( private val service: DirectoryService, private val params: HrisDirectoryListParams, private val response: HrisDirectoryListPageResponse, -) { +) : Page { /** * Delegates to [HrisDirectoryListPageResponse], but gracefully handles missing data. @@ -34,30 +34,27 @@ private constructor( */ fun paging(): Optional = response._paging().getOptional("paging") - fun hasNextPage(): Boolean { - if (individuals().isEmpty()) { + override fun items(): List = individuals() + + override fun hasNextPage(): Boolean { + if (items().isEmpty()) { return false } val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) val totalCount = paging().flatMap { it._count().getOptional("count") }.getOrDefault(Long.MAX_VALUE) - return offset + individuals().size < totalCount + return offset + items().size < totalCount } - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } - + fun nextPageParams(): HrisDirectoryListParams { val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) - return Optional.of(params.toBuilder().offset(offset + individuals().size).build()) + return params.toBuilder().offset(offset + items().size).build() } - fun getNextPage(): Optional = - getNextPageParams().map { service.list(it) } + override fun nextPage(): HrisDirectoryListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisDirectoryListParams = params @@ -126,26 +123,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisDirectoryListPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.individuals().size) { - yield(page.individuals()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPageAsync.kt index bc8d9645..06b6ee3a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisDirectoryListPageAsync.kt @@ -2,13 +2,14 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.DirectoryServiceAsync import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrDefault import kotlin.jvm.optionals.getOrNull @@ -16,9 +17,10 @@ import kotlin.jvm.optionals.getOrNull class HrisDirectoryListPageAsync private constructor( private val service: DirectoryServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisDirectoryListParams, private val response: HrisDirectoryListPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisDirectoryListPageResponse], but gracefully handles missing data. @@ -35,32 +37,29 @@ private constructor( */ fun paging(): Optional = response._paging().getOptional("paging") - fun hasNextPage(): Boolean { - if (individuals().isEmpty()) { + override fun items(): List = individuals() + + override fun hasNextPage(): Boolean { + if (items().isEmpty()) { return false } val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) val totalCount = paging().flatMap { it._count().getOptional("count") }.getOrDefault(Long.MAX_VALUE) - return offset + individuals().size < totalCount + return offset + items().size < totalCount } - fun getNextPageParams(): Optional { - if (!hasNextPage()) { - return Optional.empty() - } - + fun nextPageParams(): HrisDirectoryListParams { val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) - return Optional.of(params.toBuilder().offset(offset + individuals().size).build()) + return params.toBuilder().offset(offset + items().size).build() } - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisDirectoryListParams = params @@ -78,6 +77,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -89,18 +89,24 @@ private constructor( class Builder internal constructor() { private var service: DirectoryServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisDirectoryListParams? = null private var response: HrisDirectoryListPageResponse? = null @JvmSynthetic internal fun from(hrisDirectoryListPageAsync: HrisDirectoryListPageAsync) = apply { service = hrisDirectoryListPageAsync.service + streamHandlerExecutor = hrisDirectoryListPageAsync.streamHandlerExecutor params = hrisDirectoryListPageAsync.params response = hrisDirectoryListPageAsync.response } fun service(service: DirectoryServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisDirectoryListParams) = apply { this.params = params } @@ -115,6 +121,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -124,50 +131,22 @@ private constructor( fun build(): HrisDirectoryListPageAsync = HrisDirectoryListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisDirectoryListPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (IndividualInDirectory) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.individuals().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisDirectoryListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisDirectoryListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisDirectoryListPageAsync{service=$service, params=$params, response=$response}" + "HrisDirectoryListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPage.kt index 9987671a..a4fb48cd 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPage.kt @@ -2,12 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.EmploymentService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [EmploymentService.retrieveMany] */ @@ -16,7 +15,7 @@ private constructor( private val service: EmploymentService, private val params: HrisEmploymentRetrieveManyParams, private val response: HrisEmploymentRetrieveManyPageResponse, -) { +) : Page { /** * Delegates to [HrisEmploymentRetrieveManyPageResponse], but gracefully handles missing data. @@ -26,14 +25,16 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): Optional = - getNextPageParams().map { service.retrieveMany(it) } + fun nextPageParams(): HrisEmploymentRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): HrisEmploymentRetrieveManyPage = service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisEmploymentRetrieveManyParams = params @@ -105,26 +106,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisEmploymentRetrieveManyPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.responses().size) { - yield(page.responses()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageAsync.kt index 83f3ed95..91ccab5d 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisEmploymentRetrieveManyPageAsync.kt @@ -2,22 +2,23 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.EmploymentServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [EmploymentServiceAsync.retrieveMany] */ class HrisEmploymentRetrieveManyPageAsync private constructor( private val service: EmploymentServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisEmploymentRetrieveManyParams, private val response: HrisEmploymentRetrieveManyPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisEmploymentRetrieveManyPageResponse], but gracefully handles missing data. @@ -27,16 +28,18 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.retrieveMany(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + fun nextPageParams(): HrisEmploymentRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): CompletableFuture = + service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisEmploymentRetrieveManyParams = params @@ -55,6 +58,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -66,6 +70,7 @@ private constructor( class Builder internal constructor() { private var service: EmploymentServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisEmploymentRetrieveManyParams? = null private var response: HrisEmploymentRetrieveManyPageResponse? = null @@ -74,12 +79,17 @@ private constructor( hrisEmploymentRetrieveManyPageAsync: HrisEmploymentRetrieveManyPageAsync ) = apply { service = hrisEmploymentRetrieveManyPageAsync.service + streamHandlerExecutor = hrisEmploymentRetrieveManyPageAsync.streamHandlerExecutor params = hrisEmploymentRetrieveManyPageAsync.params response = hrisEmploymentRetrieveManyPageAsync.response } fun service(service: EmploymentServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisEmploymentRetrieveManyParams) = apply { this.params = params } @@ -96,6 +106,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -105,50 +116,22 @@ private constructor( fun build(): HrisEmploymentRetrieveManyPageAsync = HrisEmploymentRetrieveManyPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisEmploymentRetrieveManyPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (EmploymentDataResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.responses().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisEmploymentRetrieveManyPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisEmploymentRetrieveManyPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisEmploymentRetrieveManyPageAsync{service=$service, params=$params, response=$response}" + "HrisEmploymentRetrieveManyPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPage.kt index e9c57c27..ac6fca75 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPage.kt @@ -2,12 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.IndividualService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [IndividualService.retrieveMany] */ @@ -16,7 +15,7 @@ private constructor( private val service: IndividualService, private val params: HrisIndividualRetrieveManyParams, private val response: HrisIndividualRetrieveManyPageResponse, -) { +) : Page { /** * Delegates to [HrisIndividualRetrieveManyPageResponse], but gracefully handles missing data. @@ -26,14 +25,16 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): Optional = - getNextPageParams().map { service.retrieveMany(it) } + fun nextPageParams(): HrisIndividualRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): HrisIndividualRetrieveManyPage = service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisIndividualRetrieveManyParams = params @@ -105,26 +106,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisIndividualRetrieveManyPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.responses().size) { - yield(page.responses()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageAsync.kt index 77678253..efacc397 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisIndividualRetrieveManyPageAsync.kt @@ -2,22 +2,23 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.IndividualServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [IndividualServiceAsync.retrieveMany] */ class HrisIndividualRetrieveManyPageAsync private constructor( private val service: IndividualServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisIndividualRetrieveManyParams, private val response: HrisIndividualRetrieveManyPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisIndividualRetrieveManyPageResponse], but gracefully handles missing data. @@ -27,16 +28,18 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.retrieveMany(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + fun nextPageParams(): HrisIndividualRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): CompletableFuture = + service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisIndividualRetrieveManyParams = params @@ -55,6 +58,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -66,6 +70,7 @@ private constructor( class Builder internal constructor() { private var service: IndividualServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisIndividualRetrieveManyParams? = null private var response: HrisIndividualRetrieveManyPageResponse? = null @@ -74,12 +79,17 @@ private constructor( hrisIndividualRetrieveManyPageAsync: HrisIndividualRetrieveManyPageAsync ) = apply { service = hrisIndividualRetrieveManyPageAsync.service + streamHandlerExecutor = hrisIndividualRetrieveManyPageAsync.streamHandlerExecutor params = hrisIndividualRetrieveManyPageAsync.params response = hrisIndividualRetrieveManyPageAsync.response } fun service(service: IndividualServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisIndividualRetrieveManyParams) = apply { this.params = params } @@ -96,6 +106,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -105,50 +116,22 @@ private constructor( fun build(): HrisIndividualRetrieveManyPageAsync = HrisIndividualRetrieveManyPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisIndividualRetrieveManyPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (IndividualResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.responses().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisIndividualRetrieveManyPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisIndividualRetrieveManyPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisIndividualRetrieveManyPageAsync{service=$service, params=$params, response=$response}" + "HrisIndividualRetrieveManyPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPage.kt index f8a43307..ce24980a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPage.kt @@ -2,12 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.PayStatementService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull /** @see [PayStatementService.retrieveMany] */ @@ -16,7 +15,7 @@ private constructor( private val service: PayStatementService, private val params: HrisPayStatementRetrieveManyParams, private val response: HrisPayStatementRetrieveManyPageResponse, -) { +) : Page { /** * Delegates to [HrisPayStatementRetrieveManyPageResponse], but gracefully handles missing data. @@ -26,14 +25,17 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): Optional = - getNextPageParams().map { service.retrieveMany(it) } + fun nextPageParams(): HrisPayStatementRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): HrisPayStatementRetrieveManyPage = + service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisPayStatementRetrieveManyParams = params @@ -106,26 +108,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisPayStatementRetrieveManyPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.responses().size) { - yield(page.responses()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageAsync.kt index 2ec1929c..ff0099a3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPayStatementRetrieveManyPageAsync.kt @@ -2,22 +2,23 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.PayStatementServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull /** @see [PayStatementServiceAsync.retrieveMany] */ class HrisPayStatementRetrieveManyPageAsync private constructor( private val service: PayStatementServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisPayStatementRetrieveManyParams, private val response: HrisPayStatementRetrieveManyPageResponse, -) { +) : PageAsync { /** * Delegates to [HrisPayStatementRetrieveManyPageResponse], but gracefully handles missing data. @@ -27,16 +28,18 @@ private constructor( fun responses(): List = response._responses().getOptional("responses").getOrNull() ?: emptyList() - fun hasNextPage(): Boolean = responses().isNotEmpty() + override fun items(): List = responses() - fun getNextPageParams(): Optional = Optional.empty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.retrieveMany(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + fun nextPageParams(): HrisPayStatementRetrieveManyParams = + throw IllegalStateException("Cannot construct next page params") - fun autoPager(): AutoPager = AutoPager(this) + override fun nextPage(): CompletableFuture = + service.retrieveMany(nextPageParams()) + + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisPayStatementRetrieveManyParams = params @@ -55,6 +58,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -66,6 +70,7 @@ private constructor( class Builder internal constructor() { private var service: PayStatementServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisPayStatementRetrieveManyParams? = null private var response: HrisPayStatementRetrieveManyPageResponse? = null @@ -74,12 +79,17 @@ private constructor( hrisPayStatementRetrieveManyPageAsync: HrisPayStatementRetrieveManyPageAsync ) = apply { service = hrisPayStatementRetrieveManyPageAsync.service + streamHandlerExecutor = hrisPayStatementRetrieveManyPageAsync.streamHandlerExecutor params = hrisPayStatementRetrieveManyPageAsync.params response = hrisPayStatementRetrieveManyPageAsync.response } fun service(service: PayStatementServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisPayStatementRetrieveManyParams) = apply { this.params = params } @@ -96,6 +106,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .response() * ``` @@ -105,50 +116,22 @@ private constructor( fun build(): HrisPayStatementRetrieveManyPageAsync = HrisPayStatementRetrieveManyPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("response", response), ) } - class AutoPager(private val firstPage: HrisPayStatementRetrieveManyPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (PayStatementResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.responses().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisPayStatementRetrieveManyPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + return /* spotless:off */ other is HrisPayStatementRetrieveManyPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && response == other.response /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, response) /* spotless:on */ override fun toString() = - "HrisPayStatementRetrieveManyPageAsync{service=$service, params=$params, response=$response}" + "HrisPayStatementRetrieveManyPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPage.kt index 82892fa1..9cf9d9a5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPage.kt @@ -2,13 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.hris.PaymentService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport -import kotlin.jvm.optionals.getOrNull /** @see [PaymentService.list] */ class HrisPaymentListPage @@ -16,21 +14,22 @@ private constructor( private val service: PaymentService, private val params: HrisPaymentListParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisPaymentListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): HrisPaymentListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): HrisPaymentListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -93,25 +92,6 @@ private constructor( ) } - class AutoPager(private val firstPage: HrisPaymentListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPageAsync.kt index 236a00f1..ee77147a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/HrisPaymentListPageAsync.kt @@ -2,38 +2,38 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.hris.PaymentServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate /** @see [PaymentServiceAsync.list] */ class HrisPaymentListPageAsync private constructor( private val service: PaymentServiceAsync, + private val streamHandlerExecutor: Executor, private val params: HrisPaymentListParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): HrisPaymentListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): HrisPaymentListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -45,6 +45,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -56,18 +57,24 @@ private constructor( class Builder internal constructor() { private var service: PaymentServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: HrisPaymentListParams? = null private var items: List? = null @JvmSynthetic internal fun from(hrisPaymentListPageAsync: HrisPaymentListPageAsync) = apply { service = hrisPaymentListPageAsync.service + streamHandlerExecutor = hrisPaymentListPageAsync.streamHandlerExecutor params = hrisPaymentListPageAsync.params items = hrisPaymentListPageAsync.items } fun service(service: PaymentServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: HrisPaymentListParams) = apply { this.params = params } @@ -82,6 +89,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -91,47 +99,22 @@ private constructor( fun build(): HrisPaymentListPageAsync = HrisPaymentListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items), ) } - class AutoPager(private val firstPage: HrisPaymentListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Payment) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is HrisPaymentListPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is HrisPaymentListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "HrisPaymentListPageAsync{service=$service, params=$params, items=$items}" + "HrisPaymentListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPage.kt index a6556ac8..9287b371 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPage.kt @@ -2,13 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.payroll.PayGroupService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport -import kotlin.jvm.optionals.getOrNull /** @see [PayGroupService.list] */ class PayrollPayGroupListPage @@ -16,22 +14,22 @@ private constructor( private val service: PayGroupService, private val params: PayrollPayGroupListParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): PayrollPayGroupListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = - getNextPageParams().map { service.list(it) } + override fun nextPage(): PayrollPayGroupListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): PayrollPayGroupListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -94,26 +92,6 @@ private constructor( ) } - class AutoPager(private val firstPage: PayrollPayGroupListPage) : - Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPageAsync.kt index 98a97b4f..9b790ca2 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListPageAsync.kt @@ -2,38 +2,39 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.payroll.PayGroupServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate /** @see [PayGroupServiceAsync.list] */ class PayrollPayGroupListPageAsync private constructor( private val service: PayGroupServiceAsync, + private val streamHandlerExecutor: Executor, private val params: PayrollPayGroupListParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): PayrollPayGroupListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = + AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): PayrollPayGroupListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -45,6 +46,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -56,18 +58,24 @@ private constructor( class Builder internal constructor() { private var service: PayGroupServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: PayrollPayGroupListParams? = null private var items: List? = null @JvmSynthetic internal fun from(payrollPayGroupListPageAsync: PayrollPayGroupListPageAsync) = apply { service = payrollPayGroupListPageAsync.service + streamHandlerExecutor = payrollPayGroupListPageAsync.streamHandlerExecutor params = payrollPayGroupListPageAsync.params items = payrollPayGroupListPageAsync.items } fun service(service: PayGroupServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: PayrollPayGroupListParams) = apply { this.params = params } @@ -82,6 +90,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -91,50 +100,22 @@ private constructor( fun build(): PayrollPayGroupListPageAsync = PayrollPayGroupListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items), ) } - class AutoPager(private val firstPage: PayrollPayGroupListPageAsync) { - - fun forEach( - action: Predicate, - executor: Executor, - ): CompletableFuture { - fun CompletableFuture>.forEach( - action: (PayGroupListResponse) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is PayrollPayGroupListPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is PayrollPayGroupListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "PayrollPayGroupListPageAsync{service=$service, params=$params, items=$items}" + "PayrollPayGroupListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPage.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPage.kt index fddd8a63..e3c2524a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPage.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPage.kt @@ -2,13 +2,11 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPager +import com.tryfinch.api.core.Page import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.blocking.ProviderService import java.util.Objects -import java.util.Optional -import java.util.stream.Stream -import java.util.stream.StreamSupport -import kotlin.jvm.optionals.getOrNull /** @see [ProviderService.list] */ class ProviderListPage @@ -16,21 +14,22 @@ private constructor( private val service: ProviderService, private val params: ProviderListParams, private val items: List, -) { +) : Page { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): ProviderListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } + override fun nextPage(): ProviderListPage = service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPager = AutoPager.from(this) /** The parameters that were used to request this page. */ fun params(): ProviderListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -93,25 +92,6 @@ private constructor( ) } - class AutoPager(private val firstPage: ProviderListPage) : Iterable { - - override fun iterator(): Iterator = iterator { - var page = firstPage - var index = 0 - while (true) { - while (index < page.items().size) { - yield(page.items()[index++]) - } - page = page.getNextPage().getOrNull() ?: break - index = 0 - } - } - - fun stream(): Stream { - return StreamSupport.stream(spliterator(), false) - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPageAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPageAsync.kt index bdb79fb7..c23a65e2 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPageAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/ProviderListPageAsync.kt @@ -2,38 +2,38 @@ package com.tryfinch.api.models +import com.tryfinch.api.core.AutoPagerAsync +import com.tryfinch.api.core.PageAsync import com.tryfinch.api.core.checkRequired import com.tryfinch.api.services.async.ProviderServiceAsync import java.util.Objects -import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.Executor -import java.util.function.Predicate /** @see [ProviderServiceAsync.list] */ class ProviderListPageAsync private constructor( private val service: ProviderServiceAsync, + private val streamHandlerExecutor: Executor, private val params: ProviderListParams, private val items: List, -) { +) : PageAsync { - fun hasNextPage(): Boolean = items.isNotEmpty() + override fun hasNextPage(): Boolean = items().isNotEmpty() - fun getNextPageParams(): Optional = Optional.empty() + fun nextPageParams(): ProviderListParams = + throw IllegalStateException("Cannot construct next page params") - fun getNextPage(): CompletableFuture> = - getNextPageParams() - .map { service.list(it).thenApply { Optional.of(it) } } - .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + override fun nextPage(): CompletableFuture = + service.list(nextPageParams()) - fun autoPager(): AutoPager = AutoPager(this) + fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor) /** The parameters that were used to request this page. */ fun params(): ProviderListParams = params /** The response that this page was parsed from. */ - fun items(): List = items + override fun items(): List = items fun toBuilder() = Builder().from(this) @@ -45,6 +45,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -56,18 +57,24 @@ private constructor( class Builder internal constructor() { private var service: ProviderServiceAsync? = null + private var streamHandlerExecutor: Executor? = null private var params: ProviderListParams? = null private var items: List? = null @JvmSynthetic internal fun from(providerListPageAsync: ProviderListPageAsync) = apply { service = providerListPageAsync.service + streamHandlerExecutor = providerListPageAsync.streamHandlerExecutor params = providerListPageAsync.params items = providerListPageAsync.items } fun service(service: ProviderServiceAsync) = apply { this.service = service } + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { + this.streamHandlerExecutor = streamHandlerExecutor + } + /** The parameters that were used to request this page. */ fun params(params: ProviderListParams) = apply { this.params = params } @@ -82,6 +89,7 @@ private constructor( * The following fields are required: * ```java * .service() + * .streamHandlerExecutor() * .params() * .items() * ``` @@ -91,47 +99,22 @@ private constructor( fun build(): ProviderListPageAsync = ProviderListPageAsync( checkRequired("service", service), + checkRequired("streamHandlerExecutor", streamHandlerExecutor), checkRequired("params", params), checkRequired("items", items), ) } - class AutoPager(private val firstPage: ProviderListPageAsync) { - - fun forEach(action: Predicate, executor: Executor): CompletableFuture { - fun CompletableFuture>.forEach( - action: (Provider) -> Boolean, - executor: Executor, - ): CompletableFuture = - thenComposeAsync( - { page -> - page - .filter { it.items().all(action) } - .map { it.getNextPage().forEach(action, executor) } - .orElseGet { CompletableFuture.completedFuture(null) } - }, - executor, - ) - return CompletableFuture.completedFuture(Optional.of(firstPage)) - .forEach(action::test, executor) - } - - fun toList(executor: Executor): CompletableFuture> { - val values = mutableListOf() - return forEach(values::add, executor).thenApply { values } - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ProviderListPageAsync && service == other.service && params == other.params && items == other.items /* spotless:on */ + return /* spotless:off */ other is ProviderListPageAsync && service == other.service && streamHandlerExecutor == other.streamHandlerExecutor && params == other.params && items == other.items /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, items) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, streamHandlerExecutor, params, items) /* spotless:on */ override fun toString() = - "ProviderListPageAsync{service=$service, params=$params, items=$items}" + "ProviderListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, items=$items}" } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/ProviderServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/ProviderServiceAsyncImpl.kt index faaef5e4..9de04dba 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/ProviderServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/ProviderServiceAsyncImpl.kt @@ -68,6 +68,7 @@ class ProviderServiceAsyncImpl internal constructor(private val clientOptions: C .let { ProviderListPageAsync.builder() .service(ProviderServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt index 5f6007c2..1e38a525 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt @@ -220,6 +220,7 @@ class BenefitServiceAsyncImpl internal constructor(private val clientOptions: Cl .let { HrisBenefitListPageAsync.builder() .service(BenefitServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() @@ -260,6 +261,7 @@ class BenefitServiceAsyncImpl internal constructor(private val clientOptions: Cl .let { HrisBenefitListSupportedBenefitsPageAsync.builder() .service(BenefitServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DirectoryServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DirectoryServiceAsyncImpl.kt index dfe58374..737aeac0 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DirectoryServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DirectoryServiceAsyncImpl.kt @@ -80,6 +80,7 @@ class DirectoryServiceAsyncImpl internal constructor(private val clientOptions: .let { HrisDirectoryListPageAsync.builder() .service(DirectoryServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() @@ -118,6 +119,7 @@ class DirectoryServiceAsyncImpl internal constructor(private val clientOptions: .let { HrisDirectoryListIndividualsPageAsync.builder() .service(DirectoryServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/EmploymentServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/EmploymentServiceAsyncImpl.kt index 395a53ff..a9c72d89 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/EmploymentServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/EmploymentServiceAsyncImpl.kt @@ -71,6 +71,7 @@ class EmploymentServiceAsyncImpl internal constructor(private val clientOptions: .let { HrisEmploymentRetrieveManyPageAsync.builder() .service(EmploymentServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/IndividualServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/IndividualServiceAsyncImpl.kt index 20b0435f..26a7925a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/IndividualServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/IndividualServiceAsyncImpl.kt @@ -71,6 +71,7 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: .let { HrisIndividualRetrieveManyPageAsync.builder() .service(IndividualServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PayStatementServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PayStatementServiceAsyncImpl.kt index cfae8dc4..6a682d8f 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PayStatementServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PayStatementServiceAsyncImpl.kt @@ -71,6 +71,7 @@ class PayStatementServiceAsyncImpl internal constructor(private val clientOption .let { HrisPayStatementRetrieveManyPageAsync.builder() .service(PayStatementServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PaymentServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PaymentServiceAsyncImpl.kt index 35690383..c8b13fea 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PaymentServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/PaymentServiceAsyncImpl.kt @@ -68,6 +68,7 @@ class PaymentServiceAsyncImpl internal constructor(private val clientOptions: Cl .let { HrisPaymentListPageAsync.builder() .service(PaymentServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt index a7509390..959a36b0 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/benefits/IndividualServiceAsyncImpl.kt @@ -126,6 +126,7 @@ class IndividualServiceAsyncImpl internal constructor(private val clientOptions: .let { HrisBenefitIndividualRetrieveManyBenefitsPageAsync.builder() .service(IndividualServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/PayStatementItemServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/PayStatementItemServiceAsyncImpl.kt index c7b25159..6c1131c8 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/PayStatementItemServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/PayStatementItemServiceAsyncImpl.kt @@ -81,6 +81,7 @@ internal constructor(private val clientOptions: ClientOptions) : PayStatementIte .let { HrisCompanyPayStatementItemListPageAsync.builder() .service(PayStatementItemServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt index d967e16f..71f908a0 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/company/payStatementItem/RuleServiceAsyncImpl.kt @@ -162,6 +162,7 @@ class RuleServiceAsyncImpl internal constructor(private val clientOptions: Clien .let { HrisCompanyPayStatementItemRuleListPageAsync.builder() .service(RuleServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .response(it) .build() diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt index 0b42404d..2e8dacac 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/payroll/PayGroupServiceAsyncImpl.kt @@ -113,6 +113,7 @@ class PayGroupServiceAsyncImpl internal constructor(private val clientOptions: C .let { PayrollPayGroupListPageAsync.builder() .service(PayGroupServiceAsyncImpl(clientOptions)) + .streamHandlerExecutor(clientOptions.streamHandlerExecutor) .params(params) .items(it) .build() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerAsyncTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerAsyncTest.kt new file mode 100644 index 00000000..4c8940bc --- /dev/null +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerAsyncTest.kt @@ -0,0 +1,182 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +import com.tryfinch.api.core.http.AsyncStreamResponse +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.catchThrowable +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.any +import org.mockito.kotlin.clearInvocations +import org.mockito.kotlin.doAnswer +import org.mockito.kotlin.inOrder +import org.mockito.kotlin.mock +import org.mockito.kotlin.never +import org.mockito.kotlin.spy +import org.mockito.kotlin.times +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever + +@ExtendWith(MockitoExtension::class) +internal class AutoPagerAsyncTest { + + companion object { + + private val ERROR = RuntimeException("ERROR!") + } + + private class PageAsyncImpl( + private val items: List, + private val hasNext: Boolean = true, + ) : PageAsync { + + val nextPageFuture: CompletableFuture> = CompletableFuture() + + override fun hasNextPage(): Boolean = hasNext + + override fun nextPage(): CompletableFuture> = nextPageFuture + + override fun items(): List = items + } + + private val executor = + spy { + doAnswer { invocation -> invocation.getArgument(0).run() } + .whenever(it) + .execute(any()) + } + private val handler = mock>() + + @Test + fun subscribe_whenAlreadySubscribed_throws() { + val autoPagerAsync = AutoPagerAsync.from(PageAsyncImpl(emptyList()), executor) + autoPagerAsync.subscribe {} + clearInvocations(executor) + + val throwable = catchThrowable { autoPagerAsync.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe more than once") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenClosed_throws() { + val autoPagerAsync = AutoPagerAsync.from(PageAsyncImpl(emptyList()), executor) + autoPagerAsync.close() + + val throwable = catchThrowable { autoPagerAsync.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe after the response is closed") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenFirstPageNonEmpty_runsHandler() { + val page = PageAsyncImpl(listOf("item1", "item2", "item3"), hasNext = false) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + + autoPagerAsync.subscribe(handler) + + inOrder(executor, handler) { + verify(executor, times(1)).execute(any()) + verify(handler, times(1)).onNext("item1") + verify(handler, times(1)).onNext("item2") + verify(handler, times(1)).onNext("item3") + verify(handler, times(1)).onComplete(Optional.empty()) + } + } + + @Test + fun subscribe_whenFutureCompletesAfterClose_doesNothing() { + val page = PageAsyncImpl(listOf("page1")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe(handler) + autoPagerAsync.close() + + page.nextPageFuture.complete(PageAsyncImpl(listOf("page2"))) + + verify(handler, times(1)).onNext("page1") + verify(handler, never()).onNext("page2") + verify(handler, times(1)).onComplete(Optional.empty()) + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenFutureErrors_callsOnComplete() { + val page = PageAsyncImpl(emptyList()) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe(handler) + + page.nextPageFuture.completeExceptionally(ERROR) + + verify(executor, times(1)).execute(any()) + verify(handler, never()).onNext(any()) + verify(handler, times(1)).onComplete(Optional.of(ERROR)) + } + + @Test + fun subscribe_whenFutureCompletes_runsHandler() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + + autoPagerAsync.subscribe(handler) + + verify(handler, never()).onComplete(any()) + inOrder(executor, handler) { + verify(executor, times(1)).execute(any()) + verify(handler, times(1)).onNext("chunk1") + verify(handler, times(1)).onNext("chunk2") + } + clearInvocations(executor, handler) + + page.nextPageFuture.complete(PageAsyncImpl(listOf("chunk3", "chunk4"), hasNext = false)) + + verify(executor, never()).execute(any()) + inOrder(handler) { + verify(handler, times(1)).onNext("chunk3") + verify(handler, times(1)).onNext("chunk4") + verify(handler, times(1)).onComplete(Optional.empty()) + } + } + + @Test + fun onCompleteFuture_whenNextPageFutureNotCompleted_onCompleteFutureNotCompleted() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe {} + + val onCompletableFuture = autoPagerAsync.onCompleteFuture() + + assertThat(onCompletableFuture).isNotCompleted + } + + @Test + fun onCompleteFuture_whenNextPageFutureErrors_onCompleteFutureCompletedExceptionally() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2")) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe {} + page.nextPageFuture.completeExceptionally(ERROR) + + val onCompletableFuture = autoPagerAsync.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenNoNextPage_onCompleteFutureCompleted() { + val page = PageAsyncImpl(listOf("chunk1", "chunk2"), hasNext = false) + val autoPagerAsync = AutoPagerAsync.from(page, executor) + autoPagerAsync.subscribe {} + + val onCompletableFuture = autoPagerAsync.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } +} diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerTest.kt new file mode 100644 index 00000000..7ffdfe17 --- /dev/null +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/AutoPagerTest.kt @@ -0,0 +1,41 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.tryfinch.api.core + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AutoPagerTest { + + private class PageImpl( + private val items: List, + private val nextPage: Page? = null, + ) : Page { + + override fun hasNextPage(): Boolean = nextPage != null + + override fun nextPage(): Page = nextPage!! + + override fun items(): List = items + } + + @Test + fun iterator() { + val firstPage = + PageImpl(listOf("chunk1", "chunk2"), nextPage = PageImpl(listOf("chunk3", "chunk4"))) + + val autoPager = AutoPager.from(firstPage) + + assertThat(autoPager).containsExactly("chunk1", "chunk2", "chunk3", "chunk4") + } + + @Test + fun stream() { + val firstPage = + PageImpl(listOf("chunk1", "chunk2"), nextPage = PageImpl(listOf("chunk3", "chunk4"))) + + val autoPager = AutoPager.from(firstPage) + + assertThat(autoPager.stream()).containsExactly("chunk1", "chunk2", "chunk3", "chunk4") + } +} diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/core/http/AsyncStreamResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/http/AsyncStreamResponseTest.kt new file mode 100644 index 00000000..96c472b6 --- /dev/null +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/core/http/AsyncStreamResponseTest.kt @@ -0,0 +1,268 @@ +package com.tryfinch.api.core.http + +import java.util.* +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.stream.Stream +import kotlin.streams.asStream +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.catchThrowable +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertDoesNotThrow +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.* + +@ExtendWith(MockitoExtension::class) +internal class AsyncStreamResponseTest { + + companion object { + private val ERROR = RuntimeException("ERROR!") + } + + private val streamResponse = + spy> { + doReturn(Stream.of("chunk1", "chunk2", "chunk3")).whenever(it).stream() + } + private val erroringStreamResponse = + spy> { + doReturn( + sequence { + yield("chunk1") + yield("chunk2") + throw ERROR + } + .asStream() + ) + .whenever(it) + .stream() + } + private val executor = + spy { + doAnswer { invocation -> invocation.getArgument(0).run() } + .whenever(it) + .execute(any()) + } + private val handler = mock>() + + @Test + fun subscribe_whenAlreadySubscribed_throws() { + val asyncStreamResponse = CompletableFuture>().toAsync(executor) + asyncStreamResponse.subscribe {} + + val throwable = catchThrowable { asyncStreamResponse.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe more than once") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenClosed_throws() { + val asyncStreamResponse = CompletableFuture>().toAsync(executor) + asyncStreamResponse.close() + + val throwable = catchThrowable { asyncStreamResponse.subscribe {} } + + assertThat(throwable).isInstanceOf(IllegalStateException::class.java) + assertThat(throwable).hasMessage("Cannot subscribe after the response is closed") + verify(executor, never()).execute(any()) + } + + @Test + fun subscribe_whenFutureCompletesAfterClose_doesNothing() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + asyncStreamResponse.close() + + future.complete(streamResponse) + + verify(handler, never()).onNext(any()) + verify(handler, never()).onComplete(any()) + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenFutureErrors_callsOnComplete() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + + future.completeExceptionally(ERROR) + + verify(handler, never()).onNext(any()) + verify(handler, times(1)).onComplete(Optional.of(ERROR)) + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenFutureCompletes_runsHandler() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + + future.complete(streamResponse) + + inOrder(handler, streamResponse) { + verify(handler, times(1)).onNext("chunk1") + verify(handler, times(1)).onNext("chunk2") + verify(handler, times(1)).onNext("chunk3") + verify(handler, times(1)).onComplete(Optional.empty()) + verify(streamResponse, times(1)).close() + } + verify(executor, times(1)).execute(any()) + } + + @Test + fun subscribe_whenStreamErrors_callsOnCompleteEarly() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + + future.complete(erroringStreamResponse) + + inOrder(handler, erroringStreamResponse) { + verify(handler, times(1)).onNext("chunk1") + verify(handler, times(1)).onNext("chunk2") + verify(handler, times(1)).onComplete(Optional.of(ERROR)) + verify(erroringStreamResponse, times(1)).close() + } + verify(executor, times(1)).execute(any()) + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureNotCompleted_onCompleteFutureNotCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isNotCompleted + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureErrors_onCompleteFutureCompletedExceptionally() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + future.completeExceptionally(ERROR) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureCompletedButStillStreaming_onCompleteFutureNotCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + future.complete(streamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isNotCompleted + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureCompletedAndStreamErrors_onCompleteFutureCompletedExceptionally() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + future.complete(erroringStreamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenStreamResponseFutureCompletedAndStreamCompleted_onCompleteFutureCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe(handler) + future.complete(streamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } + + @Test + fun onCompleteFuture_whenHandlerOnCompleteWithoutThrowableThrows_onCompleteFutureCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe( + object : AsyncStreamResponse.Handler { + override fun onNext(value: String) {} + + override fun onComplete(error: Optional) = throw ERROR + } + ) + future.complete(streamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } + + @Test + fun onCompleteFuture_whenHandlerOnCompleteWithThrowableThrows_onCompleteFutureCompletedExceptionally() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.subscribe( + object : AsyncStreamResponse.Handler { + override fun onNext(value: String) {} + + override fun onComplete(error: Optional) = throw ERROR + } + ) + future.complete(erroringStreamResponse) + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompletedExceptionally + } + + @Test + fun onCompleteFuture_whenClosed_onCompleteFutureCompleted() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.close() + + val onCompletableFuture = asyncStreamResponse.onCompleteFuture() + + assertThat(onCompletableFuture).isCompleted + } + + @Test + fun close_whenNotClosed_closesStreamResponse() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + + asyncStreamResponse.close() + future.complete(streamResponse) + + verify(streamResponse, times(1)).close() + } + + @Test + fun close_whenAlreadyClosed_doesNothing() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.close() + future.complete(streamResponse) + + asyncStreamResponse.close() + + verify(streamResponse, times(1)).close() + } + + @Test + fun close_whenFutureErrors_doesNothing() { + val future = CompletableFuture>() + val asyncStreamResponse = future.toAsync(executor) + asyncStreamResponse.close() + + assertDoesNotThrow { future.completeExceptionally(ERROR) } + } +} From 17bd5c172f3ef94e68846f5b18670b42560e1fce Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 15 May 2025 20:40:30 +0000 Subject: [PATCH 3/6] feat(api): api update --- .stats.yml | 4 +- .../com/tryfinch/api/models/BenefitType.kt | 108 +- .../kotlin/com/tryfinch/api/models/Money.kt | 36 +- .../api/models/PayGroupListResponse.kt | 107 +- .../api/models/PayGroupRetrieveResponse.kt | 54 +- .../com/tryfinch/api/models/PayStatement.kt | 1933 +++++++++------- .../models/PayStatementItemListResponse.kt | 159 +- .../api/models/PayStatementResponse.kt | 55 +- .../api/models/PayStatementResponseBody.kt | 233 +- .../kotlin/com/tryfinch/api/models/Payment.kt | 169 +- .../api/models/SandboxPaymentCreateParams.kt | 1953 ++++++++++------- .../tryfinch/api/models/CompanyBenefitTest.kt | 6 +- .../api/models/HrisBenefitCreateParamsTest.kt | 6 +- ...anyPayStatementItemListPageResponseTest.kt | 6 +- ...ayStatementRetrieveManyPageResponseTest.kt | 111 +- .../com/tryfinch/api/models/MoneyTest.kt | 2 +- .../api/models/PayGroupListResponseTest.kt | 7 +- .../PayStatementItemListResponseTest.kt | 12 +- .../models/PayStatementResponseBodyTest.kt | 99 +- .../api/models/PayStatementResponseTest.kt | 106 +- .../tryfinch/api/models/PayStatementTest.kt | 92 +- .../com/tryfinch/api/models/PaymentTest.kt | 2 +- .../models/SandboxPaymentCreateParamsTest.kt | 102 +- .../async/hris/BenefitServiceAsyncTest.kt | 2 +- .../async/sandbox/PaymentServiceAsyncTest.kt | 38 +- .../blocking/hris/BenefitServiceTest.kt | 2 +- .../blocking/sandbox/PaymentServiceTest.kt | 38 +- 27 files changed, 3177 insertions(+), 2265 deletions(-) diff --git a/.stats.yml b/.stats.yml index d004027c..bbc9fc49 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-f09e5f2c555d7ee764478b7bc73e92cd21f403d6ec189be14574c8367bc131ce.yml -openapi_spec_hash: bd0a8e001f14132c105992d40149909a +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-331df2398447990a86899b05ac569534b6a7e4ff1d73a319d57f67b34a201fb7.yml +openapi_spec_hash: 6e57516524c0519e90213c0554b26ab4 config_hash: 53778a0b839c4f6ad34fbba051f5e8a6 diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/BenefitType.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/BenefitType.kt index 27b2ed15..b8526345 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/BenefitType.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/BenefitType.kt @@ -21,6 +21,8 @@ class BenefitType @JsonCreator private constructor(private val value: JsonField< companion object { + @JvmField val _457 = of("457") + @JvmField val _401K = of("401k") @JvmField val _401K_ROTH = of("401k_roth") @@ -31,58 +33,56 @@ class BenefitType @JsonCreator private constructor(private val value: JsonField< @JvmField val _403B_ROTH = of("403b_roth") - @JvmField val _457 = of("457") - @JvmField val _457_ROTH = of("457_roth") - @JvmField val S125_MEDICAL = of("s125_medical") - - @JvmField val S125_DENTAL = of("s125_dental") + @JvmField val COMMUTER = of("commuter") - @JvmField val S125_VISION = of("s125_vision") + @JvmField val CUSTOM_POST_TAX = of("custom_post_tax") - @JvmField val HSA_PRE = of("hsa_pre") + @JvmField val CUSTOM_PRE_TAX = of("custom_pre_tax") - @JvmField val HSA_POST = of("hsa_post") + @JvmField val FSA_DEPENDENT_CARE = of("fsa_dependent_care") @JvmField val FSA_MEDICAL = of("fsa_medical") - @JvmField val FSA_DEPENDENT_CARE = of("fsa_dependent_care") + @JvmField val HSA_POST = of("hsa_post") - @JvmField val SIMPLE_IRA = of("simple_ira") + @JvmField val HSA_PRE = of("hsa_pre") - @JvmField val SIMPLE = of("simple") + @JvmField val S125_DENTAL = of("s125_dental") - @JvmField val COMMUTER = of("commuter") + @JvmField val S125_MEDICAL = of("s125_medical") - @JvmField val CUSTOM_POST_TAX = of("custom_post_tax") + @JvmField val S125_VISION = of("s125_vision") - @JvmField val CUSTOM_PRE_TAX = of("custom_pre_tax") + @JvmField val SIMPLE = of("simple") + + @JvmField val SIMPLE_IRA = of("simple_ira") @JvmStatic fun of(value: String) = BenefitType(JsonField.of(value)) } /** An enum containing [BenefitType]'s known values. */ enum class Known { + _457, _401K, _401K_ROTH, _401K_LOAN, _403B, _403B_ROTH, - _457, _457_ROTH, - S125_MEDICAL, - S125_DENTAL, - S125_VISION, - HSA_PRE, - HSA_POST, - FSA_MEDICAL, - FSA_DEPENDENT_CARE, - SIMPLE_IRA, - SIMPLE, COMMUTER, CUSTOM_POST_TAX, CUSTOM_PRE_TAX, + FSA_DEPENDENT_CARE, + FSA_MEDICAL, + HSA_POST, + HSA_PRE, + S125_DENTAL, + S125_MEDICAL, + S125_VISION, + SIMPLE, + SIMPLE_IRA, } /** @@ -95,25 +95,25 @@ class BenefitType @JsonCreator private constructor(private val value: JsonField< * - It was constructed with an arbitrary value using the [of] method. */ enum class Value { + _457, _401K, _401K_ROTH, _401K_LOAN, _403B, _403B_ROTH, - _457, _457_ROTH, - S125_MEDICAL, - S125_DENTAL, - S125_VISION, - HSA_PRE, - HSA_POST, - FSA_MEDICAL, - FSA_DEPENDENT_CARE, - SIMPLE_IRA, - SIMPLE, COMMUTER, CUSTOM_POST_TAX, CUSTOM_PRE_TAX, + FSA_DEPENDENT_CARE, + FSA_MEDICAL, + HSA_POST, + HSA_PRE, + S125_DENTAL, + S125_MEDICAL, + S125_VISION, + SIMPLE, + SIMPLE_IRA, /** An enum member indicating that [BenefitType] was instantiated with an unknown value. */ _UNKNOWN, } @@ -127,25 +127,25 @@ class BenefitType @JsonCreator private constructor(private val value: JsonField< */ fun value(): Value = when (this) { + _457 -> Value._457 _401K -> Value._401K _401K_ROTH -> Value._401K_ROTH _401K_LOAN -> Value._401K_LOAN _403B -> Value._403B _403B_ROTH -> Value._403B_ROTH - _457 -> Value._457 _457_ROTH -> Value._457_ROTH - S125_MEDICAL -> Value.S125_MEDICAL - S125_DENTAL -> Value.S125_DENTAL - S125_VISION -> Value.S125_VISION - HSA_PRE -> Value.HSA_PRE - HSA_POST -> Value.HSA_POST - FSA_MEDICAL -> Value.FSA_MEDICAL - FSA_DEPENDENT_CARE -> Value.FSA_DEPENDENT_CARE - SIMPLE_IRA -> Value.SIMPLE_IRA - SIMPLE -> Value.SIMPLE COMMUTER -> Value.COMMUTER CUSTOM_POST_TAX -> Value.CUSTOM_POST_TAX CUSTOM_PRE_TAX -> Value.CUSTOM_PRE_TAX + FSA_DEPENDENT_CARE -> Value.FSA_DEPENDENT_CARE + FSA_MEDICAL -> Value.FSA_MEDICAL + HSA_POST -> Value.HSA_POST + HSA_PRE -> Value.HSA_PRE + S125_DENTAL -> Value.S125_DENTAL + S125_MEDICAL -> Value.S125_MEDICAL + S125_VISION -> Value.S125_VISION + SIMPLE -> Value.SIMPLE + SIMPLE_IRA -> Value.SIMPLE_IRA else -> Value._UNKNOWN } @@ -159,25 +159,25 @@ class BenefitType @JsonCreator private constructor(private val value: JsonField< */ fun known(): Known = when (this) { + _457 -> Known._457 _401K -> Known._401K _401K_ROTH -> Known._401K_ROTH _401K_LOAN -> Known._401K_LOAN _403B -> Known._403B _403B_ROTH -> Known._403B_ROTH - _457 -> Known._457 _457_ROTH -> Known._457_ROTH - S125_MEDICAL -> Known.S125_MEDICAL - S125_DENTAL -> Known.S125_DENTAL - S125_VISION -> Known.S125_VISION - HSA_PRE -> Known.HSA_PRE - HSA_POST -> Known.HSA_POST - FSA_MEDICAL -> Known.FSA_MEDICAL - FSA_DEPENDENT_CARE -> Known.FSA_DEPENDENT_CARE - SIMPLE_IRA -> Known.SIMPLE_IRA - SIMPLE -> Known.SIMPLE COMMUTER -> Known.COMMUTER CUSTOM_POST_TAX -> Known.CUSTOM_POST_TAX CUSTOM_PRE_TAX -> Known.CUSTOM_PRE_TAX + FSA_DEPENDENT_CARE -> Known.FSA_DEPENDENT_CARE + FSA_MEDICAL -> Known.FSA_MEDICAL + HSA_POST -> Known.HSA_POST + HSA_PRE -> Known.HSA_PRE + S125_DENTAL -> Known.S125_DENTAL + S125_MEDICAL -> Known.S125_MEDICAL + S125_VISION -> Known.S125_VISION + SIMPLE -> Known.SIMPLE + SIMPLE_IRA -> Known.SIMPLE_IRA else -> throw FinchInvalidDataException("Unknown BenefitType: $value") } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Money.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Money.kt index c9badec1..137e061e 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Money.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Money.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 @@ -38,10 +39,10 @@ private constructor( fun amount(): Optional = amount.getOptional("amount") /** - * @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 currency(): Optional = currency.getOptional("currency") + fun currency(): String = currency.getRequired("currency") /** * Returns the raw JSON value of [amount]. @@ -71,15 +72,23 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Money]. */ + /** + * Returns a mutable builder for constructing an instance of [Money]. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Money]. */ class Builder internal constructor() { - private var amount: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() + private var amount: JsonField? = null + private var currency: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -143,8 +152,21 @@ private constructor( * Returns an immutable instance of [Money]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Money = Money(amount, currency, additionalProperties.toMutableMap()) + fun build(): Money = + Money( + checkRequired("amount", amount), + checkRequired("currency", currency), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupListResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupListResponse.kt index 608a9101..a5826485 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupListResponse.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupListResponse.kt @@ -12,11 +12,11 @@ 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 -import java.util.Optional import kotlin.jvm.optionals.getOrNull class PayGroupListResponse @@ -39,27 +39,26 @@ private constructor( /** * Finch id (uuidv4) for the pay group * - * @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") /** * Name of the pay group * - * @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 name(): Optional = name.getOptional("name") + fun name(): String = name.getRequired("name") /** * List of pay frequencies associated with this pay group * - * @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 payFrequencies(): Optional> = - payFrequencies.getOptional("pay_frequencies") + fun payFrequencies(): List = payFrequencies.getRequired("pay_frequencies") /** * Returns the raw JSON value of [id]. @@ -98,15 +97,24 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [PayGroupListResponse]. */ + /** + * Returns a mutable builder for constructing an instance of [PayGroupListResponse]. + * + * The following fields are required: + * ```java + * .id() + * .name() + * .payFrequencies() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [PayGroupListResponse]. */ class Builder internal constructor() { - private var id: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() + private var id: JsonField? = null + private var name: JsonField? = null private var payFrequencies: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -190,12 +198,21 @@ private constructor( * Returns an immutable instance of [PayGroupListResponse]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .name() + * .payFrequencies() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): PayGroupListResponse = PayGroupListResponse( - id, - name, - (payFrequencies ?: JsonMissing.of()).map { it.toImmutable() }, + checkRequired("id", id), + checkRequired("name", name), + checkRequired("payFrequencies", payFrequencies).map { it.toImmutable() }, additionalProperties.toMutableMap(), ) } @@ -209,7 +226,7 @@ private constructor( id() name() - payFrequencies().ifPresent { it.forEach { it.validate() } } + payFrequencies().forEach { it.validate() } validated = true } @@ -249,21 +266,21 @@ private constructor( @JvmField val ANNUALLY = of("annually") - @JvmField val SEMI_ANNUALLY = of("semi_annually") + @JvmField val BI_WEEKLY = of("bi_weekly") - @JvmField val QUARTERLY = of("quarterly") + @JvmField val DAILY = of("daily") @JvmField val MONTHLY = of("monthly") - @JvmField val SEMI_MONTHLY = of("semi_monthly") + @JvmField val OTHER = of("other") - @JvmField val BI_WEEKLY = of("bi_weekly") + @JvmField val QUARTERLY = of("quarterly") - @JvmField val WEEKLY = of("weekly") + @JvmField val SEMI_ANNUALLY = of("semi_annually") - @JvmField val DAILY = of("daily") + @JvmField val SEMI_MONTHLY = of("semi_monthly") - @JvmField val OTHER = of("other") + @JvmField val WEEKLY = of("weekly") @JvmStatic fun of(value: String) = PayFrequency(JsonField.of(value)) } @@ -271,14 +288,14 @@ private constructor( /** An enum containing [PayFrequency]'s known values. */ enum class Known { ANNUALLY, - SEMI_ANNUALLY, - QUARTERLY, - MONTHLY, - SEMI_MONTHLY, BI_WEEKLY, - WEEKLY, DAILY, + MONTHLY, OTHER, + QUARTERLY, + SEMI_ANNUALLY, + SEMI_MONTHLY, + WEEKLY, } /** @@ -292,14 +309,14 @@ private constructor( */ enum class Value { ANNUALLY, - SEMI_ANNUALLY, - QUARTERLY, - MONTHLY, - SEMI_MONTHLY, BI_WEEKLY, - WEEKLY, DAILY, + MONTHLY, OTHER, + QUARTERLY, + SEMI_ANNUALLY, + SEMI_MONTHLY, + WEEKLY, /** * An enum member indicating that [PayFrequency] was instantiated with an unknown value. */ @@ -316,14 +333,14 @@ private constructor( fun value(): Value = when (this) { ANNUALLY -> Value.ANNUALLY - SEMI_ANNUALLY -> Value.SEMI_ANNUALLY - QUARTERLY -> Value.QUARTERLY - MONTHLY -> Value.MONTHLY - SEMI_MONTHLY -> Value.SEMI_MONTHLY BI_WEEKLY -> Value.BI_WEEKLY - WEEKLY -> Value.WEEKLY DAILY -> Value.DAILY + MONTHLY -> Value.MONTHLY OTHER -> Value.OTHER + QUARTERLY -> Value.QUARTERLY + SEMI_ANNUALLY -> Value.SEMI_ANNUALLY + SEMI_MONTHLY -> Value.SEMI_MONTHLY + WEEKLY -> Value.WEEKLY else -> Value._UNKNOWN } @@ -338,14 +355,14 @@ private constructor( fun known(): Known = when (this) { ANNUALLY -> Known.ANNUALLY - SEMI_ANNUALLY -> Known.SEMI_ANNUALLY - QUARTERLY -> Known.QUARTERLY - MONTHLY -> Known.MONTHLY - SEMI_MONTHLY -> Known.SEMI_MONTHLY BI_WEEKLY -> Known.BI_WEEKLY - WEEKLY -> Known.WEEKLY DAILY -> Known.DAILY + MONTHLY -> Known.MONTHLY OTHER -> Known.OTHER + QUARTERLY -> Known.QUARTERLY + SEMI_ANNUALLY -> Known.SEMI_ANNUALLY + SEMI_MONTHLY -> Known.SEMI_MONTHLY + WEEKLY -> Known.WEEKLY else -> throw FinchInvalidDataException("Unknown PayFrequency: $value") } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupRetrieveResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupRetrieveResponse.kt index e6e2c27b..8e93a1cc 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupRetrieveResponse.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupRetrieveResponse.kt @@ -317,21 +317,21 @@ private constructor( @JvmField val ANNUALLY = of("annually") - @JvmField val SEMI_ANNUALLY = of("semi_annually") + @JvmField val BI_WEEKLY = of("bi_weekly") - @JvmField val QUARTERLY = of("quarterly") + @JvmField val DAILY = of("daily") @JvmField val MONTHLY = of("monthly") - @JvmField val SEMI_MONTHLY = of("semi_monthly") + @JvmField val OTHER = of("other") - @JvmField val BI_WEEKLY = of("bi_weekly") + @JvmField val QUARTERLY = of("quarterly") - @JvmField val WEEKLY = of("weekly") + @JvmField val SEMI_ANNUALLY = of("semi_annually") - @JvmField val DAILY = of("daily") + @JvmField val SEMI_MONTHLY = of("semi_monthly") - @JvmField val OTHER = of("other") + @JvmField val WEEKLY = of("weekly") @JvmStatic fun of(value: String) = PayFrequency(JsonField.of(value)) } @@ -339,14 +339,14 @@ private constructor( /** An enum containing [PayFrequency]'s known values. */ enum class Known { ANNUALLY, - SEMI_ANNUALLY, - QUARTERLY, - MONTHLY, - SEMI_MONTHLY, BI_WEEKLY, - WEEKLY, DAILY, + MONTHLY, OTHER, + QUARTERLY, + SEMI_ANNUALLY, + SEMI_MONTHLY, + WEEKLY, } /** @@ -360,14 +360,14 @@ private constructor( */ enum class Value { ANNUALLY, - SEMI_ANNUALLY, - QUARTERLY, - MONTHLY, - SEMI_MONTHLY, BI_WEEKLY, - WEEKLY, DAILY, + MONTHLY, OTHER, + QUARTERLY, + SEMI_ANNUALLY, + SEMI_MONTHLY, + WEEKLY, /** * An enum member indicating that [PayFrequency] was instantiated with an unknown value. */ @@ -384,14 +384,14 @@ private constructor( fun value(): Value = when (this) { ANNUALLY -> Value.ANNUALLY - SEMI_ANNUALLY -> Value.SEMI_ANNUALLY - QUARTERLY -> Value.QUARTERLY - MONTHLY -> Value.MONTHLY - SEMI_MONTHLY -> Value.SEMI_MONTHLY BI_WEEKLY -> Value.BI_WEEKLY - WEEKLY -> Value.WEEKLY DAILY -> Value.DAILY + MONTHLY -> Value.MONTHLY OTHER -> Value.OTHER + QUARTERLY -> Value.QUARTERLY + SEMI_ANNUALLY -> Value.SEMI_ANNUALLY + SEMI_MONTHLY -> Value.SEMI_MONTHLY + WEEKLY -> Value.WEEKLY else -> Value._UNKNOWN } @@ -406,14 +406,14 @@ private constructor( fun known(): Known = when (this) { ANNUALLY -> Known.ANNUALLY - SEMI_ANNUALLY -> Known.SEMI_ANNUALLY - QUARTERLY -> Known.QUARTERLY - MONTHLY -> Known.MONTHLY - SEMI_MONTHLY -> Known.SEMI_MONTHLY BI_WEEKLY -> Known.BI_WEEKLY - WEEKLY -> Known.WEEKLY DAILY -> Known.DAILY + MONTHLY -> Known.MONTHLY OTHER -> Known.OTHER + QUARTERLY -> Known.QUARTERLY + SEMI_ANNUALLY -> Known.SEMI_ANNUALLY + SEMI_MONTHLY -> Known.SEMI_MONTHLY + WEEKLY -> Known.WEEKLY else -> throw FinchInvalidDataException("Unknown PayFrequency: $value") } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt index ae0b753f..9046f7a8 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt @@ -12,6 +12,7 @@ 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 @@ -105,10 +106,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 individualId(): Optional = individualId.getOptional("individual_id") + fun individualId(): String = individualId.getRequired("individual_id") /** * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -242,7 +243,23 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [PayStatement]. */ + /** + * Returns a mutable builder for constructing an instance of [PayStatement]. + * + * The following fields are required: + * ```java + * .earnings() + * .employeeDeductions() + * .employerContributions() + * .grossPay() + * .individualId() + * .netPay() + * .paymentMethod() + * .taxes() + * .totalHours() + * .type() + * ``` + */ @JvmStatic fun builder() = Builder() } @@ -252,13 +269,13 @@ private constructor( private var earnings: JsonField>? = null private var employeeDeductions: JsonField>? = null private var employerContributions: JsonField>? = null - private var grossPay: JsonField = JsonMissing.of() - private var individualId: JsonField = JsonMissing.of() - private var netPay: JsonField = JsonMissing.of() - private var paymentMethod: JsonField = JsonMissing.of() + private var grossPay: JsonField? = null + private var individualId: JsonField? = null + private var netPay: JsonField? = null + private var paymentMethod: JsonField? = null private var taxes: JsonField>? = null - private var totalHours: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() + private var totalHours: JsonField? = null + private var type: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -517,19 +534,37 @@ private constructor( * Returns an immutable instance of [PayStatement]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .earnings() + * .employeeDeductions() + * .employerContributions() + * .grossPay() + * .individualId() + * .netPay() + * .paymentMethod() + * .taxes() + * .totalHours() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): PayStatement = PayStatement( - (earnings ?: JsonMissing.of()).map { it.toImmutable() }, - (employeeDeductions ?: JsonMissing.of()).map { it.toImmutable() }, - (employerContributions ?: JsonMissing.of()).map { it.toImmutable() }, - grossPay, - individualId, - netPay, - paymentMethod, - (taxes ?: JsonMissing.of()).map { it.toImmutable() }, - totalHours, - type, + checkRequired("earnings", earnings).map { it.toImmutable() }, + checkRequired("employeeDeductions", employeeDeductions).map { it.toImmutable() }, + checkRequired("employerContributions", employerContributions).map { + it.toImmutable() + }, + checkRequired("grossPay", grossPay), + checkRequired("individualId", individualId), + checkRequired("netPay", netPay), + checkRequired("paymentMethod", paymentMethod), + checkRequired("taxes", taxes).map { it.toImmutable() }, + checkRequired("totalHours", totalHours), + checkRequired("type", type), additionalProperties.toMutableMap(), ) } @@ -585,27 +620,27 @@ private constructor( class Earning private constructor( private val amount: JsonField, - private val attributes: JsonField, private val currency: JsonField, private val hours: JsonField, private val name: JsonField, private val type: JsonField, + private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("hours") @ExcludeMissing hours: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(amount, attributes, currency, hours, name, type, mutableMapOf()) + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), + ) : this(amount, currency, hours, name, type, attributes, mutableMapOf()) /** * The earnings amount in cents. @@ -615,12 +650,6 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * The earnings currency code. * @@ -655,20 +684,17 @@ private constructor( fun type(): Optional = type.getOptional("type") /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + fun attributes(): Optional = attributes.getOptional("attributes") /** - * Returns the raw JSON value of [attributes]. + * Returns the raw JSON value of [amount]. * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount /** * Returns the raw JSON value of [currency]. @@ -698,6 +724,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -712,29 +747,40 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Earning]. */ + /** + * Returns a mutable builder for constructing an instance of [Earning]. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .hours() + * .name() + * .type() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Earning]. */ class Builder internal constructor() { - private var amount: JsonField = JsonMissing.of() + private var amount: JsonField? = null + private var currency: JsonField? = null + private var hours: JsonField? = null + private var name: JsonField? = null + private var type: JsonField? = null private var attributes: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var hours: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(earning: Earning) = apply { amount = earning.amount - attributes = earning.attributes currency = earning.currency hours = earning.hours name = earning.name type = earning.type + attributes = earning.attributes additionalProperties = earning.additionalProperties.toMutableMap() } @@ -760,22 +806,6 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } - fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - /** The earnings currency code. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -846,6 +876,22 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } + fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -869,15 +915,26 @@ private constructor( * Returns an immutable instance of [Earning]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .hours() + * .name() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Earning = Earning( - amount, + checkRequired("amount", amount), + checkRequired("currency", currency), + checkRequired("hours", hours), + checkRequired("name", name), + checkRequired("type", type), attributes, - currency, - hours, - name, - type, additionalProperties.toMutableMap(), ) } @@ -890,11 +947,11 @@ private constructor( } amount() - attributes().ifPresent { it.validate() } currency() hours() name() type().ifPresent { it.validate() } + attributes().ifPresent { it.validate() } validated = true } @@ -915,162 +972,376 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (hours.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) - - class Attributes - private constructor( - private val metadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("metadata") - @ExcludeMissing - metadata: JsonField = JsonMissing.of() - ) : this(metadata, mutableMapOf()) + (type.asKnown().getOrNull()?.validity() ?: 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun metadata(): Optional = metadata.getOptional("metadata") + /** The type of earning. */ + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { /** - * Returns the raw JSON value of [metadata]. + * Returns this class instance's raw value. * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected - * type. + * 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. */ - @JsonProperty("metadata") - @ExcludeMissing - fun _metadata(): JsonField = metadata - - @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) + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value companion object { - /** Returns a mutable builder for constructing an instance of [Attributes]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Attributes]. */ - class Builder internal constructor() { + @JvmField val SALARY = of("salary") - private var metadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + @JvmField val WAGE = of("wage") - @JvmSynthetic - internal fun from(attributes: Attributes) = apply { - metadata = attributes.metadata - additionalProperties = attributes.additionalProperties.toMutableMap() - } + @JvmField val REIMBURSEMENT = of("reimbursement") - fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + @JvmField val OVERTIME = of("overtime") - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + @JvmField val SEVERANCE = of("severance") - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + @JvmField val DOUBLE_OVERTIME = of("double_overtime") - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + @JvmField val PTO = of("pto") - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } + @JvmField val SICK = of("sick") - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + @JvmField val BONUS = of("bonus") - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + @JvmField val COMMISSION = of("commission") - /** - * Returns an immutable instance of [Attributes]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Attributes = Attributes(metadata, additionalProperties.toMutableMap()) - } + @JvmField val TIPS = of("tips") - private var validated: Boolean = false + @JvmField val _1099 = of("1099") - fun validate(): Attributes = apply { - if (validated) { - return@apply - } + @JvmField val OTHER = of("other") - metadata().ifPresent { it.validate() } - validated = true + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false - } + /** An enum containing [Type]'s known values. */ + enum class Known { + SALARY, + WAGE, + REIMBURSEMENT, + OVERTIME, + SEVERANCE, + DOUBLE_OVERTIME, + PTO, + SICK, + BONUS, + COMMISSION, + TIPS, + _1099, + OTHER, + } /** - * Returns a score indicating how many valid values are contained in this object - * recursively. + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. * - * Used for best match union deserialization. + * 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. */ - @JvmSynthetic - internal fun validity(): Int = (metadata.asKnown().getOrNull()?.validity() ?: 0) - - class Metadata - private constructor( - private val metadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("metadata") - @ExcludeMissing - metadata: JsonField = JsonMissing.of() - ) : this(metadata, mutableMapOf()) + enum class Value { + SALARY, + WAGE, + REIMBURSEMENT, + OVERTIME, + SEVERANCE, + DOUBLE_OVERTIME, + PTO, + SICK, + BONUS, + COMMISSION, + TIPS, + _1099, + OTHER, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } - /** - * The metadata to be attached to the entity by existing rules. It is a key-value + /** + * 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) { + SALARY -> Value.SALARY + WAGE -> Value.WAGE + REIMBURSEMENT -> Value.REIMBURSEMENT + OVERTIME -> Value.OVERTIME + SEVERANCE -> Value.SEVERANCE + DOUBLE_OVERTIME -> Value.DOUBLE_OVERTIME + PTO -> Value.PTO + SICK -> Value.SICK + BONUS -> Value.BONUS + COMMISSION -> Value.COMMISSION + TIPS -> Value.TIPS + _1099 -> Value._1099 + OTHER -> Value.OTHER + 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) { + SALARY -> Known.SALARY + WAGE -> Known.WAGE + REIMBURSEMENT -> Known.REIMBURSEMENT + OVERTIME -> Known.OVERTIME + SEVERANCE -> Known.SEVERANCE + DOUBLE_OVERTIME -> Known.DOUBLE_OVERTIME + PTO -> Known.PTO + SICK -> Known.SICK + BONUS -> Known.BONUS + COMMISSION -> Known.COMMISSION + TIPS -> Known.TIPS + _1099 -> Known._1099 + OTHER -> Known.OTHER + 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() + } + + class Attributes + private constructor( + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of() + ) : this(metadata, 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 metadata(): Metadata = metadata.getRequired("metadata") + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [Attributes]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Attributes]. */ + class Builder internal constructor() { + + private var metadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(attributes: Attributes) = apply { + metadata = attributes.metadata + additionalProperties = attributes.additionalProperties.toMutableMap() + } + + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + 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 [Attributes]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Attributes = + Attributes( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Attributes = apply { + if (validated) { + return@apply + } + + metadata().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 = (metadata.asKnown().getOrNull()?.validity() ?: 0) + + class Metadata + private constructor( + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of() + ) : this(metadata, mutableMapOf()) + + /** + * The metadata to be attached to the entity by existing rules. It is a key-value * pairs where the values can be of any type (string, number, boolean, object, * array, etc.). * - * @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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): InnerMetadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -1096,14 +1367,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Metadata]. */ + /** + * Returns a mutable builder for constructing an instance of [Metadata]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -1156,8 +1434,19 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = Metadata(metadata, additionalProperties.toMutableMap()) + fun build(): Metadata = + Metadata( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1167,7 +1456,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -1287,252 +1576,58 @@ private constructor( !value.isNull() && !value.isMissing() } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is InnerMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "InnerMetadata{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Metadata && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Metadata{metadata=$metadata, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Attributes && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Attributes{metadata=$metadata, additionalProperties=$additionalProperties}" - } - - /** The type of earning. */ - 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 SALARY = of("salary") - - @JvmField val WAGE = of("wage") - - @JvmField val REIMBURSEMENT = of("reimbursement") - - @JvmField val OVERTIME = of("overtime") - - @JvmField val SEVERANCE = of("severance") - - @JvmField val DOUBLE_OVERTIME = of("double_overtime") - - @JvmField val PTO = of("pto") - - @JvmField val SICK = of("sick") - - @JvmField val BONUS = of("bonus") - - @JvmField val COMMISSION = of("commission") - - @JvmField val TIPS = of("tips") - - @JvmField val _1099 = of("1099") - - @JvmField val OTHER = of("other") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - SALARY, - WAGE, - REIMBURSEMENT, - OVERTIME, - SEVERANCE, - DOUBLE_OVERTIME, - PTO, - SICK, - BONUS, - COMMISSION, - TIPS, - _1099, - OTHER, - } - - /** - * 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 { - SALARY, - WAGE, - REIMBURSEMENT, - OVERTIME, - SEVERANCE, - DOUBLE_OVERTIME, - PTO, - SICK, - BONUS, - COMMISSION, - TIPS, - _1099, - OTHER, - /** 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) { - SALARY -> Value.SALARY - WAGE -> Value.WAGE - REIMBURSEMENT -> Value.REIMBURSEMENT - OVERTIME -> Value.OVERTIME - SEVERANCE -> Value.SEVERANCE - DOUBLE_OVERTIME -> Value.DOUBLE_OVERTIME - PTO -> Value.PTO - SICK -> Value.SICK - BONUS -> Value.BONUS - COMMISSION -> Value.COMMISSION - TIPS -> Value.TIPS - _1099 -> Value._1099 - OTHER -> Value.OTHER - 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) { - SALARY -> Known.SALARY - WAGE -> Known.WAGE - REIMBURSEMENT -> Known.REIMBURSEMENT - OVERTIME -> Known.OVERTIME - SEVERANCE -> Known.SEVERANCE - DOUBLE_OVERTIME -> Known.DOUBLE_OVERTIME - PTO -> Known.PTO - SICK -> Known.SICK - BONUS -> Known.BONUS - COMMISSION -> Known.COMMISSION - TIPS -> Known.TIPS - _1099 -> Known._1099 - OTHER -> Known.OTHER - else -> throw FinchInvalidDataException("Unknown Type: $value") - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - /** - * 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") - } + return /* spotless:off */ other is InnerMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } - private var validated: Boolean = false + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ - fun validate(): Type = apply { - if (validated) { - return@apply + override fun hashCode(): Int = hashCode + + override fun toString() = + "InnerMetadata{additionalProperties=$additionalProperties}" } - known() - 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 Metadata && metadata == other.metadata && 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 = if (value() == Value._UNKNOWN) 0 else 1 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Metadata{metadata=$metadata, additionalProperties=$additionalProperties}" + } 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 Attributes && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ } - override fun hashCode() = value.hashCode() + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } + /* spotless:on */ - override fun toString() = value.toString() + override fun hashCode(): Int = hashCode + + override fun toString() = + "Attributes{metadata=$metadata, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1540,43 +1635,43 @@ private constructor( return true } - return /* spotless:off */ other is Earning && amount == other.amount && attributes == other.attributes && currency == other.currency && hours == other.hours && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Earning && amount == other.amount && currency == other.currency && hours == other.hours && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, hours, name, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, currency, hours, name, type, attributes, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Earning{amount=$amount, attributes=$attributes, currency=$currency, hours=$hours, name=$name, type=$type, additionalProperties=$additionalProperties}" + "Earning{amount=$amount, currency=$currency, hours=$hours, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" } class EmployeeDeduction private constructor( private val amount: JsonField, - private val attributes: JsonField, private val currency: JsonField, private val name: JsonField, private val preTax: JsonField, private val type: JsonField, + private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("pre_tax") @ExcludeMissing preTax: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(amount, attributes, currency, name, preTax, type, mutableMapOf()) + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), + ) : this(amount, currency, name, preTax, type, attributes, mutableMapOf()) /** * The deduction amount in cents. @@ -1586,12 +1681,6 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * The deduction currency. * @@ -1625,20 +1714,17 @@ private constructor( fun type(): Optional = type.getOptional("type") /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + fun attributes(): Optional = attributes.getOptional("attributes") /** - * Returns the raw JSON value of [attributes]. + * Returns the raw JSON value of [amount]. * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount /** * Returns the raw JSON value of [currency]. @@ -1668,6 +1754,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -1682,29 +1777,40 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [EmployeeDeduction]. */ + /** + * Returns a mutable builder for constructing an instance of [EmployeeDeduction]. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .name() + * .preTax() + * .type() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [EmployeeDeduction]. */ class Builder internal constructor() { - private var amount: JsonField = JsonMissing.of() + private var amount: JsonField? = null + private var currency: JsonField? = null + private var name: JsonField? = null + private var preTax: JsonField? = null + private var type: JsonField? = null private var attributes: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var preTax: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(employeeDeduction: EmployeeDeduction) = apply { amount = employeeDeduction.amount - attributes = employeeDeduction.attributes currency = employeeDeduction.currency name = employeeDeduction.name preTax = employeeDeduction.preTax type = employeeDeduction.type + attributes = employeeDeduction.attributes additionalProperties = employeeDeduction.additionalProperties.toMutableMap() } @@ -1730,22 +1836,6 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } - fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - /** The deduction currency. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -1813,6 +1903,22 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } + fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1836,15 +1942,26 @@ private constructor( * Returns an immutable instance of [EmployeeDeduction]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .name() + * .preTax() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): EmployeeDeduction = EmployeeDeduction( - amount, + checkRequired("amount", amount), + checkRequired("currency", currency), + checkRequired("name", name), + checkRequired("preTax", preTax), + checkRequired("type", type), attributes, - currency, - name, - preTax, - type, additionalProperties.toMutableMap(), ) } @@ -1857,11 +1974,11 @@ private constructor( } amount() - attributes().ifPresent { it.validate() } currency() name() preTax() type().ifPresent { it.validate() } + attributes().ifPresent { it.validate() } validated = true } @@ -1882,11 +1999,11 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + (if (preTax.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) class Attributes private constructor( @@ -1902,10 +2019,11 @@ private constructor( ) : this(metadata, 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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): Metadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -1931,14 +2049,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Attributes]. */ + /** + * Returns a mutable builder for constructing an instance of [Attributes]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -1984,8 +2109,19 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Attributes = Attributes(metadata, additionalProperties.toMutableMap()) + fun build(): Attributes = + Attributes( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1995,7 +2131,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -2034,10 +2170,11 @@ private constructor( * pairs where the values can be of any type (string, number, boolean, object, * array, etc.). * - * @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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): InnerMetadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -2063,14 +2200,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Metadata]. */ + /** + * Returns a mutable builder for constructing an instance of [Metadata]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -2123,8 +2267,19 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = Metadata(metadata, additionalProperties.toMutableMap()) + fun build(): Metadata = + Metadata( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -2134,7 +2289,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -2313,41 +2468,41 @@ private constructor( return true } - return /* spotless:off */ other is EmployeeDeduction && amount == other.amount && attributes == other.attributes && currency == other.currency && name == other.name && preTax == other.preTax && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is EmployeeDeduction && amount == other.amount && currency == other.currency && name == other.name && preTax == other.preTax && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, name, preTax, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, currency, name, preTax, type, attributes, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "EmployeeDeduction{amount=$amount, attributes=$attributes, currency=$currency, name=$name, preTax=$preTax, type=$type, additionalProperties=$additionalProperties}" + "EmployeeDeduction{amount=$amount, currency=$currency, name=$name, preTax=$preTax, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" } class EmployerContribution private constructor( private val amount: JsonField, - private val attributes: JsonField, private val currency: JsonField, private val name: JsonField, private val type: JsonField, + private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(amount, attributes, currency, name, type, mutableMapOf()) + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), + ) : this(amount, currency, name, type, attributes, mutableMapOf()) /** * The contribution amount in cents. @@ -2357,12 +2512,6 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * The contribution currency. * @@ -2388,20 +2537,17 @@ private constructor( fun type(): Optional = type.getOptional("type") /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + fun attributes(): Optional = attributes.getOptional("attributes") /** - * Returns the raw JSON value of [attributes]. + * Returns the raw JSON value of [amount]. * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount /** * Returns the raw JSON value of [currency]. @@ -2424,6 +2570,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -2438,27 +2593,37 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [EmployerContribution]. */ + /** + * Returns a mutable builder for constructing an instance of [EmployerContribution]. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .name() + * .type() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [EmployerContribution]. */ class Builder internal constructor() { - private var amount: JsonField = JsonMissing.of() + private var amount: JsonField? = null + private var currency: JsonField? = null + private var name: JsonField? = null + private var type: JsonField? = null private var attributes: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(employerContribution: EmployerContribution) = apply { amount = employerContribution.amount - attributes = employerContribution.attributes currency = employerContribution.currency name = employerContribution.name type = employerContribution.type + attributes = employerContribution.attributes additionalProperties = employerContribution.additionalProperties.toMutableMap() } @@ -2484,22 +2649,6 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } - fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - /** The contribution currency. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -2537,13 +2686,29 @@ private constructor( fun type(type: Optional) = type(type.getOrNull()) /** - * Sets [Builder.type] to an arbitrary JSON value. + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [BenefitType] 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 attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. * - * You should usually call [Builder.type] with a well-typed [BenefitType] value instead. - * This method is primarily for setting the field to an undocumented or not yet + * You should usually call [Builder.attributes] with a well-typed [Attributes] 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 attributes(attributes: JsonField) = apply { + this.attributes = attributes + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -2568,14 +2733,24 @@ private constructor( * Returns an immutable instance of [EmployerContribution]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .name() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): EmployerContribution = EmployerContribution( - amount, + checkRequired("amount", amount), + checkRequired("currency", currency), + checkRequired("name", name), + checkRequired("type", type), attributes, - currency, - name, - type, additionalProperties.toMutableMap(), ) } @@ -2588,10 +2763,10 @@ private constructor( } amount() - attributes().ifPresent { it.validate() } currency() name() type().ifPresent { it.validate() } + attributes().ifPresent { it.validate() } validated = true } @@ -2612,10 +2787,10 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) class Attributes private constructor( @@ -2631,10 +2806,11 @@ private constructor( ) : this(metadata, 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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): Metadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -2660,14 +2836,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Attributes]. */ + /** + * Returns a mutable builder for constructing an instance of [Attributes]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -2713,8 +2896,19 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Attributes = Attributes(metadata, additionalProperties.toMutableMap()) + fun build(): Attributes = + Attributes( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -2724,7 +2918,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -2763,10 +2957,11 @@ private constructor( * pairs where the values can be of any type (string, number, boolean, object, * array, etc.). * - * @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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): InnerMetadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -2792,14 +2987,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Metadata]. */ + /** + * Returns a mutable builder for constructing an instance of [Metadata]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -2852,8 +3054,19 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = Metadata(metadata, additionalProperties.toMutableMap()) + fun build(): Metadata = + Metadata( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -2863,7 +3076,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -3042,17 +3255,17 @@ private constructor( return true } - return /* spotless:off */ other is EmployerContribution && amount == other.amount && attributes == other.attributes && currency == other.currency && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is EmployerContribution && amount == other.amount && currency == other.currency && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, name, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, currency, name, type, attributes, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "EmployerContribution{amount=$amount, attributes=$attributes, currency=$currency, name=$name, type=$type, additionalProperties=$additionalProperties}" + "EmployerContribution{amount=$amount, currency=$currency, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" } /** The payment method. */ @@ -3187,20 +3400,17 @@ private constructor( class Tax private constructor( private val amount: JsonField, - private val attributes: JsonField, private val currency: JsonField, private val employer: JsonField, private val name: JsonField, private val type: JsonField, + private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @@ -3209,7 +3419,10 @@ private constructor( employer: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(amount, attributes, currency, employer, name, type, mutableMapOf()) + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), + ) : this(amount, currency, employer, name, type, attributes, mutableMapOf()) /** * The tax amount in cents. @@ -3219,12 +3432,6 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * The currency code. * @@ -3258,20 +3465,17 @@ private constructor( fun type(): Optional = type.getOptional("type") /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + fun attributes(): Optional = attributes.getOptional("attributes") /** - * Returns the raw JSON value of [attributes]. + * Returns the raw JSON value of [amount]. * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount /** * Returns the raw JSON value of [currency]. @@ -3301,6 +3505,15 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -3315,29 +3528,40 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Tax]. */ + /** + * Returns a mutable builder for constructing an instance of [Tax]. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .employer() + * .name() + * .type() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Tax]. */ class Builder internal constructor() { - private var amount: JsonField = JsonMissing.of() + private var amount: JsonField? = null + private var currency: JsonField? = null + private var employer: JsonField? = null + private var name: JsonField? = null + private var type: JsonField? = null private var attributes: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var employer: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tax: Tax) = apply { amount = tax.amount - attributes = tax.attributes currency = tax.currency employer = tax.employer name = tax.name type = tax.type + attributes = tax.attributes additionalProperties = tax.additionalProperties.toMutableMap() } @@ -3363,22 +3587,6 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } - fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - /** The currency code. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -3438,88 +3646,255 @@ private constructor( fun type(type: Optional) = type(type.getOrNull()) /** - * Sets [Builder.type] to an arbitrary JSON value. + * 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 attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + + 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 [Tax]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .employer() + * .name() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tax = + Tax( + checkRequired("amount", amount), + checkRequired("currency", currency), + checkRequired("employer", employer), + checkRequired("name", name), + checkRequired("type", type), + attributes, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tax = apply { + if (validated) { + return@apply + } + + amount() + currency() + employer() + name() + type().ifPresent { it.validate() } + attributes().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 = + (if (amount.asKnown().isPresent) 1 else 0) + + (if (currency.asKnown().isPresent) 1 else 0) + + (if (employer.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) + + /** The type of taxes. */ + 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 STATE = of("state") + + @JvmField val FEDERAL = of("federal") + + @JvmField val LOCAL = of("local") + + @JvmField val FICA = of("fica") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + STATE, + FEDERAL, + LOCAL, + FICA, + } + + /** + * 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 { + STATE, + FEDERAL, + LOCAL, + FICA, + /** 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) { + STATE -> Value.STATE + FEDERAL -> Value.FEDERAL + LOCAL -> Value.LOCAL + FICA -> Value.FICA + 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) { + STATE -> Known.STATE + FEDERAL -> Known.FEDERAL + LOCAL -> Known.LOCAL + FICA -> Known.FICA + else -> throw FinchInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. * - * 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. + * 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 type(type: JsonField) = apply { this.type = type } + fun asString(): String = + _value().asString().orElseThrow { + FinchInvalidDataException("Value is not a String") + } - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + private var validated: Boolean = false - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + fun validate(): Type = apply { + if (validated) { + return@apply + } - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) + known() + validated = true } - fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } - - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + false + } /** - * Returns an immutable instance of [Tax]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * Further updates to this [Builder] will not mutate the returned instance. + * Used for best match union deserialization. */ - fun build(): Tax = - Tax( - amount, - attributes, - currency, - employer, - name, - type, - additionalProperties.toMutableMap(), - ) - } + @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(): Tax = apply { - if (validated) { - return@apply + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ } - amount() - attributes().ifPresent { it.validate() } - currency() - employer() - name() - type().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false - } + override fun hashCode() = value.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 (amount.asKnown().isPresent) 1 else 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + - (if (currency.asKnown().isPresent) 1 else 0) + - (if (employer.asKnown().isPresent) 1 else 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + override fun toString() = value.toString() + } class Attributes private constructor( @@ -3535,10 +3910,11 @@ private constructor( ) : this(metadata, 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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): Metadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -3564,14 +3940,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Attributes]. */ + /** + * Returns a mutable builder for constructing an instance of [Attributes]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -3617,8 +4000,19 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Attributes = Attributes(metadata, additionalProperties.toMutableMap()) + fun build(): Attributes = + Attributes( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -3628,7 +4022,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -3667,10 +4061,11 @@ private constructor( * pairs where the values can be of any type (string, number, boolean, object, * array, etc.). * - * @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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): InnerMetadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -3696,14 +4091,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Metadata]. */ + /** + * Returns a mutable builder for constructing an instance of [Metadata]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -3756,8 +4158,19 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = Metadata(metadata, additionalProperties.toMutableMap()) + fun build(): Metadata = + Metadata( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -3767,7 +4180,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -3941,162 +4354,22 @@ private constructor( "Attributes{metadata=$metadata, additionalProperties=$additionalProperties}" } - /** The type of taxes. */ - 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 STATE = of("state") - - @JvmField val FEDERAL = of("federal") - - @JvmField val LOCAL = of("local") - - @JvmField val FICA = of("fica") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - STATE, - FEDERAL, - LOCAL, - FICA, - } - - /** - * 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 { - STATE, - FEDERAL, - LOCAL, - FICA, - /** 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) { - STATE -> Value.STATE - FEDERAL -> Value.FEDERAL - LOCAL -> Value.LOCAL - FICA -> Value.FICA - 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) { - STATE -> Known.STATE - FEDERAL -> Known.FEDERAL - LOCAL -> Known.LOCAL - FICA -> Known.FICA - 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 Tax && amount == other.amount && attributes == other.attributes && currency == other.currency && employer == other.employer && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Tax && amount == other.amount && currency == other.currency && employer == other.employer && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, employer, name, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, currency, employer, name, type, attributes, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Tax{amount=$amount, attributes=$attributes, currency=$currency, employer=$employer, name=$name, type=$type, additionalProperties=$additionalProperties}" + "Tax{amount=$amount, currency=$currency, employer=$employer, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" } /** The type of the payment associated with the pay statement. */ diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementItemListResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementItemListResponse.kt index 846be3c3..172c2ddf 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementItemListResponse.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementItemListResponse.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.core.toImmutable import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections @@ -38,26 +39,26 @@ private constructor( /** * The attributes of the pay statement item. * - * @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 attributes(): Optional = attributes.getOptional("attributes") + fun attributes(): Attributes = attributes.getRequired("attributes") /** * The category of the pay statement item. * - * @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 category(): Optional = category.getOptional("category") + fun category(): Category = category.getRequired("category") /** * The name of the pay statement item. * - * @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 name(): Optional = name.getOptional("name") + fun name(): String = name.getRequired("name") /** * Returns the raw JSON value of [attributes]. @@ -98,6 +99,13 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [PayStatementItemListResponse]. + * + * The following fields are required: + * ```java + * .attributes() + * .category() + * .name() + * ``` */ @JvmStatic fun builder() = Builder() } @@ -105,9 +113,9 @@ private constructor( /** A builder for [PayStatementItemListResponse]. */ class Builder internal constructor() { - private var attributes: JsonField = JsonMissing.of() - private var category: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() + private var attributes: JsonField? = null + private var category: JsonField? = null + private var name: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -176,12 +184,21 @@ private constructor( * Returns an immutable instance of [PayStatementItemListResponse]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .attributes() + * .category() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): PayStatementItemListResponse = PayStatementItemListResponse( - attributes, - category, - name, + checkRequired("attributes", attributes), + checkRequired("category", category), + checkRequired("name", name), additionalProperties.toMutableMap(), ) } @@ -193,8 +210,8 @@ private constructor( return@apply } - attributes().ifPresent { it.validate() } - category().ifPresent { it.validate() } + attributes().validate() + category().validate() name() validated = true } @@ -221,8 +238,8 @@ private constructor( /** The attributes of the pay statement item. */ class Attributes private constructor( - private val employer: JsonField, private val metadata: JsonField, + private val employer: JsonField, private val preTax: JsonField, private val type: JsonField, private val additionalProperties: MutableMap, @@ -230,32 +247,32 @@ private constructor( @JsonCreator private constructor( - @JsonProperty("employer") - @ExcludeMissing - employer: JsonField = JsonMissing.of(), @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("employer") + @ExcludeMissing + employer: JsonField = JsonMissing.of(), @JsonProperty("pre_tax") @ExcludeMissing preTax: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(employer, metadata, preTax, type, mutableMapOf()) + ) : this(metadata, employer, preTax, type, mutableMapOf()) /** - * `true` if the amount is paid by the employers. This field is only available for taxes. + * The metadata of the pay statement item derived by the rules engine if available. Each + * attribute will be a key-value pair defined by a rule. * * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun employer(): Optional = employer.getOptional("employer") + fun metadata(): Optional = metadata.getOptional("metadata") /** - * The metadata of the pay statement item derived by the rules engine if available. Each - * attribute will be a key-value pair defined by a rule. + * `true` if the amount is paid by the employers. This field is only available for taxes. * * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = metadata.getOptional("metadata") + fun employer(): Optional = employer.getOptional("employer") /** * `true` if the pay statement item is pre-tax. This field is only available for employee @@ -275,18 +292,18 @@ private constructor( fun type(): Optional = type.getOptional("type") /** - * Returns the raw JSON value of [employer]. + * Returns the raw JSON value of [metadata]. * - * Unlike [employer], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("employer") @ExcludeMissing fun _employer(): JsonField = employer + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata /** - * Returns the raw JSON value of [metadata]. + * Returns the raw JSON value of [employer]. * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [employer], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + @JsonProperty("employer") @ExcludeMissing fun _employer(): JsonField = employer /** * Returns the raw JSON value of [preTax]. @@ -316,28 +333,53 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Attributes]. */ + /** + * Returns a mutable builder for constructing an instance of [Attributes]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { + private var metadata: JsonField? = null private var employer: JsonField = JsonMissing.of() - private var metadata: JsonField = JsonMissing.of() private var preTax: JsonField = JsonMissing.of() private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(attributes: Attributes) = apply { - employer = attributes.employer metadata = attributes.metadata + employer = attributes.employer preTax = attributes.preTax type = attributes.type additionalProperties = attributes.additionalProperties.toMutableMap() } + /** + * The metadata of the pay statement item derived by the rules engine if available. Each + * attribute will be a key-value pair defined by a rule. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** * `true` if the amount is paid by the employers. This field is only available for * taxes. @@ -363,24 +405,6 @@ private constructor( */ fun employer(employer: JsonField) = apply { this.employer = employer } - /** - * The metadata of the pay statement item derived by the rules engine if available. Each - * attribute will be a key-value pair defined by a rule. - */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - /** * `true` if the pay statement item is pre-tax. This field is only available for * employee deductions. @@ -444,9 +468,22 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Attributes = - Attributes(employer, metadata, preTax, type, additionalProperties.toMutableMap()) + Attributes( + checkRequired("metadata", metadata), + employer, + preTax, + type, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -456,8 +493,8 @@ private constructor( return@apply } - employer() metadata().ifPresent { it.validate() } + employer() preTax() type() validated = true @@ -479,8 +516,8 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (employer.asKnown().isPresent) 1 else 0) + - (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (employer.asKnown().isPresent) 1 else 0) + (if (preTax.asKnown().isPresent) 1 else 0) + (if (type.asKnown().isPresent) 1 else 0) @@ -597,17 +634,17 @@ private constructor( return true } - return /* spotless:off */ other is Attributes && employer == other.employer && metadata == other.metadata && preTax == other.preTax && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Attributes && metadata == other.metadata && employer == other.employer && preTax == other.preTax && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(employer, metadata, preTax, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(metadata, employer, preTax, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Attributes{employer=$employer, metadata=$metadata, preTax=$preTax, type=$type, additionalProperties=$additionalProperties}" + "Attributes{metadata=$metadata, employer=$employer, preTax=$preTax, type=$type, additionalProperties=$additionalProperties}" } /** The category of the pay statement item. */ diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponse.kt index 3f5cf6c6..ed1418b5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponse.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponse.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 PayStatementResponse @@ -34,22 +34,22 @@ private constructor( ) : this(body, code, paymentId, 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(): PayStatementResponseBody = 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 paymentId(): Optional = paymentId.getOptional("payment_id") + fun paymentId(): String = paymentId.getRequired("payment_id") /** * Returns the raw JSON value of [body]. @@ -86,16 +86,25 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [PayStatementResponse]. */ + /** + * Returns a mutable builder for constructing an instance of [PayStatementResponse]. + * + * The following fields are required: + * ```java + * .body() + * .code() + * .paymentId() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [PayStatementResponse]. */ class Builder internal constructor() { - private var body: JsonField = JsonMissing.of() - private var code: JsonField = JsonMissing.of() - private var paymentId: JsonField = JsonMissing.of() + private var body: JsonField? = null + private var code: JsonField? = null + private var paymentId: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -161,9 +170,23 @@ private constructor( * Returns an immutable instance of [PayStatementResponse]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .body() + * .code() + * .paymentId() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): PayStatementResponse = - PayStatementResponse(body, code, paymentId, additionalProperties.toMutableMap()) + PayStatementResponse( + checkRequired("body", body), + checkRequired("code", code), + checkRequired("paymentId", paymentId), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -173,7 +196,7 @@ private constructor( return@apply } - body().ifPresent { it.validate() } + body().validate() code() paymentId() validated = true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponseBody.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponseBody.kt index 66722b9f..712d6020 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponseBody.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponseBody.kt @@ -11,6 +11,7 @@ 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 @@ -34,18 +35,16 @@ private constructor( ) : this(paging, payStatements, 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 paging(): Optional = paging.getOptional("paging") + fun paging(): Paging = paging.getRequired("paging") /** - * The array of pay statements for the current payment. - * - * @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 payStatements(): Optional> = payStatements.getOptional("pay_statements") + fun payStatements(): List = payStatements.getRequired("pay_statements") /** * Returns the raw JSON value of [paging]. @@ -77,14 +76,22 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [PayStatementResponseBody]. */ + /** + * Returns a mutable builder for constructing an instance of [PayStatementResponseBody]. + * + * The following fields are required: + * ```java + * .paging() + * .payStatements() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [PayStatementResponseBody]. */ class Builder internal constructor() { - private var paging: JsonField = JsonMissing.of() + private var paging: JsonField? = null private var payStatements: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -105,7 +112,6 @@ private constructor( */ fun paging(paging: JsonField) = apply { this.paging = paging } - /** The array of pay statements for the current payment. */ fun payStatements(payStatements: List) = payStatements(JsonField.of(payStatements)) @@ -155,11 +161,19 @@ private constructor( * Returns an immutable instance of [PayStatementResponseBody]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .paging() + * .payStatements() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): PayStatementResponseBody = PayStatementResponseBody( - paging, - (payStatements ?: JsonMissing.of()).map { it.toImmutable() }, + checkRequired("paging", paging), + checkRequired("payStatements", payStatements).map { it.toImmutable() }, additionalProperties.toMutableMap(), ) } @@ -171,8 +185,8 @@ private constructor( return@apply } - paging().ifPresent { it.validate() } - payStatements().ifPresent { it.forEach { it.validate() } } + paging().validate() + payStatements().forEach { it.validate() } validated = true } @@ -194,6 +208,195 @@ private constructor( (paging.asKnown().getOrNull()?.validity() ?: 0) + (payStatements.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + class Paging + private constructor( + private val offset: JsonField, + private val count: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("offset") @ExcludeMissing offset: JsonField = JsonMissing.of(), + @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) + * + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun count(): Optional = count.getOptional("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 + + /** + * Returns the raw JSON value of [count]. + * + * Unlike [count], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("count") @ExcludeMissing fun _count(): JsonField = count + + @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 [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 additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(paging: Paging) = apply { + offset = paging.offset + count = paging.count + additionalProperties = paging.additionalProperties.toMutableMap() + } + + /** The current start index of the returned list of elements */ + fun offset(offset: Long) = offset(JsonField.of(offset)) + + /** + * Sets [Builder.offset] to an arbitrary JSON value. + * + * 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 offset(offset: JsonField) = apply { this.offset = 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.count] to an arbitrary JSON value. + * + * 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 count(count: JsonField) = apply { this.count = count } + + 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 [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(checkRequired("offset", offset), count, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Paging = apply { + if (validated) { + return@apply + } + + offset() + count() + 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 (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 && offset == other.offset && count == other.count && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(offset, count, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Paging{offset=$offset, count=$count, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Payment.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Payment.kt index 27d85584..c3dfdb32 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Payment.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Payment.kt @@ -12,6 +12,7 @@ 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 @@ -83,10 +84,10 @@ private constructor( /** * The unique id for the payment. * - * @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") /** * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -273,25 +274,43 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Payment]. */ + /** + * Returns a mutable builder for constructing an instance of [Payment]. + * + * The following fields are required: + * ```java + * .id() + * .companyDebit() + * .debitDate() + * .employeeTaxes() + * .employerTaxes() + * .grossPay() + * .individualIds() + * .netPay() + * .payDate() + * .payFrequencies() + * .payGroupIds() + * .payPeriod() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Payment]. */ class Builder internal constructor() { - private var id: JsonField = JsonMissing.of() - private var companyDebit: JsonField = JsonMissing.of() - private var debitDate: JsonField = JsonMissing.of() - private var employeeTaxes: JsonField = JsonMissing.of() - private var employerTaxes: JsonField = JsonMissing.of() - private var grossPay: JsonField = JsonMissing.of() + private var id: JsonField? = null + private var companyDebit: JsonField? = null + private var debitDate: JsonField? = null + private var employeeTaxes: JsonField? = null + private var employerTaxes: JsonField? = null + private var grossPay: JsonField? = null private var individualIds: JsonField>? = null - private var netPay: JsonField = JsonMissing.of() - private var payDate: JsonField = JsonMissing.of() + private var netPay: JsonField? = null + private var payDate: JsonField? = null private var payFrequencies: JsonField>? = null private var payGroupIds: JsonField>? = null - private var payPeriod: JsonField = JsonMissing.of() + private var payPeriod: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -554,21 +573,39 @@ private constructor( * Returns an immutable instance of [Payment]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .companyDebit() + * .debitDate() + * .employeeTaxes() + * .employerTaxes() + * .grossPay() + * .individualIds() + * .netPay() + * .payDate() + * .payFrequencies() + * .payGroupIds() + * .payPeriod() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Payment = Payment( - id, - companyDebit, - debitDate, - employeeTaxes, - employerTaxes, - grossPay, - (individualIds ?: JsonMissing.of()).map { it.toImmutable() }, - netPay, - payDate, - (payFrequencies ?: JsonMissing.of()).map { it.toImmutable() }, - (payGroupIds ?: JsonMissing.of()).map { it.toImmutable() }, - payPeriod, + checkRequired("id", id), + checkRequired("companyDebit", companyDebit), + checkRequired("debitDate", debitDate), + checkRequired("employeeTaxes", employeeTaxes), + checkRequired("employerTaxes", employerTaxes), + checkRequired("grossPay", grossPay), + checkRequired("individualIds", individualIds).map { it.toImmutable() }, + checkRequired("netPay", netPay), + checkRequired("payDate", payDate), + checkRequired("payFrequencies", payFrequencies).map { it.toImmutable() }, + checkRequired("payGroupIds", payGroupIds).map { it.toImmutable() }, + checkRequired("payPeriod", payPeriod), additionalProperties.toMutableMap(), ) } @@ -640,21 +677,21 @@ private constructor( @JvmField val ANNUALLY = of("annually") - @JvmField val SEMI_ANNUALLY = of("semi_annually") + @JvmField val BI_WEEKLY = of("bi_weekly") - @JvmField val QUARTERLY = of("quarterly") + @JvmField val DAILY = of("daily") @JvmField val MONTHLY = of("monthly") - @JvmField val SEMI_MONTHLY = of("semi_monthly") + @JvmField val OTHER = of("other") - @JvmField val BI_WEEKLY = of("bi_weekly") + @JvmField val QUARTERLY = of("quarterly") - @JvmField val WEEKLY = of("weekly") + @JvmField val SEMI_ANNUALLY = of("semi_annually") - @JvmField val DAILY = of("daily") + @JvmField val SEMI_MONTHLY = of("semi_monthly") - @JvmField val OTHER = of("other") + @JvmField val WEEKLY = of("weekly") @JvmStatic fun of(value: String) = PayFrequency(JsonField.of(value)) } @@ -662,14 +699,14 @@ private constructor( /** An enum containing [PayFrequency]'s known values. */ enum class Known { ANNUALLY, - SEMI_ANNUALLY, - QUARTERLY, - MONTHLY, - SEMI_MONTHLY, BI_WEEKLY, - WEEKLY, DAILY, + MONTHLY, OTHER, + QUARTERLY, + SEMI_ANNUALLY, + SEMI_MONTHLY, + WEEKLY, } /** @@ -683,14 +720,14 @@ private constructor( */ enum class Value { ANNUALLY, - SEMI_ANNUALLY, - QUARTERLY, - MONTHLY, - SEMI_MONTHLY, BI_WEEKLY, - WEEKLY, DAILY, + MONTHLY, OTHER, + QUARTERLY, + SEMI_ANNUALLY, + SEMI_MONTHLY, + WEEKLY, /** * An enum member indicating that [PayFrequency] was instantiated with an unknown value. */ @@ -707,14 +744,14 @@ private constructor( fun value(): Value = when (this) { ANNUALLY -> Value.ANNUALLY - SEMI_ANNUALLY -> Value.SEMI_ANNUALLY - QUARTERLY -> Value.QUARTERLY - MONTHLY -> Value.MONTHLY - SEMI_MONTHLY -> Value.SEMI_MONTHLY BI_WEEKLY -> Value.BI_WEEKLY - WEEKLY -> Value.WEEKLY DAILY -> Value.DAILY + MONTHLY -> Value.MONTHLY OTHER -> Value.OTHER + QUARTERLY -> Value.QUARTERLY + SEMI_ANNUALLY -> Value.SEMI_ANNUALLY + SEMI_MONTHLY -> Value.SEMI_MONTHLY + WEEKLY -> Value.WEEKLY else -> Value._UNKNOWN } @@ -729,14 +766,14 @@ private constructor( fun known(): Known = when (this) { ANNUALLY -> Known.ANNUALLY - SEMI_ANNUALLY -> Known.SEMI_ANNUALLY - QUARTERLY -> Known.QUARTERLY - MONTHLY -> Known.MONTHLY - SEMI_MONTHLY -> Known.SEMI_MONTHLY BI_WEEKLY -> Known.BI_WEEKLY - WEEKLY -> Known.WEEKLY DAILY -> Known.DAILY + MONTHLY -> Known.MONTHLY OTHER -> Known.OTHER + QUARTERLY -> Known.QUARTERLY + SEMI_ANNUALLY -> Known.SEMI_ANNUALLY + SEMI_MONTHLY -> Known.SEMI_MONTHLY + WEEKLY -> Known.WEEKLY else -> throw FinchInvalidDataException("Unknown PayFrequency: $value") } @@ -848,15 +885,23 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [PayPeriod]. */ + /** + * Returns a mutable builder for constructing an instance of [PayPeriod]. + * + * The following fields are required: + * ```java + * .endDate() + * .startDate() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [PayPeriod]. */ class Builder internal constructor() { - private var endDate: JsonField = JsonMissing.of() - private var startDate: JsonField = JsonMissing.of() + private var endDate: JsonField? = null + private var startDate: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -917,9 +962,21 @@ private constructor( * Returns an immutable instance of [PayPeriod]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .endDate() + * .startDate() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): PayPeriod = - PayPeriod(endDate, startDate, additionalProperties.toMutableMap()) + PayPeriod( + checkRequired("endDate", endDate), + checkRequired("startDate", startDate), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt index 480911e5..f43df6a5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt @@ -13,6 +13,7 @@ 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.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.core.toImmutable @@ -613,10 +614,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 individualId(): Optional = individualId.getOptional("individual_id") + fun individualId(): String = individualId.getRequired("individual_id") /** * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -756,7 +757,23 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [PayStatement]. */ + /** + * Returns a mutable builder for constructing an instance of [PayStatement]. + * + * The following fields are required: + * ```java + * .earnings() + * .employeeDeductions() + * .employerContributions() + * .grossPay() + * .individualId() + * .netPay() + * .paymentMethod() + * .taxes() + * .totalHours() + * .type() + * ``` + */ @JvmStatic fun builder() = Builder() } @@ -766,13 +783,13 @@ private constructor( private var earnings: JsonField>? = null private var employeeDeductions: JsonField>? = null private var employerContributions: JsonField>? = null - private var grossPay: JsonField = JsonMissing.of() - private var individualId: JsonField = JsonMissing.of() - private var netPay: JsonField = JsonMissing.of() - private var paymentMethod: JsonField = JsonMissing.of() + private var grossPay: JsonField? = null + private var individualId: JsonField? = null + private var netPay: JsonField? = null + private var paymentMethod: JsonField? = null private var taxes: JsonField>? = null - private var totalHours: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() + private var totalHours: JsonField? = null + private var type: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -1041,19 +1058,39 @@ private constructor( * Returns an immutable instance of [PayStatement]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .earnings() + * .employeeDeductions() + * .employerContributions() + * .grossPay() + * .individualId() + * .netPay() + * .paymentMethod() + * .taxes() + * .totalHours() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): PayStatement = PayStatement( - (earnings ?: JsonMissing.of()).map { it.toImmutable() }, - (employeeDeductions ?: JsonMissing.of()).map { it.toImmutable() }, - (employerContributions ?: JsonMissing.of()).map { it.toImmutable() }, - grossPay, - individualId, - netPay, - paymentMethod, - (taxes ?: JsonMissing.of()).map { it.toImmutable() }, - totalHours, - type, + checkRequired("earnings", earnings).map { it.toImmutable() }, + checkRequired("employeeDeductions", employeeDeductions).map { + it.toImmutable() + }, + checkRequired("employerContributions", employerContributions).map { + it.toImmutable() + }, + checkRequired("grossPay", grossPay), + checkRequired("individualId", individualId), + checkRequired("netPay", netPay), + checkRequired("paymentMethod", paymentMethod), + checkRequired("taxes", taxes).map { it.toImmutable() }, + checkRequired("totalHours", totalHours), + checkRequired("type", type), additionalProperties.toMutableMap(), ) } @@ -1111,27 +1148,27 @@ private constructor( class Earning private constructor( private val amount: JsonField, - private val attributes: JsonField, private val currency: JsonField, private val hours: JsonField, private val name: JsonField, private val type: JsonField, + private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("hours") @ExcludeMissing hours: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(amount, attributes, currency, hours, name, type, mutableMapOf()) + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), + ) : this(amount, currency, hours, name, type, attributes, mutableMapOf()) /** * The earnings amount in cents. @@ -1141,12 +1178,6 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * The earnings currency code. * @@ -1181,21 +1212,17 @@ private constructor( fun type(): Optional = type.getOptional("type") /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + fun attributes(): Optional = attributes.getOptional("attributes") /** - * Returns the raw JSON value of [attributes]. + * Returns the raw JSON value of [amount]. * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected - * type. + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount /** * Returns the raw JSON value of [currency]. @@ -1226,6 +1253,16 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -1240,29 +1277,40 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Earning]. */ + /** + * Returns a mutable builder for constructing an instance of [Earning]. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .hours() + * .name() + * .type() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Earning]. */ class Builder internal constructor() { - private var amount: JsonField = JsonMissing.of() + private var amount: JsonField? = null + private var currency: JsonField? = null + private var hours: JsonField? = null + private var name: JsonField? = null + private var type: JsonField? = null private var attributes: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var hours: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(earning: Earning) = apply { amount = earning.amount - attributes = earning.attributes currency = earning.currency hours = earning.hours name = earning.name type = earning.type + attributes = earning.attributes additionalProperties = earning.additionalProperties.toMutableMap() } @@ -1288,24 +1336,6 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } - fun attributes(attributes: Attributes?) = - attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = - attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - /** The earnings currency code. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -1376,6 +1406,24 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } + fun attributes(attributes: Attributes?) = + attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = + attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1402,15 +1450,26 @@ private constructor( * Returns an immutable instance of [Earning]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .hours() + * .name() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Earning = Earning( - amount, + checkRequired("amount", amount), + checkRequired("currency", currency), + checkRequired("hours", hours), + checkRequired("name", name), + checkRequired("type", type), attributes, - currency, - hours, - name, - type, additionalProperties.toMutableMap(), ) } @@ -1423,11 +1482,11 @@ private constructor( } amount() - attributes().ifPresent { it.validate() } currency() hours() name() type().ifPresent { it.validate() } + attributes().ifPresent { it.validate() } validated = true } @@ -1448,146 +1507,361 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (hours.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) - - class Attributes - private constructor( - private val metadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("metadata") - @ExcludeMissing - metadata: JsonField = JsonMissing.of() - ) : this(metadata, mutableMapOf()) + (type.asKnown().getOrNull()?.validity() ?: 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. - * if the server responded with an unexpected value). - */ - fun metadata(): Optional = metadata.getOptional("metadata") + /** The type of earning. */ + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { /** - * Returns the raw JSON value of [metadata]. + * Returns this class instance's raw value. * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected - * type. + * 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. */ - @JsonProperty("metadata") - @ExcludeMissing - fun _metadata(): JsonField = metadata - - @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) + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value companion object { - /** Returns a mutable builder for constructing an instance of [Attributes]. */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Attributes]. */ - class Builder internal constructor() { + @JvmField val SALARY = of("salary") - private var metadata: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() + @JvmField val WAGE = of("wage") - @JvmSynthetic - internal fun from(attributes: Attributes) = apply { - metadata = attributes.metadata - additionalProperties = attributes.additionalProperties.toMutableMap() - } + @JvmField val REIMBURSEMENT = of("reimbursement") - fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + @JvmField val OVERTIME = of("overtime") - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + @JvmField val SEVERANCE = of("severance") - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + @JvmField val DOUBLE_OVERTIME = of("double_overtime") - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - additionalProperties.put(key, value) - } + @JvmField val PTO = of("pto") - fun putAllAdditionalProperties(additionalProperties: Map) = - apply { - this.additionalProperties.putAll(additionalProperties) - } + @JvmField val SICK = of("sick") - fun removeAdditionalProperty(key: String) = apply { - additionalProperties.remove(key) - } + @JvmField val BONUS = of("bonus") - fun removeAllAdditionalProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalProperty) - } + @JvmField val COMMISSION = of("commission") - /** - * Returns an immutable instance of [Attributes]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Attributes = - Attributes(metadata, additionalProperties.toMutableMap()) - } + @JvmField val TIPS = of("tips") - private var validated: Boolean = false + @JvmField val _1099 = of("1099") - fun validate(): Attributes = apply { - if (validated) { - return@apply - } + @JvmField val OTHER = of("other") - metadata().ifPresent { it.validate() } - validated = true + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false - } + /** An enum containing [Type]'s known values. */ + enum class Known { + SALARY, + WAGE, + REIMBURSEMENT, + OVERTIME, + SEVERANCE, + DOUBLE_OVERTIME, + PTO, + SICK, + BONUS, + COMMISSION, + TIPS, + _1099, + OTHER, + } /** - * Returns a score indicating how many valid values are contained in this object - * recursively. + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. * - * Used for best match union deserialization. + * 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. */ - @JvmSynthetic - internal fun validity(): Int = (metadata.asKnown().getOrNull()?.validity() ?: 0) + enum class Value { + SALARY, + WAGE, + REIMBURSEMENT, + OVERTIME, + SEVERANCE, + DOUBLE_OVERTIME, + PTO, + SICK, + BONUS, + COMMISSION, + TIPS, + _1099, + OTHER, + /** + * An enum member indicating that [Type] was instantiated with an unknown value. + */ + _UNKNOWN, + } - class Metadata - private constructor( - private val metadata: JsonField, - private val additionalProperties: MutableMap, - ) { + /** + * 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) { + SALARY -> Value.SALARY + WAGE -> Value.WAGE + REIMBURSEMENT -> Value.REIMBURSEMENT + OVERTIME -> Value.OVERTIME + SEVERANCE -> Value.SEVERANCE + DOUBLE_OVERTIME -> Value.DOUBLE_OVERTIME + PTO -> Value.PTO + SICK -> Value.SICK + BONUS -> Value.BONUS + COMMISSION -> Value.COMMISSION + TIPS -> Value.TIPS + _1099 -> Value._1099 + OTHER -> Value.OTHER + 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) { + SALARY -> Known.SALARY + WAGE -> Known.WAGE + REIMBURSEMENT -> Known.REIMBURSEMENT + OVERTIME -> Known.OVERTIME + SEVERANCE -> Known.SEVERANCE + DOUBLE_OVERTIME -> Known.DOUBLE_OVERTIME + PTO -> Known.PTO + SICK -> Known.SICK + BONUS -> Known.BONUS + COMMISSION -> Known.COMMISSION + TIPS -> Known.TIPS + _1099 -> Known._1099 + OTHER -> Known.OTHER + 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() + } + + class Attributes + private constructor( + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of() + ) : this(metadata, 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 metadata(): Metadata = metadata.getRequired("metadata") + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata + + @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 [Attributes]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Attributes]. */ + class Builder internal constructor() { + + private var metadata: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(attributes: Attributes) = apply { + metadata = attributes.metadata + additionalProperties = attributes.additionalProperties.toMutableMap() + } + + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + 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 [Attributes]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Attributes = + Attributes( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Attributes = apply { + if (validated) { + return@apply + } + + metadata().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 = (metadata.asKnown().getOrNull()?.validity() ?: 0) + + class Metadata + private constructor( + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { @JsonCreator private constructor( @@ -1601,10 +1875,11 @@ private constructor( * key-value pairs where the values can be of any type (string, number, boolean, * object, array, etc.). * - * @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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): InnerMetadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -1630,14 +1905,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Metadata]. */ + /** + * Returns a mutable builder for constructing an instance of [Metadata]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -1691,9 +1973,19 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Metadata = - Metadata(metadata, additionalProperties.toMutableMap()) + Metadata( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -1703,7 +1995,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -1815,265 +2107,68 @@ private constructor( /** * 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 = - additionalProperties.count { (_, value) -> - !value.isNull() && !value.isMissing() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is InnerMetadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "InnerMetadata{additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Metadata && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Metadata{metadata=$metadata, additionalProperties=$additionalProperties}" - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Attributes && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Attributes{metadata=$metadata, additionalProperties=$additionalProperties}" - } - - /** The type of earning. */ - 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 SALARY = of("salary") - - @JvmField val WAGE = of("wage") - - @JvmField val REIMBURSEMENT = of("reimbursement") - - @JvmField val OVERTIME = of("overtime") - - @JvmField val SEVERANCE = of("severance") - - @JvmField val DOUBLE_OVERTIME = of("double_overtime") - - @JvmField val PTO = of("pto") - - @JvmField val SICK = of("sick") - - @JvmField val BONUS = of("bonus") - - @JvmField val COMMISSION = of("commission") - - @JvmField val TIPS = of("tips") - - @JvmField val _1099 = of("1099") - - @JvmField val OTHER = of("other") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - SALARY, - WAGE, - REIMBURSEMENT, - OVERTIME, - SEVERANCE, - DOUBLE_OVERTIME, - PTO, - SICK, - BONUS, - COMMISSION, - TIPS, - _1099, - OTHER, - } - - /** - * 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 { - SALARY, - WAGE, - REIMBURSEMENT, - OVERTIME, - SEVERANCE, - DOUBLE_OVERTIME, - PTO, - SICK, - BONUS, - COMMISSION, - TIPS, - _1099, - OTHER, - /** - * 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) { - SALARY -> Value.SALARY - WAGE -> Value.WAGE - REIMBURSEMENT -> Value.REIMBURSEMENT - OVERTIME -> Value.OVERTIME - SEVERANCE -> Value.SEVERANCE - DOUBLE_OVERTIME -> Value.DOUBLE_OVERTIME - PTO -> Value.PTO - SICK -> Value.SICK - BONUS -> Value.BONUS - COMMISSION -> Value.COMMISSION - TIPS -> Value.TIPS - _1099 -> Value._1099 - OTHER -> Value.OTHER - 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) { - SALARY -> Known.SALARY - WAGE -> Known.WAGE - REIMBURSEMENT -> Known.REIMBURSEMENT - OVERTIME -> Known.OVERTIME - SEVERANCE -> Known.SEVERANCE - DOUBLE_OVERTIME -> Known.DOUBLE_OVERTIME - PTO -> Known.PTO - SICK -> Known.SICK - BONUS -> Known.BONUS - COMMISSION -> Known.COMMISSION - TIPS -> Known.TIPS - _1099 -> Known._1099 - OTHER -> Known.OTHER - else -> throw FinchInvalidDataException("Unknown Type: $value") - } + * object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> + !value.isNull() && !value.isMissing() + } - /** - * 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") - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } - private var validated: Boolean = false + return /* spotless:off */ other is InnerMetadata && additionalProperties == other.additionalProperties /* spotless:on */ + } - fun validate(): Type = apply { - if (validated) { - return@apply + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "InnerMetadata{additionalProperties=$additionalProperties}" } - known() - 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 Metadata && metadata == other.metadata && 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 = if (value() == Value._UNKNOWN) 0 else 1 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Metadata{metadata=$metadata, additionalProperties=$additionalProperties}" + } 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 Attributes && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ } - override fun hashCode() = value.hashCode() + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } + /* spotless:on */ - override fun toString() = value.toString() + override fun hashCode(): Int = hashCode + + override fun toString() = + "Attributes{metadata=$metadata, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -2081,36 +2176,33 @@ private constructor( return true } - return /* spotless:off */ other is Earning && amount == other.amount && attributes == other.attributes && currency == other.currency && hours == other.hours && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Earning && amount == other.amount && currency == other.currency && hours == other.hours && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, hours, name, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, currency, hours, name, type, attributes, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Earning{amount=$amount, attributes=$attributes, currency=$currency, hours=$hours, name=$name, type=$type, additionalProperties=$additionalProperties}" + "Earning{amount=$amount, currency=$currency, hours=$hours, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" } class EmployeeDeduction private constructor( private val amount: JsonField, - private val attributes: JsonField, private val currency: JsonField, private val name: JsonField, private val preTax: JsonField, private val type: JsonField, + private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @@ -2121,7 +2213,10 @@ private constructor( @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(amount, attributes, currency, name, preTax, type, mutableMapOf()) + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), + ) : this(amount, currency, name, preTax, type, attributes, mutableMapOf()) /** * The deduction amount in cents. @@ -2131,12 +2226,6 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * The deduction currency. * @@ -2170,21 +2259,17 @@ private constructor( fun type(): Optional = type.getOptional("type") /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + fun attributes(): Optional = attributes.getOptional("attributes") /** - * Returns the raw JSON value of [attributes]. + * Returns the raw JSON value of [amount]. * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected - * type. + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount /** * Returns the raw JSON value of [currency]. @@ -2215,6 +2300,16 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -2231,6 +2326,15 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [EmployeeDeduction]. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .name() + * .preTax() + * .type() + * ``` */ @JvmStatic fun builder() = Builder() } @@ -2238,22 +2342,22 @@ private constructor( /** A builder for [EmployeeDeduction]. */ class Builder internal constructor() { - private var amount: JsonField = JsonMissing.of() + private var amount: JsonField? = null + private var currency: JsonField? = null + private var name: JsonField? = null + private var preTax: JsonField? = null + private var type: JsonField? = null private var attributes: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var preTax: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(employeeDeduction: EmployeeDeduction) = apply { amount = employeeDeduction.amount - attributes = employeeDeduction.attributes currency = employeeDeduction.currency name = employeeDeduction.name preTax = employeeDeduction.preTax type = employeeDeduction.type + attributes = employeeDeduction.attributes additionalProperties = employeeDeduction.additionalProperties.toMutableMap() } @@ -2279,24 +2383,6 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } - fun attributes(attributes: Attributes?) = - attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = - attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - /** The deduction currency. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -2364,6 +2450,24 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } + fun attributes(attributes: Attributes?) = + attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = + attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -2390,15 +2494,26 @@ private constructor( * Returns an immutable instance of [EmployeeDeduction]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .name() + * .preTax() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): EmployeeDeduction = EmployeeDeduction( - amount, + checkRequired("amount", amount), + checkRequired("currency", currency), + checkRequired("name", name), + checkRequired("preTax", preTax), + checkRequired("type", type), attributes, - currency, - name, - preTax, - type, additionalProperties.toMutableMap(), ) } @@ -2411,11 +2526,11 @@ private constructor( } amount() - attributes().ifPresent { it.validate() } currency() name() preTax() type().ifPresent { it.validate() } + attributes().ifPresent { it.validate() } validated = true } @@ -2436,11 +2551,11 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + (if (preTax.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) class Attributes private constructor( @@ -2456,10 +2571,11 @@ private constructor( ) : this(metadata, 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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): Metadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -2485,14 +2601,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Attributes]. */ + /** + * Returns a mutable builder for constructing an instance of [Attributes]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -2538,9 +2661,19 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Attributes = - Attributes(metadata, additionalProperties.toMutableMap()) + Attributes( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -2550,7 +2683,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -2589,10 +2722,11 @@ private constructor( * key-value pairs where the values can be of any type (string, number, boolean, * object, array, etc.). * - * @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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): InnerMetadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -2618,14 +2752,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Metadata]. */ + /** + * Returns a mutable builder for constructing an instance of [Metadata]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -2679,9 +2820,19 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Metadata = - Metadata(metadata, additionalProperties.toMutableMap()) + Metadata( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -2691,7 +2842,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -2872,35 +3023,32 @@ private constructor( return true } - return /* spotless:off */ other is EmployeeDeduction && amount == other.amount && attributes == other.attributes && currency == other.currency && name == other.name && preTax == other.preTax && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is EmployeeDeduction && amount == other.amount && currency == other.currency && name == other.name && preTax == other.preTax && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, name, preTax, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, currency, name, preTax, type, attributes, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "EmployeeDeduction{amount=$amount, attributes=$attributes, currency=$currency, name=$name, preTax=$preTax, type=$type, additionalProperties=$additionalProperties}" + "EmployeeDeduction{amount=$amount, currency=$currency, name=$name, preTax=$preTax, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" } class EmployerContribution private constructor( private val amount: JsonField, - private val attributes: JsonField, private val currency: JsonField, private val name: JsonField, private val type: JsonField, + private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @@ -2908,7 +3056,10 @@ private constructor( @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(amount, attributes, currency, name, type, mutableMapOf()) + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), + ) : this(amount, currency, name, type, attributes, mutableMapOf()) /** * The contribution amount in cents. @@ -2918,12 +3069,6 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * The contribution currency. * @@ -2949,21 +3094,17 @@ private constructor( fun type(): Optional = type.getOptional("type") /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + fun attributes(): Optional = attributes.getOptional("attributes") /** - * Returns the raw JSON value of [attributes]. + * Returns the raw JSON value of [amount]. * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected - * type. + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount /** * Returns the raw JSON value of [currency]. @@ -2987,6 +3128,16 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -3003,6 +3154,14 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [EmployerContribution]. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .name() + * .type() + * ``` */ @JvmStatic fun builder() = Builder() } @@ -3010,20 +3169,20 @@ private constructor( /** A builder for [EmployerContribution]. */ class Builder internal constructor() { - private var amount: JsonField = JsonMissing.of() + private var amount: JsonField? = null + private var currency: JsonField? = null + private var name: JsonField? = null + private var type: JsonField? = null private var attributes: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(employerContribution: EmployerContribution) = apply { amount = employerContribution.amount - attributes = employerContribution.attributes currency = employerContribution.currency name = employerContribution.name type = employerContribution.type + attributes = employerContribution.attributes additionalProperties = employerContribution.additionalProperties.toMutableMap() } @@ -3049,24 +3208,6 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } - fun attributes(attributes: Attributes?) = - attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = - attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - /** The contribution currency. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -3112,6 +3253,24 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } + fun attributes(attributes: Attributes?) = + attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = + attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -3138,14 +3297,24 @@ private constructor( * Returns an immutable instance of [EmployerContribution]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .name() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): EmployerContribution = EmployerContribution( - amount, + checkRequired("amount", amount), + checkRequired("currency", currency), + checkRequired("name", name), + checkRequired("type", type), attributes, - currency, - name, - type, additionalProperties.toMutableMap(), ) } @@ -3158,10 +3327,10 @@ private constructor( } amount() - attributes().ifPresent { it.validate() } currency() name() type().ifPresent { it.validate() } + attributes().ifPresent { it.validate() } validated = true } @@ -3182,10 +3351,10 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) class Attributes private constructor( @@ -3201,10 +3370,11 @@ private constructor( ) : this(metadata, 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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): Metadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -3230,14 +3400,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Attributes]. */ + /** + * Returns a mutable builder for constructing an instance of [Attributes]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -3283,9 +3460,19 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Attributes = - Attributes(metadata, additionalProperties.toMutableMap()) + Attributes( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -3295,7 +3482,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -3334,10 +3521,11 @@ private constructor( * key-value pairs where the values can be of any type (string, number, boolean, * object, array, etc.). * - * @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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): InnerMetadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -3363,14 +3551,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Metadata]. */ + /** + * Returns a mutable builder for constructing an instance of [Metadata]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -3424,9 +3619,19 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Metadata = - Metadata(metadata, additionalProperties.toMutableMap()) + Metadata( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -3436,7 +3641,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -3617,17 +3822,17 @@ private constructor( return true } - return /* spotless:off */ other is EmployerContribution && amount == other.amount && attributes == other.attributes && currency == other.currency && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is EmployerContribution && amount == other.amount && currency == other.currency && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, name, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, currency, name, type, attributes, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "EmployerContribution{amount=$amount, attributes=$attributes, currency=$currency, name=$name, type=$type, additionalProperties=$additionalProperties}" + "EmployerContribution{amount=$amount, currency=$currency, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" } /** The payment method. */ @@ -3765,20 +3970,17 @@ private constructor( class Tax private constructor( private val amount: JsonField, - private val attributes: JsonField, private val currency: JsonField, private val employer: JsonField, private val name: JsonField, private val type: JsonField, + private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @@ -3787,7 +3989,10 @@ private constructor( employer: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(amount, attributes, currency, employer, name, type, mutableMapOf()) + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), + ) : this(amount, currency, employer, name, type, attributes, mutableMapOf()) /** * The tax amount in cents. @@ -3797,12 +4002,6 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * The currency code. * @@ -3836,21 +4035,17 @@ private constructor( fun type(): Optional = type.getOptional("type") /** - * Returns the raw JSON value of [amount]. - * - * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + fun attributes(): Optional = attributes.getOptional("attributes") /** - * Returns the raw JSON value of [attributes]. + * Returns the raw JSON value of [amount]. * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected - * type. + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes + @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount /** * Returns the raw JSON value of [currency]. @@ -3882,6 +4077,16 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -3896,29 +4101,40 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Tax]. */ + /** + * Returns a mutable builder for constructing an instance of [Tax]. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .employer() + * .name() + * .type() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Tax]. */ class Builder internal constructor() { - private var amount: JsonField = JsonMissing.of() + private var amount: JsonField? = null + private var currency: JsonField? = null + private var employer: JsonField? = null + private var name: JsonField? = null + private var type: JsonField? = null private var attributes: JsonField = JsonMissing.of() - private var currency: JsonField = JsonMissing.of() - private var employer: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tax: Tax) = apply { amount = tax.amount - attributes = tax.attributes currency = tax.currency employer = tax.employer name = tax.name type = tax.type + attributes = tax.attributes additionalProperties = tax.additionalProperties.toMutableMap() } @@ -3944,24 +4160,6 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } - fun attributes(attributes: Attributes?) = - attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = - attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - /** The currency code. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -4021,91 +4219,263 @@ private constructor( fun type(type: Optional) = type(type.getOrNull()) /** - * Sets [Builder.type] to an arbitrary JSON value. + * 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 attributes(attributes: Attributes?) = + attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = + attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + + 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 [Tax]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currency() + * .employer() + * .name() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Tax = + Tax( + checkRequired("amount", amount), + checkRequired("currency", currency), + checkRequired("employer", employer), + checkRequired("name", name), + checkRequired("type", type), + attributes, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Tax = apply { + if (validated) { + return@apply + } + + amount() + currency() + employer() + name() + type().ifPresent { it.validate() } + attributes().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 = + (if (amount.asKnown().isPresent) 1 else 0) + + (if (currency.asKnown().isPresent) 1 else 0) + + (if (employer.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) + + /** The type of taxes. */ + 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 STATE = of("state") + + @JvmField val FEDERAL = of("federal") + + @JvmField val LOCAL = of("local") + + @JvmField val FICA = of("fica") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + STATE, + FEDERAL, + LOCAL, + FICA, + } + + /** + * 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 { + STATE, + FEDERAL, + LOCAL, + FICA, + /** + * 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) { + STATE -> Value.STATE + FEDERAL -> Value.FEDERAL + LOCAL -> Value.LOCAL + FICA -> Value.FICA + 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) { + STATE -> Known.STATE + FEDERAL -> Known.FEDERAL + LOCAL -> Known.LOCAL + FICA -> Known.FICA + else -> throw FinchInvalidDataException("Unknown Type: $value") + } + + /** + * Returns this class instance's primitive wire representation. * - * 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. + * 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 type(type: JsonField) = apply { this.type = type } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - putAllAdditionalProperties(additionalProperties) - } + fun asString(): String = + _value().asString().orElseThrow { + FinchInvalidDataException("Value is not a String") + } - 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(): Type = 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 [Tax]. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * Further updates to this [Builder] will not mutate the returned instance. + * Used for best match union deserialization. */ - fun build(): Tax = - Tax( - amount, - attributes, - currency, - employer, - name, - type, - additionalProperties.toMutableMap(), - ) - } + @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(): Tax = apply { - if (validated) { - return@apply + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ } - amount() - attributes().ifPresent { it.validate() } - currency() - employer() - name() - type().ifPresent { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false - } + override fun hashCode() = value.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 (amount.asKnown().isPresent) 1 else 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + - (if (currency.asKnown().isPresent) 1 else 0) + - (if (employer.asKnown().isPresent) 1 else 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + override fun toString() = value.toString() + } class Attributes private constructor( @@ -4121,10 +4491,11 @@ private constructor( ) : this(metadata, 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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): Metadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -4150,14 +4521,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Attributes]. */ + /** + * Returns a mutable builder for constructing an instance of [Attributes]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -4203,9 +4581,19 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Attributes = - Attributes(metadata, additionalProperties.toMutableMap()) + Attributes( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -4215,7 +4603,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -4254,10 +4642,11 @@ private constructor( * key-value pairs where the values can be of any type (string, number, boolean, * object, array, etc.). * - * @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 metadata(): Optional = metadata.getOptional("metadata") + fun metadata(): InnerMetadata = metadata.getRequired("metadata") /** * Returns the raw JSON value of [metadata]. @@ -4283,14 +4672,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Metadata]. */ + /** + * Returns a mutable builder for constructing an instance of [Metadata]. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField = JsonMissing.of() + private var metadata: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -4344,9 +4740,19 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .metadata() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Metadata = - Metadata(metadata, additionalProperties.toMutableMap()) + Metadata( + checkRequired("metadata", metadata), + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -4356,7 +4762,7 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } + metadata().validate() validated = true } @@ -4532,165 +4938,22 @@ private constructor( "Attributes{metadata=$metadata, additionalProperties=$additionalProperties}" } - /** The type of taxes. */ - 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 STATE = of("state") - - @JvmField val FEDERAL = of("federal") - - @JvmField val LOCAL = of("local") - - @JvmField val FICA = of("fica") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - STATE, - FEDERAL, - LOCAL, - FICA, - } - - /** - * 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 { - STATE, - FEDERAL, - LOCAL, - FICA, - /** - * 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) { - STATE -> Value.STATE - FEDERAL -> Value.FEDERAL - LOCAL -> Value.LOCAL - FICA -> Value.FICA - 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) { - STATE -> Known.STATE - FEDERAL -> Known.FEDERAL - LOCAL -> Known.LOCAL - FICA -> Known.FICA - 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 Tax && amount == other.amount && attributes == other.attributes && currency == other.currency && employer == other.employer && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Tax && amount == other.amount && currency == other.currency && employer == other.employer && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, employer, name, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, currency, employer, name, type, attributes, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Tax{amount=$amount, attributes=$attributes, currency=$currency, employer=$employer, name=$name, type=$type, additionalProperties=$additionalProperties}" + "Tax{amount=$amount, currency=$currency, employer=$employer, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" } /** The type of the payment associated with the pay statement. */ 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 7f4ae9bc..17bf547a 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 @@ -27,7 +27,7 @@ internal class CompanyBenefitTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._401K) + .type(BenefitType._457) .build() assertThat(companyBenefit.benefitId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -45,7 +45,7 @@ internal class CompanyBenefitTest { ) assertThat(companyBenefit.description()).contains("description") assertThat(companyBenefit.frequency()).contains(BenefitFrequency.ONE_TIME) - assertThat(companyBenefit.type()).contains(BenefitType._401K) + assertThat(companyBenefit.type()).contains(BenefitType._457) } @Test @@ -67,7 +67,7 @@ internal class CompanyBenefitTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._401K) + .type(BenefitType._457) .build() val roundtrippedCompanyBenefit = 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 d16fa73a..65de7bff 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 @@ -23,7 +23,7 @@ internal class HrisBenefitCreateParamsTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._401K) + .type(BenefitType._457) .build() } @@ -44,7 +44,7 @@ internal class HrisBenefitCreateParamsTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._401K) + .type(BenefitType._457) .build() val body = params._body() @@ -63,7 +63,7 @@ internal class HrisBenefitCreateParamsTest { ) assertThat(body.description()).contains("description") assertThat(body.frequency()).contains(BenefitFrequency.ONE_TIME) - assertThat(body.type()).contains(BenefitType._401K) + assertThat(body.type()).contains(BenefitType._457) } @Test diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageResponseTest.kt index 73041054..aca870bd 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageResponseTest.kt @@ -18,12 +18,12 @@ internal class HrisCompanyPayStatementItemListPageResponseTest { PayStatementItemListResponse.builder() .attributes( PayStatementItemListResponse.Attributes.builder() - .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + .employer(true) .preTax(true) .type("type") .build() @@ -39,12 +39,12 @@ internal class HrisCompanyPayStatementItemListPageResponseTest { PayStatementItemListResponse.builder() .attributes( PayStatementItemListResponse.Attributes.builder() - .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + .employer(true) .preTax(true) .type("type") .build() @@ -64,12 +64,12 @@ internal class HrisCompanyPayStatementItemListPageResponseTest { PayStatementItemListResponse.builder() .attributes( PayStatementItemListResponse.Attributes.builder() - .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + .employer(true) .preTax(true) .type("type") .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 21ccd032..a3dc09f4 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,12 +18,21 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging(Paging.builder().offset(0L).count(0L).build()) + .paging( + PayStatementResponseBody.Paging.builder() + .offset(0L) + .count(0L) + .build() + ) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -46,15 +55,15 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes .builder() @@ -81,15 +90,14 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes .builder() @@ -117,9 +125,6 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay( @@ -133,6 +138,10 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -155,10 +164,6 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -178,12 +183,21 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging(Paging.builder().offset(0L).count(0L).build()) + .paging( + PayStatementResponseBody.Paging.builder() + .offset(0L) + .count(0L) + .build() + ) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -206,15 +220,15 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -239,15 +253,14 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes .builder() @@ -273,9 +286,6 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay( @@ -287,6 +297,10 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -308,10 +322,6 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -335,12 +345,21 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging(Paging.builder().offset(0L).count(0L).build()) + .paging( + PayStatementResponseBody.Paging.builder() + .offset(0L) + .count(0L) + .build() + ) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -363,15 +382,15 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes .builder() @@ -398,15 +417,14 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes .builder() @@ -434,9 +452,6 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay( @@ -450,6 +465,10 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -472,10 +491,6 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/MoneyTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/MoneyTest.kt index 76045e09..a9e57056 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/MoneyTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/MoneyTest.kt @@ -14,7 +14,7 @@ internal class MoneyTest { val money = Money.builder().amount(0L).currency("currency").build() assertThat(money.amount()).contains(0L) - assertThat(money.currency()).contains("currency") + assertThat(money.currency()).isEqualTo("currency") } @Test diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayGroupListResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayGroupListResponseTest.kt index e696a7ea..a0cd4fb7 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayGroupListResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayGroupListResponseTest.kt @@ -4,7 +4,6 @@ package com.tryfinch.api.models import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.tryfinch.api.core.jsonMapper -import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -19,9 +18,9 @@ internal class PayGroupListResponseTest { .addPayFrequency(PayGroupListResponse.PayFrequency.ANNUALLY) .build() - assertThat(payGroupListResponse.id()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - assertThat(payGroupListResponse.name()).contains("name") - assertThat(payGroupListResponse.payFrequencies().getOrNull()) + assertThat(payGroupListResponse.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + assertThat(payGroupListResponse.name()).isEqualTo("name") + assertThat(payGroupListResponse.payFrequencies()) .containsExactly(PayGroupListResponse.PayFrequency.ANNUALLY) } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementItemListResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementItemListResponseTest.kt index 56558e40..332a3257 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementItemListResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementItemListResponseTest.kt @@ -16,12 +16,12 @@ internal class PayStatementItemListResponseTest { PayStatementItemListResponse.builder() .attributes( PayStatementItemListResponse.Attributes.builder() - .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + .employer(true) .preTax(true) .type("type") .build() @@ -31,21 +31,21 @@ internal class PayStatementItemListResponseTest { .build() assertThat(payStatementItemListResponse.attributes()) - .contains( + .isEqualTo( PayStatementItemListResponse.Attributes.builder() - .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + .employer(true) .preTax(true) .type("type") .build() ) assertThat(payStatementItemListResponse.category()) - .contains(PayStatementItemListResponse.Category.EARNINGS) - assertThat(payStatementItemListResponse.name()).contains("name") + .isEqualTo(PayStatementItemListResponse.Category.EARNINGS) + assertThat(payStatementItemListResponse.name()).isEqualTo("name") } @Test @@ -55,12 +55,12 @@ internal class PayStatementItemListResponseTest { PayStatementItemListResponse.builder() .attributes( PayStatementItemListResponse.Attributes.builder() - .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) + .employer(true) .preTax(true) .type("type") .build() 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 40b61151..0968a185 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 @@ -5,7 +5,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 kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -15,12 +14,16 @@ internal class PayStatementResponseBodyTest { fun create() { val payStatementResponseBody = PayStatementResponseBody.builder() - .paging(Paging.builder().offset(0L).count(0L).build()) + .paging(PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -39,15 +42,15 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -68,15 +71,14 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -97,9 +99,6 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -109,6 +108,10 @@ internal class PayStatementResponseBodyTest { .addTax( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -127,10 +130,6 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -140,13 +139,17 @@ internal class PayStatementResponseBodyTest { .build() assertThat(payStatementResponseBody.paging()) - .contains(Paging.builder().offset(0L).count(0L).build()) - assertThat(payStatementResponseBody.payStatements().getOrNull()) + .isEqualTo(PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build()) + assertThat(payStatementResponseBody.payStatements()) .containsExactly( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -165,15 +168,15 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -192,15 +195,14 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -221,9 +223,6 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -233,6 +232,10 @@ internal class PayStatementResponseBodyTest { .addTax( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -250,10 +253,6 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -267,12 +266,16 @@ internal class PayStatementResponseBodyTest { val jsonMapper = jsonMapper() val payStatementResponseBody = PayStatementResponseBody.builder() - .paging(Paging.builder().offset(0L).count(0L).build()) + .paging(PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -291,15 +294,15 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -320,15 +323,14 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -349,9 +351,6 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -361,6 +360,10 @@ internal class PayStatementResponseBodyTest { .addTax( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -379,10 +382,6 @@ internal class PayStatementResponseBodyTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) 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 b436711a..2ecf667c 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,12 +16,18 @@ internal class PayStatementResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging(Paging.builder().offset(0L).count(0L).build()) + .paging( + PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build() + ) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -43,15 +49,15 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -76,15 +82,14 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -109,9 +114,6 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -121,6 +123,10 @@ internal class PayStatementResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -141,10 +147,6 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -158,14 +160,18 @@ internal class PayStatementResponseTest { .build() assertThat(payStatementResponse.body()) - .contains( + .isEqualTo( PayStatementResponseBody.builder() - .paging(Paging.builder().offset(0L).count(0L).build()) + .paging(PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -184,15 +190,15 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -213,15 +219,14 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -243,9 +248,6 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -255,6 +257,10 @@ internal class PayStatementResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -273,10 +279,6 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -285,8 +287,8 @@ internal class PayStatementResponseTest { ) .build() ) - assertThat(payStatementResponse.code()).contains(0L) - assertThat(payStatementResponse.paymentId()).contains("payment_id") + assertThat(payStatementResponse.code()).isEqualTo(0L) + assertThat(payStatementResponse.paymentId()).isEqualTo("payment_id") } @Test @@ -296,12 +298,18 @@ internal class PayStatementResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging(Paging.builder().offset(0L).count(0L).build()) + .paging( + PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build() + ) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -323,15 +331,15 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -356,15 +364,14 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -389,9 +396,6 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -401,6 +405,10 @@ internal class PayStatementResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -421,10 +429,6 @@ internal class PayStatementResponseTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) 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 3724bb43..05b154a3 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 @@ -18,6 +18,10 @@ internal class PayStatementTest { .addEarning( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -35,15 +39,15 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -62,15 +66,14 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -89,9 +92,6 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -101,6 +101,10 @@ internal class PayStatementTest { .addTax( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -118,10 +122,6 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -132,6 +132,10 @@ internal class PayStatementTest { .containsExactly( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -149,16 +153,16 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) assertThat(payStatement.employeeDeductions().getOrNull()) .containsExactly( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -177,16 +181,15 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) assertThat(payStatement.employerContributions().getOrNull()) .containsExactly( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -205,14 +208,11 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) assertThat(payStatement.grossPay()) .contains(Money.builder().amount(0L).currency("currency").build()) - assertThat(payStatement.individualId()).contains("individual_id") + assertThat(payStatement.individualId()).isEqualTo("individual_id") assertThat(payStatement.netPay()) .contains(Money.builder().amount(0L).currency("currency").build()) assertThat(payStatement.paymentMethod()).contains(PayStatement.PaymentMethod.CHECK) @@ -220,6 +220,10 @@ internal class PayStatementTest { .containsExactly( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -236,10 +240,6 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) assertThat(payStatement.totalHours()).contains(0.0) @@ -254,6 +254,10 @@ internal class PayStatementTest { .addEarning( PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -271,15 +275,15 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -298,15 +302,14 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -325,9 +328,6 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -337,6 +337,10 @@ internal class PayStatementTest { .addTax( PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -354,10 +358,6 @@ internal class PayStatementTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PaymentTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PaymentTest.kt index fce8572b..c21eb02e 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PaymentTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PaymentTest.kt @@ -30,7 +30,7 @@ internal class PaymentTest { ) .build() - assertThat(payment.id()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + assertThat(payment.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(payment.companyDebit()) .contains(Money.builder().amount(0L).currency("currency").build()) assertThat(payment.debitDate()).contains("debit_date") 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 0f9cfcf9..779152df 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 @@ -18,6 +18,10 @@ internal class SandboxPaymentCreateParamsTest { .addEarning( SandboxPaymentCreateParams.PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .attributes( SandboxPaymentCreateParams.PayStatement.Earning.Attributes.builder() .metadata( @@ -40,15 +44,15 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.builder() - .amount(2000L) + .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.Attributes .builder() @@ -74,15 +78,14 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("usd") - .name("401k test") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( SandboxPaymentCreateParams.PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployerContribution .Attributes @@ -109,18 +112,19 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) - .individualId("b2338cfb-472f-4f72-9faa-e028c083144a") + .individualId("individual_id") .netPay(Money.builder().amount(0L).currency("currency").build()) .paymentMethod(SandboxPaymentCreateParams.PayStatement.PaymentMethod.CHECK) .addTax( SandboxPaymentCreateParams.PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .attributes( SandboxPaymentCreateParams.PayStatement.Tax.Attributes.builder() .metadata( @@ -143,10 +147,6 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -167,6 +167,10 @@ internal class SandboxPaymentCreateParamsTest { .addEarning( SandboxPaymentCreateParams.PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .attributes( SandboxPaymentCreateParams.PayStatement.Earning.Attributes .builder() @@ -191,15 +195,15 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.builder() - .amount(2000L) + .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction .Attributes @@ -227,15 +231,14 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("usd") - .name("401k test") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( SandboxPaymentCreateParams.PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployerContribution .Attributes @@ -263,18 +266,19 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) - .individualId("b2338cfb-472f-4f72-9faa-e028c083144a") + .individualId("individual_id") .netPay(Money.builder().amount(0L).currency("currency").build()) .paymentMethod(SandboxPaymentCreateParams.PayStatement.PaymentMethod.CHECK) .addTax( SandboxPaymentCreateParams.PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .attributes( SandboxPaymentCreateParams.PayStatement.Tax.Attributes.builder() .metadata( @@ -297,10 +301,6 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -319,6 +319,10 @@ internal class SandboxPaymentCreateParamsTest { .addEarning( SandboxPaymentCreateParams.PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .attributes( SandboxPaymentCreateParams.PayStatement.Earning.Attributes.builder() .metadata( @@ -341,15 +345,15 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.builder() - .amount(2000L) + .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.Attributes .builder() @@ -375,15 +379,14 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("usd") - .name("401k test") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( SandboxPaymentCreateParams.PayStatement.EmployerContribution.builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployerContribution .Attributes @@ -410,18 +413,19 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) - .individualId("b2338cfb-472f-4f72-9faa-e028c083144a") + .individualId("individual_id") .netPay(Money.builder().amount(0L).currency("currency").build()) .paymentMethod(SandboxPaymentCreateParams.PayStatement.PaymentMethod.CHECK) .addTax( SandboxPaymentCreateParams.PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .attributes( SandboxPaymentCreateParams.PayStatement.Tax.Attributes.builder() .metadata( @@ -444,10 +448,6 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) 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 9d4af287..99d7b0e9 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 @@ -42,7 +42,7 @@ internal class BenefitServiceAsyncTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._401K) + .type(BenefitType._457) .build() ) 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 fc235e7b..6405f81b 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 @@ -32,6 +32,12 @@ internal class PaymentServiceAsyncTest { .addEarning( SandboxPaymentCreateParams.PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type( + SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY + ) .attributes( SandboxPaymentCreateParams.PayStatement.Earning.Attributes .builder() @@ -57,17 +63,15 @@ internal class PaymentServiceAsyncTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type( - SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY - ) .build() ) .addEmployeeDeduction( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.builder() - .amount(2000L) + .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction .Attributes @@ -95,16 +99,15 @@ internal class PaymentServiceAsyncTest { ) .build() ) - .currency("usd") - .name("401k test") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( SandboxPaymentCreateParams.PayStatement.EmployerContribution .builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployerContribution .Attributes @@ -132,13 +135,10 @@ internal class PaymentServiceAsyncTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) - .individualId("b2338cfb-472f-4f72-9faa-e028c083144a") + .individualId("individual_id") .netPay(Money.builder().amount(0L).currency("currency").build()) .paymentMethod( SandboxPaymentCreateParams.PayStatement.PaymentMethod.CHECK @@ -146,6 +146,10 @@ internal class PaymentServiceAsyncTest { .addTax( SandboxPaymentCreateParams.PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .attributes( SandboxPaymentCreateParams.PayStatement.Tax.Attributes .builder() @@ -170,10 +174,6 @@ internal class PaymentServiceAsyncTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) 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 ff54482a..334986ff 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 @@ -42,7 +42,7 @@ internal class BenefitServiceTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._401K) + .type(BenefitType._457) .build() ) 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 1a8dba8b..8ac4538e 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 @@ -32,6 +32,12 @@ internal class PaymentServiceTest { .addEarning( SandboxPaymentCreateParams.PayStatement.Earning.builder() .amount(0L) + .currency("currency") + .hours(0.0) + .name("name") + .type( + SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY + ) .attributes( SandboxPaymentCreateParams.PayStatement.Earning.Attributes .builder() @@ -57,17 +63,15 @@ internal class PaymentServiceTest { ) .build() ) - .currency("currency") - .hours(0.0) - .name("name") - .type( - SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY - ) .build() ) .addEmployeeDeduction( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.builder() - .amount(2000L) + .amount(0L) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction .Attributes @@ -95,16 +99,15 @@ internal class PaymentServiceTest { ) .build() ) - .currency("usd") - .name("401k test") - .preTax(true) - .type(BenefitType._401K) .build() ) .addEmployerContribution( SandboxPaymentCreateParams.PayStatement.EmployerContribution .builder() .amount(0L) + .currency("currency") + .name("name") + .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployerContribution .Attributes @@ -132,13 +135,10 @@ internal class PaymentServiceTest { ) .build() ) - .currency("currency") - .name("name") - .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) - .individualId("b2338cfb-472f-4f72-9faa-e028c083144a") + .individualId("individual_id") .netPay(Money.builder().amount(0L).currency("currency").build()) .paymentMethod( SandboxPaymentCreateParams.PayStatement.PaymentMethod.CHECK @@ -146,6 +146,10 @@ internal class PaymentServiceTest { .addTax( SandboxPaymentCreateParams.PayStatement.Tax.builder() .amount(0L) + .currency("currency") + .employer(true) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .attributes( SandboxPaymentCreateParams.PayStatement.Tax.Attributes .builder() @@ -170,10 +174,6 @@ internal class PaymentServiceTest { ) .build() ) - .currency("currency") - .employer(true) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) From 79328615d98546e904f7cf99c222f7645ecd9131 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 15 May 2025 21:42:53 +0000 Subject: [PATCH 4/6] feat(api): api update --- .stats.yml | 4 ++-- .../src/main/kotlin/com/tryfinch/api/models/PayStatement.kt | 6 ++++++ .../com/tryfinch/api/models/SandboxPaymentCreateParams.kt | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index bbc9fc49..d2522c7a 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-331df2398447990a86899b05ac569534b6a7e4ff1d73a319d57f67b34a201fb7.yml -openapi_spec_hash: 6e57516524c0519e90213c0554b26ab4 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-2450f9bcc309174bb09e7cc75c3d873240626676782a6d0aa7578395adfa80a8.yml +openapi_spec_hash: ce0eebc26042d65a7831455ca7e9c5a8 config_hash: 53778a0b839c4f6ad34fbba051f5e8a6 diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt index 9046f7a8..dabd98f7 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt @@ -3288,6 +3288,8 @@ private constructor( @JvmField val DIRECT_DEPOSIT = of("direct_deposit") + @JvmField val OTHER = of("other") + @JvmStatic fun of(value: String) = PaymentMethod(JsonField.of(value)) } @@ -3295,6 +3297,7 @@ private constructor( enum class Known { CHECK, DIRECT_DEPOSIT, + OTHER, } /** @@ -3309,6 +3312,7 @@ private constructor( enum class Value { CHECK, DIRECT_DEPOSIT, + OTHER, /** * An enum member indicating that [PaymentMethod] was instantiated with an unknown * value. @@ -3327,6 +3331,7 @@ private constructor( when (this) { CHECK -> Value.CHECK DIRECT_DEPOSIT -> Value.DIRECT_DEPOSIT + OTHER -> Value.OTHER else -> Value._UNKNOWN } @@ -3342,6 +3347,7 @@ private constructor( when (this) { CHECK -> Known.CHECK DIRECT_DEPOSIT -> Known.DIRECT_DEPOSIT + OTHER -> Known.OTHER else -> throw FinchInvalidDataException("Unknown PaymentMethod: $value") } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt index f43df6a5..578be7a5 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt @@ -3855,6 +3855,8 @@ private constructor( @JvmField val DIRECT_DEPOSIT = of("direct_deposit") + @JvmField val OTHER = of("other") + @JvmStatic fun of(value: String) = PaymentMethod(JsonField.of(value)) } @@ -3862,6 +3864,7 @@ private constructor( enum class Known { CHECK, DIRECT_DEPOSIT, + OTHER, } /** @@ -3876,6 +3879,7 @@ private constructor( enum class Value { CHECK, DIRECT_DEPOSIT, + OTHER, /** * An enum member indicating that [PaymentMethod] was instantiated with an unknown * value. @@ -3894,6 +3898,7 @@ private constructor( when (this) { CHECK -> Value.CHECK DIRECT_DEPOSIT -> Value.DIRECT_DEPOSIT + OTHER -> Value.OTHER else -> Value._UNKNOWN } @@ -3910,6 +3915,7 @@ private constructor( when (this) { CHECK -> Known.CHECK DIRECT_DEPOSIT -> Known.DIRECT_DEPOSIT + OTHER -> Known.OTHER else -> throw FinchInvalidDataException("Unknown PaymentMethod: $value") } From f226da9c89911bb4f3f39f3657c2f725d0773e7a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 16 May 2025 04:52:22 +0000 Subject: [PATCH 5/6] feat(api): api update --- .stats.yml | 4 +- .../com/tryfinch/api/models/BenefitType.kt | 108 +- .../kotlin/com/tryfinch/api/models/Money.kt | 36 +- .../api/models/PayGroupListResponse.kt | 107 +- .../api/models/PayGroupRetrieveResponse.kt | 54 +- .../com/tryfinch/api/models/PayStatement.kt | 1879 +++++++--------- .../models/PayStatementItemListResponse.kt | 159 +- .../api/models/PayStatementResponse.kt | 55 +- .../api/models/PayStatementResponseBody.kt | 233 +- .../kotlin/com/tryfinch/api/models/Payment.kt | 169 +- .../api/models/SandboxPaymentCreateParams.kt | 1889 +++++++---------- .../tryfinch/api/models/CompanyBenefitTest.kt | 6 +- .../api/models/HrisBenefitCreateParamsTest.kt | 6 +- ...anyPayStatementItemListPageResponseTest.kt | 6 +- ...ayStatementRetrieveManyPageResponseTest.kt | 111 +- .../com/tryfinch/api/models/MoneyTest.kt | 2 +- .../api/models/PayGroupListResponseTest.kt | 7 +- .../PayStatementItemListResponseTest.kt | 12 +- .../models/PayStatementResponseBodyTest.kt | 99 +- .../api/models/PayStatementResponseTest.kt | 106 +- .../tryfinch/api/models/PayStatementTest.kt | 92 +- .../com/tryfinch/api/models/PaymentTest.kt | 2 +- .../models/SandboxPaymentCreateParamsTest.kt | 102 +- .../async/hris/BenefitServiceAsyncTest.kt | 2 +- .../async/sandbox/PaymentServiceAsyncTest.kt | 38 +- .../blocking/hris/BenefitServiceTest.kt | 2 +- .../blocking/sandbox/PaymentServiceTest.kt | 38 +- 27 files changed, 2206 insertions(+), 3118 deletions(-) diff --git a/.stats.yml b/.stats.yml index d2522c7a..9cbd6b8d 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-2450f9bcc309174bb09e7cc75c3d873240626676782a6d0aa7578395adfa80a8.yml -openapi_spec_hash: ce0eebc26042d65a7831455ca7e9c5a8 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-5b00a0bc705b1d5bfcb5ea79c7af544766d51ec12ccc4721825664ab397789d8.yml +openapi_spec_hash: 34891659cff31395ba7683a8153b1db5 config_hash: 53778a0b839c4f6ad34fbba051f5e8a6 diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/BenefitType.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/BenefitType.kt index b8526345..27b2ed15 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/BenefitType.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/BenefitType.kt @@ -21,8 +21,6 @@ class BenefitType @JsonCreator private constructor(private val value: JsonField< companion object { - @JvmField val _457 = of("457") - @JvmField val _401K = of("401k") @JvmField val _401K_ROTH = of("401k_roth") @@ -33,56 +31,58 @@ class BenefitType @JsonCreator private constructor(private val value: JsonField< @JvmField val _403B_ROTH = of("403b_roth") - @JvmField val _457_ROTH = of("457_roth") + @JvmField val _457 = of("457") - @JvmField val COMMUTER = of("commuter") + @JvmField val _457_ROTH = of("457_roth") - @JvmField val CUSTOM_POST_TAX = of("custom_post_tax") + @JvmField val S125_MEDICAL = of("s125_medical") - @JvmField val CUSTOM_PRE_TAX = of("custom_pre_tax") + @JvmField val S125_DENTAL = of("s125_dental") - @JvmField val FSA_DEPENDENT_CARE = of("fsa_dependent_care") + @JvmField val S125_VISION = of("s125_vision") - @JvmField val FSA_MEDICAL = of("fsa_medical") + @JvmField val HSA_PRE = of("hsa_pre") @JvmField val HSA_POST = of("hsa_post") - @JvmField val HSA_PRE = of("hsa_pre") - - @JvmField val S125_DENTAL = of("s125_dental") + @JvmField val FSA_MEDICAL = of("fsa_medical") - @JvmField val S125_MEDICAL = of("s125_medical") + @JvmField val FSA_DEPENDENT_CARE = of("fsa_dependent_care") - @JvmField val S125_VISION = of("s125_vision") + @JvmField val SIMPLE_IRA = of("simple_ira") @JvmField val SIMPLE = of("simple") - @JvmField val SIMPLE_IRA = of("simple_ira") + @JvmField val COMMUTER = of("commuter") + + @JvmField val CUSTOM_POST_TAX = of("custom_post_tax") + + @JvmField val CUSTOM_PRE_TAX = of("custom_pre_tax") @JvmStatic fun of(value: String) = BenefitType(JsonField.of(value)) } /** An enum containing [BenefitType]'s known values. */ enum class Known { - _457, _401K, _401K_ROTH, _401K_LOAN, _403B, _403B_ROTH, + _457, _457_ROTH, - COMMUTER, - CUSTOM_POST_TAX, - CUSTOM_PRE_TAX, - FSA_DEPENDENT_CARE, - FSA_MEDICAL, - HSA_POST, - HSA_PRE, - S125_DENTAL, S125_MEDICAL, + S125_DENTAL, S125_VISION, - SIMPLE, + HSA_PRE, + HSA_POST, + FSA_MEDICAL, + FSA_DEPENDENT_CARE, SIMPLE_IRA, + SIMPLE, + COMMUTER, + CUSTOM_POST_TAX, + CUSTOM_PRE_TAX, } /** @@ -95,25 +95,25 @@ class BenefitType @JsonCreator private constructor(private val value: JsonField< * - It was constructed with an arbitrary value using the [of] method. */ enum class Value { - _457, _401K, _401K_ROTH, _401K_LOAN, _403B, _403B_ROTH, + _457, _457_ROTH, - COMMUTER, - CUSTOM_POST_TAX, - CUSTOM_PRE_TAX, - FSA_DEPENDENT_CARE, - FSA_MEDICAL, - HSA_POST, - HSA_PRE, - S125_DENTAL, S125_MEDICAL, + S125_DENTAL, S125_VISION, - SIMPLE, + HSA_PRE, + HSA_POST, + FSA_MEDICAL, + FSA_DEPENDENT_CARE, SIMPLE_IRA, + SIMPLE, + COMMUTER, + CUSTOM_POST_TAX, + CUSTOM_PRE_TAX, /** An enum member indicating that [BenefitType] was instantiated with an unknown value. */ _UNKNOWN, } @@ -127,25 +127,25 @@ class BenefitType @JsonCreator private constructor(private val value: JsonField< */ fun value(): Value = when (this) { - _457 -> Value._457 _401K -> Value._401K _401K_ROTH -> Value._401K_ROTH _401K_LOAN -> Value._401K_LOAN _403B -> Value._403B _403B_ROTH -> Value._403B_ROTH + _457 -> Value._457 _457_ROTH -> Value._457_ROTH - COMMUTER -> Value.COMMUTER - CUSTOM_POST_TAX -> Value.CUSTOM_POST_TAX - CUSTOM_PRE_TAX -> Value.CUSTOM_PRE_TAX - FSA_DEPENDENT_CARE -> Value.FSA_DEPENDENT_CARE - FSA_MEDICAL -> Value.FSA_MEDICAL - HSA_POST -> Value.HSA_POST - HSA_PRE -> Value.HSA_PRE - S125_DENTAL -> Value.S125_DENTAL S125_MEDICAL -> Value.S125_MEDICAL + S125_DENTAL -> Value.S125_DENTAL S125_VISION -> Value.S125_VISION - SIMPLE -> Value.SIMPLE + HSA_PRE -> Value.HSA_PRE + HSA_POST -> Value.HSA_POST + FSA_MEDICAL -> Value.FSA_MEDICAL + FSA_DEPENDENT_CARE -> Value.FSA_DEPENDENT_CARE SIMPLE_IRA -> Value.SIMPLE_IRA + SIMPLE -> Value.SIMPLE + COMMUTER -> Value.COMMUTER + CUSTOM_POST_TAX -> Value.CUSTOM_POST_TAX + CUSTOM_PRE_TAX -> Value.CUSTOM_PRE_TAX else -> Value._UNKNOWN } @@ -159,25 +159,25 @@ class BenefitType @JsonCreator private constructor(private val value: JsonField< */ fun known(): Known = when (this) { - _457 -> Known._457 _401K -> Known._401K _401K_ROTH -> Known._401K_ROTH _401K_LOAN -> Known._401K_LOAN _403B -> Known._403B _403B_ROTH -> Known._403B_ROTH + _457 -> Known._457 _457_ROTH -> Known._457_ROTH - COMMUTER -> Known.COMMUTER - CUSTOM_POST_TAX -> Known.CUSTOM_POST_TAX - CUSTOM_PRE_TAX -> Known.CUSTOM_PRE_TAX - FSA_DEPENDENT_CARE -> Known.FSA_DEPENDENT_CARE - FSA_MEDICAL -> Known.FSA_MEDICAL - HSA_POST -> Known.HSA_POST - HSA_PRE -> Known.HSA_PRE - S125_DENTAL -> Known.S125_DENTAL S125_MEDICAL -> Known.S125_MEDICAL + S125_DENTAL -> Known.S125_DENTAL S125_VISION -> Known.S125_VISION - SIMPLE -> Known.SIMPLE + HSA_PRE -> Known.HSA_PRE + HSA_POST -> Known.HSA_POST + FSA_MEDICAL -> Known.FSA_MEDICAL + FSA_DEPENDENT_CARE -> Known.FSA_DEPENDENT_CARE SIMPLE_IRA -> Known.SIMPLE_IRA + SIMPLE -> Known.SIMPLE + COMMUTER -> Known.COMMUTER + CUSTOM_POST_TAX -> Known.CUSTOM_POST_TAX + CUSTOM_PRE_TAX -> Known.CUSTOM_PRE_TAX else -> throw FinchInvalidDataException("Unknown BenefitType: $value") } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Money.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Money.kt index 137e061e..c9badec1 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Money.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Money.kt @@ -10,7 +10,6 @@ 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 @@ -39,10 +38,10 @@ private constructor( fun amount(): Optional = amount.getOptional("amount") /** - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun currency(): String = currency.getRequired("currency") + fun currency(): Optional = currency.getOptional("currency") /** * Returns the raw JSON value of [amount]. @@ -72,23 +71,15 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Money]. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Money]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Money]. */ class Builder internal constructor() { - private var amount: JsonField? = null - private var currency: JsonField? = null + private var amount: JsonField = JsonMissing.of() + private var currency: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -152,21 +143,8 @@ private constructor( * Returns an immutable instance of [Money]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): Money = - Money( - checkRequired("amount", amount), - checkRequired("currency", currency), - additionalProperties.toMutableMap(), - ) + fun build(): Money = Money(amount, currency, additionalProperties.toMutableMap()) } private var validated: Boolean = false diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupListResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupListResponse.kt index a5826485..608a9101 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupListResponse.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupListResponse.kt @@ -12,11 +12,11 @@ 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 +import java.util.Optional import kotlin.jvm.optionals.getOrNull class PayGroupListResponse @@ -39,26 +39,27 @@ private constructor( /** * Finch id (uuidv4) for the pay group * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun id(): String = id.getRequired("id") + fun id(): Optional = id.getOptional("id") /** * Name of the pay group * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun name(): String = name.getRequired("name") + fun name(): Optional = name.getOptional("name") /** * List of pay frequencies associated with this pay group * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun payFrequencies(): List = payFrequencies.getRequired("pay_frequencies") + fun payFrequencies(): Optional> = + payFrequencies.getOptional("pay_frequencies") /** * Returns the raw JSON value of [id]. @@ -97,24 +98,15 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [PayGroupListResponse]. - * - * The following fields are required: - * ```java - * .id() - * .name() - * .payFrequencies() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [PayGroupListResponse]. */ @JvmStatic fun builder() = Builder() } /** A builder for [PayGroupListResponse]. */ class Builder internal constructor() { - private var id: JsonField? = null - private var name: JsonField? = null + private var id: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() private var payFrequencies: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -198,21 +190,12 @@ private constructor( * Returns an immutable instance of [PayGroupListResponse]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .id() - * .name() - * .payFrequencies() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PayGroupListResponse = PayGroupListResponse( - checkRequired("id", id), - checkRequired("name", name), - checkRequired("payFrequencies", payFrequencies).map { it.toImmutable() }, + id, + name, + (payFrequencies ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toMutableMap(), ) } @@ -226,7 +209,7 @@ private constructor( id() name() - payFrequencies().forEach { it.validate() } + payFrequencies().ifPresent { it.forEach { it.validate() } } validated = true } @@ -266,21 +249,21 @@ private constructor( @JvmField val ANNUALLY = of("annually") - @JvmField val BI_WEEKLY = of("bi_weekly") + @JvmField val SEMI_ANNUALLY = of("semi_annually") - @JvmField val DAILY = of("daily") + @JvmField val QUARTERLY = of("quarterly") @JvmField val MONTHLY = of("monthly") - @JvmField val OTHER = of("other") + @JvmField val SEMI_MONTHLY = of("semi_monthly") - @JvmField val QUARTERLY = of("quarterly") + @JvmField val BI_WEEKLY = of("bi_weekly") - @JvmField val SEMI_ANNUALLY = of("semi_annually") + @JvmField val WEEKLY = of("weekly") - @JvmField val SEMI_MONTHLY = of("semi_monthly") + @JvmField val DAILY = of("daily") - @JvmField val WEEKLY = of("weekly") + @JvmField val OTHER = of("other") @JvmStatic fun of(value: String) = PayFrequency(JsonField.of(value)) } @@ -288,14 +271,14 @@ private constructor( /** An enum containing [PayFrequency]'s known values. */ enum class Known { ANNUALLY, - BI_WEEKLY, - DAILY, - MONTHLY, - OTHER, - QUARTERLY, SEMI_ANNUALLY, + QUARTERLY, + MONTHLY, SEMI_MONTHLY, + BI_WEEKLY, WEEKLY, + DAILY, + OTHER, } /** @@ -309,14 +292,14 @@ private constructor( */ enum class Value { ANNUALLY, - BI_WEEKLY, - DAILY, - MONTHLY, - OTHER, - QUARTERLY, SEMI_ANNUALLY, + QUARTERLY, + MONTHLY, SEMI_MONTHLY, + BI_WEEKLY, WEEKLY, + DAILY, + OTHER, /** * An enum member indicating that [PayFrequency] was instantiated with an unknown value. */ @@ -333,14 +316,14 @@ private constructor( fun value(): Value = when (this) { ANNUALLY -> Value.ANNUALLY - BI_WEEKLY -> Value.BI_WEEKLY - DAILY -> Value.DAILY - MONTHLY -> Value.MONTHLY - OTHER -> Value.OTHER - QUARTERLY -> Value.QUARTERLY SEMI_ANNUALLY -> Value.SEMI_ANNUALLY + QUARTERLY -> Value.QUARTERLY + MONTHLY -> Value.MONTHLY SEMI_MONTHLY -> Value.SEMI_MONTHLY + BI_WEEKLY -> Value.BI_WEEKLY WEEKLY -> Value.WEEKLY + DAILY -> Value.DAILY + OTHER -> Value.OTHER else -> Value._UNKNOWN } @@ -355,14 +338,14 @@ private constructor( fun known(): Known = when (this) { ANNUALLY -> Known.ANNUALLY - BI_WEEKLY -> Known.BI_WEEKLY - DAILY -> Known.DAILY - MONTHLY -> Known.MONTHLY - OTHER -> Known.OTHER - QUARTERLY -> Known.QUARTERLY SEMI_ANNUALLY -> Known.SEMI_ANNUALLY + QUARTERLY -> Known.QUARTERLY + MONTHLY -> Known.MONTHLY SEMI_MONTHLY -> Known.SEMI_MONTHLY + BI_WEEKLY -> Known.BI_WEEKLY WEEKLY -> Known.WEEKLY + DAILY -> Known.DAILY + OTHER -> Known.OTHER else -> throw FinchInvalidDataException("Unknown PayFrequency: $value") } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupRetrieveResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupRetrieveResponse.kt index 8e93a1cc..e6e2c27b 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupRetrieveResponse.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayGroupRetrieveResponse.kt @@ -317,21 +317,21 @@ private constructor( @JvmField val ANNUALLY = of("annually") - @JvmField val BI_WEEKLY = of("bi_weekly") + @JvmField val SEMI_ANNUALLY = of("semi_annually") - @JvmField val DAILY = of("daily") + @JvmField val QUARTERLY = of("quarterly") @JvmField val MONTHLY = of("monthly") - @JvmField val OTHER = of("other") + @JvmField val SEMI_MONTHLY = of("semi_monthly") - @JvmField val QUARTERLY = of("quarterly") + @JvmField val BI_WEEKLY = of("bi_weekly") - @JvmField val SEMI_ANNUALLY = of("semi_annually") + @JvmField val WEEKLY = of("weekly") - @JvmField val SEMI_MONTHLY = of("semi_monthly") + @JvmField val DAILY = of("daily") - @JvmField val WEEKLY = of("weekly") + @JvmField val OTHER = of("other") @JvmStatic fun of(value: String) = PayFrequency(JsonField.of(value)) } @@ -339,14 +339,14 @@ private constructor( /** An enum containing [PayFrequency]'s known values. */ enum class Known { ANNUALLY, - BI_WEEKLY, - DAILY, - MONTHLY, - OTHER, - QUARTERLY, SEMI_ANNUALLY, + QUARTERLY, + MONTHLY, SEMI_MONTHLY, + BI_WEEKLY, WEEKLY, + DAILY, + OTHER, } /** @@ -360,14 +360,14 @@ private constructor( */ enum class Value { ANNUALLY, - BI_WEEKLY, - DAILY, - MONTHLY, - OTHER, - QUARTERLY, SEMI_ANNUALLY, + QUARTERLY, + MONTHLY, SEMI_MONTHLY, + BI_WEEKLY, WEEKLY, + DAILY, + OTHER, /** * An enum member indicating that [PayFrequency] was instantiated with an unknown value. */ @@ -384,14 +384,14 @@ private constructor( fun value(): Value = when (this) { ANNUALLY -> Value.ANNUALLY - BI_WEEKLY -> Value.BI_WEEKLY - DAILY -> Value.DAILY - MONTHLY -> Value.MONTHLY - OTHER -> Value.OTHER - QUARTERLY -> Value.QUARTERLY SEMI_ANNUALLY -> Value.SEMI_ANNUALLY + QUARTERLY -> Value.QUARTERLY + MONTHLY -> Value.MONTHLY SEMI_MONTHLY -> Value.SEMI_MONTHLY + BI_WEEKLY -> Value.BI_WEEKLY WEEKLY -> Value.WEEKLY + DAILY -> Value.DAILY + OTHER -> Value.OTHER else -> Value._UNKNOWN } @@ -406,14 +406,14 @@ private constructor( fun known(): Known = when (this) { ANNUALLY -> Known.ANNUALLY - BI_WEEKLY -> Known.BI_WEEKLY - DAILY -> Known.DAILY - MONTHLY -> Known.MONTHLY - OTHER -> Known.OTHER - QUARTERLY -> Known.QUARTERLY SEMI_ANNUALLY -> Known.SEMI_ANNUALLY + QUARTERLY -> Known.QUARTERLY + MONTHLY -> Known.MONTHLY SEMI_MONTHLY -> Known.SEMI_MONTHLY + BI_WEEKLY -> Known.BI_WEEKLY WEEKLY -> Known.WEEKLY + DAILY -> Known.DAILY + OTHER -> Known.OTHER else -> throw FinchInvalidDataException("Unknown PayFrequency: $value") } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt index dabd98f7..805ed50b 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatement.kt @@ -12,7 +12,6 @@ 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 @@ -106,10 +105,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 or is unexpectedly - * missing or null (e.g. if the server responded with an unexpected value). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun individualId(): String = individualId.getRequired("individual_id") + fun individualId(): Optional = individualId.getOptional("individual_id") /** * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -243,23 +242,7 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [PayStatement]. - * - * The following fields are required: - * ```java - * .earnings() - * .employeeDeductions() - * .employerContributions() - * .grossPay() - * .individualId() - * .netPay() - * .paymentMethod() - * .taxes() - * .totalHours() - * .type() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [PayStatement]. */ @JvmStatic fun builder() = Builder() } @@ -269,13 +252,13 @@ private constructor( private var earnings: JsonField>? = null private var employeeDeductions: JsonField>? = null private var employerContributions: JsonField>? = null - private var grossPay: JsonField? = null - private var individualId: JsonField? = null - private var netPay: JsonField? = null - private var paymentMethod: JsonField? = null + private var grossPay: JsonField = JsonMissing.of() + private var individualId: JsonField = JsonMissing.of() + private var netPay: JsonField = JsonMissing.of() + private var paymentMethod: JsonField = JsonMissing.of() private var taxes: JsonField>? = null - private var totalHours: JsonField? = null - private var type: JsonField? = null + private var totalHours: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -534,37 +517,19 @@ private constructor( * Returns an immutable instance of [PayStatement]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .earnings() - * .employeeDeductions() - * .employerContributions() - * .grossPay() - * .individualId() - * .netPay() - * .paymentMethod() - * .taxes() - * .totalHours() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PayStatement = PayStatement( - checkRequired("earnings", earnings).map { it.toImmutable() }, - checkRequired("employeeDeductions", employeeDeductions).map { it.toImmutable() }, - checkRequired("employerContributions", employerContributions).map { - it.toImmutable() - }, - checkRequired("grossPay", grossPay), - checkRequired("individualId", individualId), - checkRequired("netPay", netPay), - checkRequired("paymentMethod", paymentMethod), - checkRequired("taxes", taxes).map { it.toImmutable() }, - checkRequired("totalHours", totalHours), - checkRequired("type", type), + (earnings ?: JsonMissing.of()).map { it.toImmutable() }, + (employeeDeductions ?: JsonMissing.of()).map { it.toImmutable() }, + (employerContributions ?: JsonMissing.of()).map { it.toImmutable() }, + grossPay, + individualId, + netPay, + paymentMethod, + (taxes ?: JsonMissing.of()).map { it.toImmutable() }, + totalHours, + type, additionalProperties.toMutableMap(), ) } @@ -620,27 +585,27 @@ private constructor( class Earning private constructor( private val amount: JsonField, + private val attributes: JsonField, private val currency: JsonField, private val hours: JsonField, private val name: JsonField, private val type: JsonField, - private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("hours") @ExcludeMissing hours: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), - ) : this(amount, currency, hours, name, type, attributes, mutableMapOf()) + ) : this(amount, attributes, currency, hours, name, type, mutableMapOf()) /** * The earnings amount in cents. @@ -650,6 +615,12 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun attributes(): Optional = attributes.getOptional("attributes") + /** * The earnings currency code. * @@ -683,12 +654,6 @@ private constructor( */ fun type(): Optional = type.getOptional("type") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * Returns the raw JSON value of [amount]. * @@ -696,6 +661,15 @@ private constructor( */ @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + /** * Returns the raw JSON value of [currency]. * @@ -724,15 +698,6 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - /** - * Returns the raw JSON value of [attributes]. - * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -747,40 +712,29 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Earning]. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .hours() - * .name() - * .type() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Earning]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Earning]. */ class Builder internal constructor() { - private var amount: JsonField? = null - private var currency: JsonField? = null - private var hours: JsonField? = null - private var name: JsonField? = null - private var type: JsonField? = null + private var amount: JsonField = JsonMissing.of() private var attributes: JsonField = JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var hours: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(earning: Earning) = apply { amount = earning.amount + attributes = earning.attributes currency = earning.currency hours = earning.hours name = earning.name type = earning.type - attributes = earning.attributes additionalProperties = earning.additionalProperties.toMutableMap() } @@ -806,6 +760,22 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } + fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + /** The earnings currency code. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -876,22 +846,6 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } - fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -915,26 +869,15 @@ private constructor( * Returns an immutable instance of [Earning]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .hours() - * .name() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): Earning = Earning( - checkRequired("amount", amount), - checkRequired("currency", currency), - checkRequired("hours", hours), - checkRequired("name", name), - checkRequired("type", type), + amount, attributes, + currency, + hours, + name, + type, additionalProperties.toMutableMap(), ) } @@ -947,11 +890,11 @@ private constructor( } amount() + attributes().ifPresent { it.validate() } currency() hours() name() type().ifPresent { it.validate() } - attributes().ifPresent { it.validate() } validated = true } @@ -972,349 +915,136 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (hours.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) - /** The type of earning. */ - class Type @JsonCreator private constructor(private val value: JsonField) : Enum { + class Attributes + private constructor( + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of() + ) : this(metadata, mutableMapOf()) /** - * Returns this class instance's raw value. + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Returns the raw JSON value of [metadata]. * - * 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. + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - companion object { + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - @JvmField val SALARY = of("salary") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - @JvmField val WAGE = of("wage") + fun toBuilder() = Builder().from(this) - @JvmField val REIMBURSEMENT = of("reimbursement") + companion object { - @JvmField val OVERTIME = of("overtime") + /** Returns a mutable builder for constructing an instance of [Attributes]. */ + @JvmStatic fun builder() = Builder() + } - @JvmField val SEVERANCE = of("severance") + /** A builder for [Attributes]. */ + class Builder internal constructor() { - @JvmField val DOUBLE_OVERTIME = of("double_overtime") + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - @JvmField val PTO = of("pto") + @JvmSynthetic + internal fun from(attributes: Attributes) = apply { + metadata = attributes.metadata + additionalProperties = attributes.additionalProperties.toMutableMap() + } - @JvmField val SICK = of("sick") + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) - @JvmField val BONUS = of("bonus") + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - @JvmField val COMMISSION = of("commission") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - @JvmField val TIPS = of("tips") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - @JvmField val _1099 = of("1099") + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - @JvmField val OTHER = of("other") + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** An enum containing [Type]'s known values. */ - enum class Known { - SALARY, - WAGE, - REIMBURSEMENT, - OVERTIME, - SEVERANCE, - DOUBLE_OVERTIME, - PTO, - SICK, - BONUS, - COMMISSION, - TIPS, - _1099, - OTHER, + /** + * Returns an immutable instance of [Attributes]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Attributes = Attributes(metadata, additionalProperties.toMutableMap()) } - /** - * 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 { - SALARY, - WAGE, - REIMBURSEMENT, - OVERTIME, - SEVERANCE, - DOUBLE_OVERTIME, - PTO, - SICK, - BONUS, - COMMISSION, - TIPS, - _1099, - OTHER, - /** An enum member indicating that [Type] was instantiated with an unknown value. */ - _UNKNOWN, + private var validated: Boolean = false + + fun validate(): Attributes = apply { + if (validated) { + return@apply + } + + metadata().ifPresent { it.validate() } + validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + false + } + /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * 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) { - SALARY -> Value.SALARY - WAGE -> Value.WAGE - REIMBURSEMENT -> Value.REIMBURSEMENT - OVERTIME -> Value.OVERTIME - SEVERANCE -> Value.SEVERANCE - DOUBLE_OVERTIME -> Value.DOUBLE_OVERTIME - PTO -> Value.PTO - SICK -> Value.SICK - BONUS -> Value.BONUS - COMMISSION -> Value.COMMISSION - TIPS -> Value.TIPS - _1099 -> Value._1099 - OTHER -> Value.OTHER - 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) { - SALARY -> Known.SALARY - WAGE -> Known.WAGE - REIMBURSEMENT -> Known.REIMBURSEMENT - OVERTIME -> Known.OVERTIME - SEVERANCE -> Known.SEVERANCE - DOUBLE_OVERTIME -> Known.DOUBLE_OVERTIME - PTO -> Known.PTO - SICK -> Known.SICK - BONUS -> Known.BONUS - COMMISSION -> Known.COMMISSION - TIPS -> Known.TIPS - _1099 -> Known._1099 - OTHER -> Known.OTHER - 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() - } - - class Attributes - private constructor( - private val metadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("metadata") - @ExcludeMissing - metadata: JsonField = JsonMissing.of() - ) : this(metadata, 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 metadata(): Metadata = metadata.getRequired("metadata") - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("metadata") - @ExcludeMissing - fun _metadata(): JsonField = metadata - - @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 [Attributes]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Attributes]. */ - class Builder internal constructor() { - - private var metadata: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(attributes: Attributes) = apply { - metadata = attributes.metadata - additionalProperties = attributes.additionalProperties.toMutableMap() - } - - fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - 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 [Attributes]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Attributes = - Attributes( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Attributes = apply { - if (validated) { - return@apply - } - - metadata().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. + * Used for best match union deserialization. */ @JvmSynthetic internal fun validity(): Int = (metadata.asKnown().getOrNull()?.validity() ?: 0) @@ -1337,11 +1067,10 @@ private constructor( * pairs where the values can be of any type (string, number, boolean, object, * array, etc.). * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). */ - fun metadata(): InnerMetadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -1367,21 +1096,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Metadata]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -1434,19 +1156,8 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = - Metadata( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + fun build(): Metadata = Metadata(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -1456,7 +1167,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -1594,40 +1305,234 @@ private constructor( "InnerMetadata{additionalProperties=$additionalProperties}" } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Metadata && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Metadata{metadata=$metadata, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Attributes && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Attributes{metadata=$metadata, additionalProperties=$additionalProperties}" + } + + /** The type of earning. */ + 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 SALARY = of("salary") + + @JvmField val WAGE = of("wage") + + @JvmField val REIMBURSEMENT = of("reimbursement") + + @JvmField val OVERTIME = of("overtime") + + @JvmField val SEVERANCE = of("severance") + + @JvmField val DOUBLE_OVERTIME = of("double_overtime") + + @JvmField val PTO = of("pto") + + @JvmField val SICK = of("sick") + + @JvmField val BONUS = of("bonus") + + @JvmField val COMMISSION = of("commission") + + @JvmField val TIPS = of("tips") + + @JvmField val _1099 = of("1099") + + @JvmField val OTHER = of("other") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SALARY, + WAGE, + REIMBURSEMENT, + OVERTIME, + SEVERANCE, + DOUBLE_OVERTIME, + PTO, + SICK, + BONUS, + COMMISSION, + TIPS, + _1099, + OTHER, + } + + /** + * 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 { + SALARY, + WAGE, + REIMBURSEMENT, + OVERTIME, + SEVERANCE, + DOUBLE_OVERTIME, + PTO, + SICK, + BONUS, + COMMISSION, + TIPS, + _1099, + OTHER, + /** 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) { + SALARY -> Value.SALARY + WAGE -> Value.WAGE + REIMBURSEMENT -> Value.REIMBURSEMENT + OVERTIME -> Value.OVERTIME + SEVERANCE -> Value.SEVERANCE + DOUBLE_OVERTIME -> Value.DOUBLE_OVERTIME + PTO -> Value.PTO + SICK -> Value.SICK + BONUS -> Value.BONUS + COMMISSION -> Value.COMMISSION + TIPS -> Value.TIPS + _1099 -> Value._1099 + OTHER -> Value.OTHER + 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) { + SALARY -> Known.SALARY + WAGE -> Known.WAGE + REIMBURSEMENT -> Known.REIMBURSEMENT + OVERTIME -> Known.OVERTIME + SEVERANCE -> Known.SEVERANCE + DOUBLE_OVERTIME -> Known.DOUBLE_OVERTIME + PTO -> Known.PTO + SICK -> Known.SICK + BONUS -> Known.BONUS + COMMISSION -> Known.COMMISSION + TIPS -> Known.TIPS + _1099 -> Known._1099 + OTHER -> Known.OTHER + else -> throw FinchInvalidDataException("Unknown Type: $value") + } - return /* spotless:off */ other is Metadata && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + /** + * 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") } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } - /* spotless:on */ + private var validated: Boolean = false - override fun hashCode(): Int = hashCode + fun validate(): Type = apply { + if (validated) { + return@apply + } - override fun toString() = - "Metadata{metadata=$metadata, additionalProperties=$additionalProperties}" + 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 Attributes && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ } - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode + override fun hashCode() = value.hashCode() - override fun toString() = - "Attributes{metadata=$metadata, additionalProperties=$additionalProperties}" + override fun toString() = value.toString() } override fun equals(other: Any?): Boolean { @@ -1635,43 +1540,43 @@ private constructor( return true } - return /* spotless:off */ other is Earning && amount == other.amount && currency == other.currency && hours == other.hours && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Earning && amount == other.amount && attributes == other.attributes && currency == other.currency && hours == other.hours && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, currency, hours, name, type, attributes, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, hours, name, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Earning{amount=$amount, currency=$currency, hours=$hours, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" + "Earning{amount=$amount, attributes=$attributes, currency=$currency, hours=$hours, name=$name, type=$type, additionalProperties=$additionalProperties}" } class EmployeeDeduction private constructor( private val amount: JsonField, + private val attributes: JsonField, private val currency: JsonField, private val name: JsonField, private val preTax: JsonField, private val type: JsonField, - private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("pre_tax") @ExcludeMissing preTax: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), - ) : this(amount, currency, name, preTax, type, attributes, mutableMapOf()) + ) : this(amount, attributes, currency, name, preTax, type, mutableMapOf()) /** * The deduction amount in cents. @@ -1681,6 +1586,12 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun attributes(): Optional = attributes.getOptional("attributes") + /** * The deduction currency. * @@ -1713,12 +1624,6 @@ private constructor( */ fun type(): Optional = type.getOptional("type") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * Returns the raw JSON value of [amount]. * @@ -1726,6 +1631,15 @@ private constructor( */ @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + /** * Returns the raw JSON value of [currency]. * @@ -1754,15 +1668,6 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - /** - * Returns the raw JSON value of [attributes]. - * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -1777,40 +1682,29 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [EmployeeDeduction]. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .name() - * .preTax() - * .type() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [EmployeeDeduction]. */ @JvmStatic fun builder() = Builder() } /** A builder for [EmployeeDeduction]. */ class Builder internal constructor() { - private var amount: JsonField? = null - private var currency: JsonField? = null - private var name: JsonField? = null - private var preTax: JsonField? = null - private var type: JsonField? = null + private var amount: JsonField = JsonMissing.of() private var attributes: JsonField = JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var preTax: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(employeeDeduction: EmployeeDeduction) = apply { amount = employeeDeduction.amount + attributes = employeeDeduction.attributes currency = employeeDeduction.currency name = employeeDeduction.name preTax = employeeDeduction.preTax type = employeeDeduction.type - attributes = employeeDeduction.attributes additionalProperties = employeeDeduction.additionalProperties.toMutableMap() } @@ -1836,6 +1730,22 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } + fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + /** The deduction currency. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -1903,22 +1813,6 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } - fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1942,26 +1836,15 @@ private constructor( * Returns an immutable instance of [EmployeeDeduction]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .name() - * .preTax() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): EmployeeDeduction = EmployeeDeduction( - checkRequired("amount", amount), - checkRequired("currency", currency), - checkRequired("name", name), - checkRequired("preTax", preTax), - checkRequired("type", type), + amount, attributes, + currency, + name, + preTax, + type, additionalProperties.toMutableMap(), ) } @@ -1974,11 +1857,11 @@ private constructor( } amount() + attributes().ifPresent { it.validate() } currency() name() preTax() type().ifPresent { it.validate() } - attributes().ifPresent { it.validate() } validated = true } @@ -1999,11 +1882,11 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + (if (preTax.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) class Attributes private constructor( @@ -2019,11 +1902,10 @@ private constructor( ) : this(metadata, 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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun metadata(): Metadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -2049,21 +1931,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Attributes]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Attributes]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -2109,19 +1984,8 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): Attributes = - Attributes( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + fun build(): Attributes = Attributes(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -2131,7 +1995,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -2170,11 +2034,10 @@ private constructor( * pairs where the values can be of any type (string, number, boolean, object, * array, etc.). * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). */ - fun metadata(): InnerMetadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -2200,21 +2063,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Metadata]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -2267,19 +2123,8 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = - Metadata( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + fun build(): Metadata = Metadata(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -2289,7 +2134,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -2468,41 +2313,41 @@ private constructor( return true } - return /* spotless:off */ other is EmployeeDeduction && amount == other.amount && currency == other.currency && name == other.name && preTax == other.preTax && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is EmployeeDeduction && amount == other.amount && attributes == other.attributes && currency == other.currency && name == other.name && preTax == other.preTax && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, currency, name, preTax, type, attributes, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, name, preTax, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "EmployeeDeduction{amount=$amount, currency=$currency, name=$name, preTax=$preTax, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" + "EmployeeDeduction{amount=$amount, attributes=$attributes, currency=$currency, name=$name, preTax=$preTax, type=$type, additionalProperties=$additionalProperties}" } class EmployerContribution private constructor( private val amount: JsonField, + private val attributes: JsonField, private val currency: JsonField, private val name: JsonField, private val type: JsonField, - private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), - ) : this(amount, currency, name, type, attributes, mutableMapOf()) + ) : this(amount, attributes, currency, name, type, mutableMapOf()) /** * The contribution amount in cents. @@ -2512,6 +2357,12 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun attributes(): Optional = attributes.getOptional("attributes") + /** * The contribution currency. * @@ -2536,12 +2387,6 @@ private constructor( */ fun type(): Optional = type.getOptional("type") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * Returns the raw JSON value of [amount]. * @@ -2549,6 +2394,15 @@ private constructor( */ @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + /** * Returns the raw JSON value of [currency]. * @@ -2570,15 +2424,6 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - /** - * Returns the raw JSON value of [attributes]. - * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -2593,37 +2438,27 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [EmployerContribution]. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .name() - * .type() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [EmployerContribution]. */ @JvmStatic fun builder() = Builder() } /** A builder for [EmployerContribution]. */ class Builder internal constructor() { - private var amount: JsonField? = null - private var currency: JsonField? = null - private var name: JsonField? = null - private var type: JsonField? = null + private var amount: JsonField = JsonMissing.of() private var attributes: JsonField = JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(employerContribution: EmployerContribution) = apply { amount = employerContribution.amount + attributes = employerContribution.attributes currency = employerContribution.currency name = employerContribution.name type = employerContribution.type - attributes = employerContribution.attributes additionalProperties = employerContribution.additionalProperties.toMutableMap() } @@ -2649,6 +2484,22 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } + fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + /** The contribution currency. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -2694,22 +2545,6 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } - fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -2733,24 +2568,14 @@ private constructor( * Returns an immutable instance of [EmployerContribution]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .name() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): EmployerContribution = EmployerContribution( - checkRequired("amount", amount), - checkRequired("currency", currency), - checkRequired("name", name), - checkRequired("type", type), + amount, attributes, + currency, + name, + type, additionalProperties.toMutableMap(), ) } @@ -2763,10 +2588,10 @@ private constructor( } amount() + attributes().ifPresent { it.validate() } currency() name() type().ifPresent { it.validate() } - attributes().ifPresent { it.validate() } validated = true } @@ -2787,10 +2612,10 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) class Attributes private constructor( @@ -2806,11 +2631,10 @@ private constructor( ) : this(metadata, 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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun metadata(): Metadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -2836,21 +2660,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Attributes]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Attributes]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -2896,19 +2713,8 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): Attributes = - Attributes( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + fun build(): Attributes = Attributes(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -2918,7 +2724,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -2957,11 +2763,10 @@ private constructor( * pairs where the values can be of any type (string, number, boolean, object, * array, etc.). * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). */ - fun metadata(): InnerMetadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -2987,21 +2792,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Metadata]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -3054,19 +2852,8 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = - Metadata( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + fun build(): Metadata = Metadata(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -3076,7 +2863,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -3255,17 +3042,17 @@ private constructor( return true } - return /* spotless:off */ other is EmployerContribution && amount == other.amount && currency == other.currency && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is EmployerContribution && amount == other.amount && attributes == other.attributes && currency == other.currency && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, currency, name, type, attributes, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, name, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "EmployerContribution{amount=$amount, currency=$currency, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" + "EmployerContribution{amount=$amount, attributes=$attributes, currency=$currency, name=$name, type=$type, additionalProperties=$additionalProperties}" } /** The payment method. */ @@ -3406,17 +3193,20 @@ private constructor( class Tax private constructor( private val amount: JsonField, + private val attributes: JsonField, private val currency: JsonField, private val employer: JsonField, private val name: JsonField, private val type: JsonField, - private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @@ -3425,10 +3215,7 @@ private constructor( employer: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), - ) : this(amount, currency, employer, name, type, attributes, mutableMapOf()) + ) : this(amount, attributes, currency, employer, name, type, mutableMapOf()) /** * The tax amount in cents. @@ -3438,6 +3225,12 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun attributes(): Optional = attributes.getOptional("attributes") + /** * The currency code. * @@ -3470,12 +3263,6 @@ private constructor( */ fun type(): Optional = type.getOptional("type") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * Returns the raw JSON value of [amount]. * @@ -3483,6 +3270,15 @@ private constructor( */ @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + /** * Returns the raw JSON value of [currency]. * @@ -3511,15 +3307,6 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - /** - * Returns the raw JSON value of [attributes]. - * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -3534,40 +3321,29 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Tax]. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .employer() - * .name() - * .type() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Tax]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Tax]. */ class Builder internal constructor() { - private var amount: JsonField? = null - private var currency: JsonField? = null - private var employer: JsonField? = null - private var name: JsonField? = null - private var type: JsonField? = null + private var amount: JsonField = JsonMissing.of() private var attributes: JsonField = JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var employer: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tax: Tax) = apply { amount = tax.amount + attributes = tax.attributes currency = tax.currency employer = tax.employer name = tax.name type = tax.type - attributes = tax.attributes additionalProperties = tax.additionalProperties.toMutableMap() } @@ -3593,6 +3369,22 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } + fun attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + /** The currency code. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -3639,269 +3431,102 @@ private constructor( /** * 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 type of taxes. */ - 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 attributes(attributes: Attributes?) = attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - - 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 [Tax]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .employer() - * .name() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Tax = - Tax( - checkRequired("amount", amount), - checkRequired("currency", currency), - checkRequired("employer", employer), - checkRequired("name", name), - checkRequired("type", type), - attributes, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Tax = apply { - if (validated) { - return@apply - } - - amount() - currency() - employer() - name() - type().ifPresent { it.validate() } - attributes().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 = - (if (amount.asKnown().isPresent) 1 else 0) + - (if (currency.asKnown().isPresent) 1 else 0) + - (if (employer.asKnown().isPresent) 1 else 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) - - /** The type of taxes. */ - 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 STATE = of("state") - - @JvmField val FEDERAL = of("federal") - - @JvmField val LOCAL = of("local") - - @JvmField val FICA = of("fica") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - STATE, - FEDERAL, - LOCAL, - FICA, - } - - /** - * 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 { - STATE, - FEDERAL, - LOCAL, - FICA, - /** 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) { - STATE -> Value.STATE - FEDERAL -> Value.FEDERAL - LOCAL -> Value.LOCAL - FICA -> Value.FICA - 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) { - STATE -> Known.STATE - FEDERAL -> Known.FEDERAL - LOCAL -> Known.LOCAL - FICA -> Known.FICA - else -> throw FinchInvalidDataException("Unknown Type: $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 type of taxes. */ + fun type(type: Type?) = type(JsonField.ofNullable(type)) + + /** Alias for calling [Builder.type] with `type.orElse(null)`. */ + fun type(type: Optional) = type(type.getOrNull()) /** - * 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. + * Sets [Builder.type] to an arbitrary JSON value. * - * @throws FinchInvalidDataException if this class instance's value does not have the - * expected primitive type. + * 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 asString(): String = - _value().asString().orElseThrow { - FinchInvalidDataException("Value is not a String") - } + fun type(type: JsonField) = apply { this.type = type } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): Type = apply { - if (validated) { - return@apply - } + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - known() - validated = true + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false - } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } /** - * Returns a score indicating how many valid values are contained in this object - * recursively. + * Returns an immutable instance of [Tax]. * - * Used for best match union deserialization. + * Further updates to this [Builder] will not mutate the returned instance. */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + fun build(): Tax = + Tax( + amount, + attributes, + currency, + employer, + name, + type, + additionalProperties.toMutableMap(), + ) + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + private var validated: Boolean = false - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + fun validate(): Tax = apply { + if (validated) { + return@apply } - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() + amount() + attributes().ifPresent { it.validate() } + currency() + employer() + name() + 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 = + (if (amount.asKnown().isPresent) 1 else 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) + + (if (currency.asKnown().isPresent) 1 else 0) + + (if (employer.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Attributes private constructor( private val metadata: JsonField, @@ -3916,11 +3541,10 @@ private constructor( ) : this(metadata, 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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). */ - fun metadata(): Metadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -3946,21 +3570,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Attributes]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Attributes]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -4006,19 +3623,8 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): Attributes = - Attributes( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + fun build(): Attributes = Attributes(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -4028,7 +3634,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -4067,11 +3673,10 @@ private constructor( * pairs where the values can be of any type (string, number, boolean, object, * array, etc.). * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). */ - fun metadata(): InnerMetadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -4097,21 +3702,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Metadata]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -4164,19 +3762,8 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ - fun build(): Metadata = - Metadata( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + fun build(): Metadata = Metadata(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -4186,7 +3773,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -4360,22 +3947,162 @@ private constructor( "Attributes{metadata=$metadata, additionalProperties=$additionalProperties}" } + /** The type of taxes. */ + 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 STATE = of("state") + + @JvmField val FEDERAL = of("federal") + + @JvmField val LOCAL = of("local") + + @JvmField val FICA = of("fica") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + STATE, + FEDERAL, + LOCAL, + FICA, + } + + /** + * 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 { + STATE, + FEDERAL, + LOCAL, + FICA, + /** 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) { + STATE -> Value.STATE + FEDERAL -> Value.FEDERAL + LOCAL -> Value.LOCAL + FICA -> Value.FICA + 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) { + STATE -> Known.STATE + FEDERAL -> Known.FEDERAL + LOCAL -> Known.LOCAL + FICA -> Known.FICA + 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 Tax && amount == other.amount && currency == other.currency && employer == other.employer && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Tax && amount == other.amount && attributes == other.attributes && currency == other.currency && employer == other.employer && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, currency, employer, name, type, attributes, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, employer, name, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Tax{amount=$amount, currency=$currency, employer=$employer, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" + "Tax{amount=$amount, attributes=$attributes, currency=$currency, employer=$employer, name=$name, type=$type, additionalProperties=$additionalProperties}" } /** The type of the payment associated with the pay statement. */ diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementItemListResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementItemListResponse.kt index 172c2ddf..846be3c3 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementItemListResponse.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementItemListResponse.kt @@ -11,7 +11,6 @@ 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.core.toImmutable import com.tryfinch.api.errors.FinchInvalidDataException import java.util.Collections @@ -39,26 +38,26 @@ private constructor( /** * The attributes of the pay statement item. * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun attributes(): Attributes = attributes.getRequired("attributes") + fun attributes(): Optional = attributes.getOptional("attributes") /** * The category of the pay statement item. * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun category(): Category = category.getRequired("category") + fun category(): Optional = category.getOptional("category") /** * The name of the pay statement item. * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun name(): String = name.getRequired("name") + fun name(): Optional = name.getOptional("name") /** * Returns the raw JSON value of [attributes]. @@ -99,13 +98,6 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [PayStatementItemListResponse]. - * - * The following fields are required: - * ```java - * .attributes() - * .category() - * .name() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -113,9 +105,9 @@ private constructor( /** A builder for [PayStatementItemListResponse]. */ class Builder internal constructor() { - private var attributes: JsonField? = null - private var category: JsonField? = null - private var name: JsonField? = null + private var attributes: JsonField = JsonMissing.of() + private var category: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -184,21 +176,12 @@ private constructor( * Returns an immutable instance of [PayStatementItemListResponse]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .attributes() - * .category() - * .name() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PayStatementItemListResponse = PayStatementItemListResponse( - checkRequired("attributes", attributes), - checkRequired("category", category), - checkRequired("name", name), + attributes, + category, + name, additionalProperties.toMutableMap(), ) } @@ -210,8 +193,8 @@ private constructor( return@apply } - attributes().validate() - category().validate() + attributes().ifPresent { it.validate() } + category().ifPresent { it.validate() } name() validated = true } @@ -238,8 +221,8 @@ private constructor( /** The attributes of the pay statement item. */ class Attributes private constructor( - private val metadata: JsonField, private val employer: JsonField, + private val metadata: JsonField, private val preTax: JsonField, private val type: JsonField, private val additionalProperties: MutableMap, @@ -247,32 +230,32 @@ private constructor( @JsonCreator private constructor( - @JsonProperty("metadata") - @ExcludeMissing - metadata: JsonField = JsonMissing.of(), @JsonProperty("employer") @ExcludeMissing employer: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), @JsonProperty("pre_tax") @ExcludeMissing preTax: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(metadata, employer, preTax, type, mutableMapOf()) + ) : this(employer, metadata, preTax, type, mutableMapOf()) /** - * The metadata of the pay statement item derived by the rules engine if available. Each - * attribute will be a key-value pair defined by a rule. + * `true` if the amount is paid by the employers. This field is only available for taxes. * * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun metadata(): Optional = metadata.getOptional("metadata") + fun employer(): Optional = employer.getOptional("employer") /** - * `true` if the amount is paid by the employers. This field is only available for taxes. + * The metadata of the pay statement item derived by the rules engine if available. Each + * attribute will be a key-value pair defined by a rule. * * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun employer(): Optional = employer.getOptional("employer") + fun metadata(): Optional = metadata.getOptional("metadata") /** * `true` if the pay statement item is pre-tax. This field is only available for employee @@ -292,18 +275,18 @@ private constructor( fun type(): Optional = type.getOptional("type") /** - * Returns the raw JSON value of [metadata]. + * Returns the raw JSON value of [employer]. * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [employer], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + @JsonProperty("employer") @ExcludeMissing fun _employer(): JsonField = employer /** - * Returns the raw JSON value of [employer]. + * Returns the raw JSON value of [metadata]. * - * Unlike [employer], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("employer") @ExcludeMissing fun _employer(): JsonField = employer + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata /** * Returns the raw JSON value of [preTax]. @@ -333,53 +316,28 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Attributes]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Attributes]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField? = null private var employer: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() private var preTax: JsonField = JsonMissing.of() private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(attributes: Attributes) = apply { - metadata = attributes.metadata employer = attributes.employer + metadata = attributes.metadata preTax = attributes.preTax type = attributes.type additionalProperties = attributes.additionalProperties.toMutableMap() } - /** - * The metadata of the pay statement item derived by the rules engine if available. Each - * attribute will be a key-value pair defined by a rule. - */ - fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) - - /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ - fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - /** * `true` if the amount is paid by the employers. This field is only available for * taxes. @@ -405,6 +363,24 @@ private constructor( */ fun employer(employer: JsonField) = apply { this.employer = employer } + /** + * The metadata of the pay statement item derived by the rules engine if available. Each + * attribute will be a key-value pair defined by a rule. + */ + fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata)) + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** * `true` if the pay statement item is pre-tax. This field is only available for * employee deductions. @@ -468,22 +444,9 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): Attributes = - Attributes( - checkRequired("metadata", metadata), - employer, - preTax, - type, - additionalProperties.toMutableMap(), - ) + Attributes(employer, metadata, preTax, type, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -493,8 +456,8 @@ private constructor( return@apply } - metadata().ifPresent { it.validate() } employer() + metadata().ifPresent { it.validate() } preTax() type() validated = true @@ -516,8 +479,8 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (metadata.asKnown().getOrNull()?.validity() ?: 0) + - (if (employer.asKnown().isPresent) 1 else 0) + + (if (employer.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + (if (preTax.asKnown().isPresent) 1 else 0) + (if (type.asKnown().isPresent) 1 else 0) @@ -634,17 +597,17 @@ private constructor( return true } - return /* spotless:off */ other is Attributes && metadata == other.metadata && employer == other.employer && preTax == other.preTax && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Attributes && employer == other.employer && metadata == other.metadata && preTax == other.preTax && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(metadata, employer, preTax, type, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(employer, metadata, preTax, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Attributes{metadata=$metadata, employer=$employer, preTax=$preTax, type=$type, additionalProperties=$additionalProperties}" + "Attributes{employer=$employer, metadata=$metadata, preTax=$preTax, type=$type, additionalProperties=$additionalProperties}" } /** The category of the pay statement item. */ diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponse.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponse.kt index ed1418b5..3f5cf6c6 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponse.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponse.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 PayStatementResponse @@ -34,22 +34,22 @@ private constructor( ) : this(body, code, paymentId, 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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun body(): PayStatementResponseBody = body.getRequired("body") + fun body(): Optional = body.getOptional("body") /** - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun code(): Long = code.getRequired("code") + fun code(): Optional = code.getOptional("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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun paymentId(): String = paymentId.getRequired("payment_id") + fun paymentId(): Optional = paymentId.getOptional("payment_id") /** * Returns the raw JSON value of [body]. @@ -86,25 +86,16 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [PayStatementResponse]. - * - * The following fields are required: - * ```java - * .body() - * .code() - * .paymentId() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [PayStatementResponse]. */ @JvmStatic fun builder() = Builder() } /** A builder for [PayStatementResponse]. */ class Builder internal constructor() { - private var body: JsonField? = null - private var code: JsonField? = null - private var paymentId: JsonField? = null + private var body: JsonField = JsonMissing.of() + private var code: JsonField = JsonMissing.of() + private var paymentId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -170,23 +161,9 @@ private constructor( * Returns an immutable instance of [PayStatementResponse]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .body() - * .code() - * .paymentId() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PayStatementResponse = - PayStatementResponse( - checkRequired("body", body), - checkRequired("code", code), - checkRequired("paymentId", paymentId), - additionalProperties.toMutableMap(), - ) + PayStatementResponse(body, code, paymentId, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -196,7 +173,7 @@ private constructor( return@apply } - body().validate() + body().ifPresent { it.validate() } code() paymentId() validated = true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponseBody.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponseBody.kt index 712d6020..66722b9f 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponseBody.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementResponseBody.kt @@ -11,7 +11,6 @@ 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 @@ -35,16 +34,18 @@ private constructor( ) : this(paging, payStatements, 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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun paging(): Paging = paging.getRequired("paging") + fun paging(): Optional = paging.getOptional("paging") /** - * @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). + * The array of pay statements for the current payment. + * + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun payStatements(): List = payStatements.getRequired("pay_statements") + fun payStatements(): Optional> = payStatements.getOptional("pay_statements") /** * Returns the raw JSON value of [paging]. @@ -76,22 +77,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [PayStatementResponseBody]. - * - * The following fields are required: - * ```java - * .paging() - * .payStatements() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [PayStatementResponseBody]. */ @JvmStatic fun builder() = Builder() } /** A builder for [PayStatementResponseBody]. */ class Builder internal constructor() { - private var paging: JsonField? = null + private var paging: JsonField = JsonMissing.of() private var payStatements: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @@ -112,6 +105,7 @@ private constructor( */ fun paging(paging: JsonField) = apply { this.paging = paging } + /** The array of pay statements for the current payment. */ fun payStatements(payStatements: List) = payStatements(JsonField.of(payStatements)) @@ -161,19 +155,11 @@ private constructor( * Returns an immutable instance of [PayStatementResponseBody]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .paging() - * .payStatements() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PayStatementResponseBody = PayStatementResponseBody( - checkRequired("paging", paging), - checkRequired("payStatements", payStatements).map { it.toImmutable() }, + paging, + (payStatements ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toMutableMap(), ) } @@ -185,8 +171,8 @@ private constructor( return@apply } - paging().validate() - payStatements().forEach { it.validate() } + paging().ifPresent { it.validate() } + payStatements().ifPresent { it.forEach { it.validate() } } validated = true } @@ -208,195 +194,6 @@ private constructor( (paging.asKnown().getOrNull()?.validity() ?: 0) + (payStatements.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - class Paging - private constructor( - private val offset: JsonField, - private val count: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("offset") @ExcludeMissing offset: JsonField = JsonMissing.of(), - @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) - * - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun count(): Optional = count.getOptional("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 - - /** - * Returns the raw JSON value of [count]. - * - * Unlike [count], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("count") @ExcludeMissing fun _count(): JsonField = count - - @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 [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 additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(paging: Paging) = apply { - offset = paging.offset - count = paging.count - additionalProperties = paging.additionalProperties.toMutableMap() - } - - /** The current start index of the returned list of elements */ - fun offset(offset: Long) = offset(JsonField.of(offset)) - - /** - * Sets [Builder.offset] to an arbitrary JSON value. - * - * 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 offset(offset: JsonField) = apply { this.offset = 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.count] to an arbitrary JSON value. - * - * 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 count(count: JsonField) = apply { this.count = count } - - 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 [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(checkRequired("offset", offset), count, additionalProperties.toMutableMap()) - } - - private var validated: Boolean = false - - fun validate(): Paging = apply { - if (validated) { - return@apply - } - - offset() - count() - 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 (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 && offset == other.offset && count == other.count && additionalProperties == other.additionalProperties /* spotless:on */ - } - - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(offset, count, additionalProperties) } - /* spotless:on */ - - override fun hashCode(): Int = hashCode - - override fun toString() = - "Paging{offset=$offset, count=$count, additionalProperties=$additionalProperties}" - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Payment.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Payment.kt index c3dfdb32..27d85584 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Payment.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/Payment.kt @@ -12,7 +12,6 @@ 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 @@ -84,10 +83,10 @@ private constructor( /** * The unique id for the payment. * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun id(): String = id.getRequired("id") + fun id(): Optional = id.getOptional("id") /** * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -274,43 +273,25 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Payment]. - * - * The following fields are required: - * ```java - * .id() - * .companyDebit() - * .debitDate() - * .employeeTaxes() - * .employerTaxes() - * .grossPay() - * .individualIds() - * .netPay() - * .payDate() - * .payFrequencies() - * .payGroupIds() - * .payPeriod() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Payment]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Payment]. */ class Builder internal constructor() { - private var id: JsonField? = null - private var companyDebit: JsonField? = null - private var debitDate: JsonField? = null - private var employeeTaxes: JsonField? = null - private var employerTaxes: JsonField? = null - private var grossPay: JsonField? = null + private var id: JsonField = JsonMissing.of() + private var companyDebit: JsonField = JsonMissing.of() + private var debitDate: JsonField = JsonMissing.of() + private var employeeTaxes: JsonField = JsonMissing.of() + private var employerTaxes: JsonField = JsonMissing.of() + private var grossPay: JsonField = JsonMissing.of() private var individualIds: JsonField>? = null - private var netPay: JsonField? = null - private var payDate: JsonField? = null + private var netPay: JsonField = JsonMissing.of() + private var payDate: JsonField = JsonMissing.of() private var payFrequencies: JsonField>? = null private var payGroupIds: JsonField>? = null - private var payPeriod: JsonField? = null + private var payPeriod: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -573,39 +554,21 @@ private constructor( * Returns an immutable instance of [Payment]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .id() - * .companyDebit() - * .debitDate() - * .employeeTaxes() - * .employerTaxes() - * .grossPay() - * .individualIds() - * .netPay() - * .payDate() - * .payFrequencies() - * .payGroupIds() - * .payPeriod() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): Payment = Payment( - checkRequired("id", id), - checkRequired("companyDebit", companyDebit), - checkRequired("debitDate", debitDate), - checkRequired("employeeTaxes", employeeTaxes), - checkRequired("employerTaxes", employerTaxes), - checkRequired("grossPay", grossPay), - checkRequired("individualIds", individualIds).map { it.toImmutable() }, - checkRequired("netPay", netPay), - checkRequired("payDate", payDate), - checkRequired("payFrequencies", payFrequencies).map { it.toImmutable() }, - checkRequired("payGroupIds", payGroupIds).map { it.toImmutable() }, - checkRequired("payPeriod", payPeriod), + id, + companyDebit, + debitDate, + employeeTaxes, + employerTaxes, + grossPay, + (individualIds ?: JsonMissing.of()).map { it.toImmutable() }, + netPay, + payDate, + (payFrequencies ?: JsonMissing.of()).map { it.toImmutable() }, + (payGroupIds ?: JsonMissing.of()).map { it.toImmutable() }, + payPeriod, additionalProperties.toMutableMap(), ) } @@ -677,21 +640,21 @@ private constructor( @JvmField val ANNUALLY = of("annually") - @JvmField val BI_WEEKLY = of("bi_weekly") + @JvmField val SEMI_ANNUALLY = of("semi_annually") - @JvmField val DAILY = of("daily") + @JvmField val QUARTERLY = of("quarterly") @JvmField val MONTHLY = of("monthly") - @JvmField val OTHER = of("other") + @JvmField val SEMI_MONTHLY = of("semi_monthly") - @JvmField val QUARTERLY = of("quarterly") + @JvmField val BI_WEEKLY = of("bi_weekly") - @JvmField val SEMI_ANNUALLY = of("semi_annually") + @JvmField val WEEKLY = of("weekly") - @JvmField val SEMI_MONTHLY = of("semi_monthly") + @JvmField val DAILY = of("daily") - @JvmField val WEEKLY = of("weekly") + @JvmField val OTHER = of("other") @JvmStatic fun of(value: String) = PayFrequency(JsonField.of(value)) } @@ -699,14 +662,14 @@ private constructor( /** An enum containing [PayFrequency]'s known values. */ enum class Known { ANNUALLY, - BI_WEEKLY, - DAILY, - MONTHLY, - OTHER, - QUARTERLY, SEMI_ANNUALLY, + QUARTERLY, + MONTHLY, SEMI_MONTHLY, + BI_WEEKLY, WEEKLY, + DAILY, + OTHER, } /** @@ -720,14 +683,14 @@ private constructor( */ enum class Value { ANNUALLY, - BI_WEEKLY, - DAILY, - MONTHLY, - OTHER, - QUARTERLY, SEMI_ANNUALLY, + QUARTERLY, + MONTHLY, SEMI_MONTHLY, + BI_WEEKLY, WEEKLY, + DAILY, + OTHER, /** * An enum member indicating that [PayFrequency] was instantiated with an unknown value. */ @@ -744,14 +707,14 @@ private constructor( fun value(): Value = when (this) { ANNUALLY -> Value.ANNUALLY - BI_WEEKLY -> Value.BI_WEEKLY - DAILY -> Value.DAILY - MONTHLY -> Value.MONTHLY - OTHER -> Value.OTHER - QUARTERLY -> Value.QUARTERLY SEMI_ANNUALLY -> Value.SEMI_ANNUALLY + QUARTERLY -> Value.QUARTERLY + MONTHLY -> Value.MONTHLY SEMI_MONTHLY -> Value.SEMI_MONTHLY + BI_WEEKLY -> Value.BI_WEEKLY WEEKLY -> Value.WEEKLY + DAILY -> Value.DAILY + OTHER -> Value.OTHER else -> Value._UNKNOWN } @@ -766,14 +729,14 @@ private constructor( fun known(): Known = when (this) { ANNUALLY -> Known.ANNUALLY - BI_WEEKLY -> Known.BI_WEEKLY - DAILY -> Known.DAILY - MONTHLY -> Known.MONTHLY - OTHER -> Known.OTHER - QUARTERLY -> Known.QUARTERLY SEMI_ANNUALLY -> Known.SEMI_ANNUALLY + QUARTERLY -> Known.QUARTERLY + MONTHLY -> Known.MONTHLY SEMI_MONTHLY -> Known.SEMI_MONTHLY + BI_WEEKLY -> Known.BI_WEEKLY WEEKLY -> Known.WEEKLY + DAILY -> Known.DAILY + OTHER -> Known.OTHER else -> throw FinchInvalidDataException("Unknown PayFrequency: $value") } @@ -885,23 +848,15 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [PayPeriod]. - * - * The following fields are required: - * ```java - * .endDate() - * .startDate() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [PayPeriod]. */ @JvmStatic fun builder() = Builder() } /** A builder for [PayPeriod]. */ class Builder internal constructor() { - private var endDate: JsonField? = null - private var startDate: JsonField? = null + private var endDate: JsonField = JsonMissing.of() + private var startDate: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -962,21 +917,9 @@ private constructor( * Returns an immutable instance of [PayPeriod]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .endDate() - * .startDate() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PayPeriod = - PayPeriod( - checkRequired("endDate", endDate), - checkRequired("startDate", startDate), - additionalProperties.toMutableMap(), - ) + PayPeriod(endDate, startDate, additionalProperties.toMutableMap()) } private var validated: Boolean = false diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt index 578be7a5..82188e32 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/SandboxPaymentCreateParams.kt @@ -13,7 +13,6 @@ 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.checkRequired import com.tryfinch.api.core.http.Headers import com.tryfinch.api.core.http.QueryParams import com.tryfinch.api.core.toImmutable @@ -614,10 +613,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 or is - * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). */ - fun individualId(): String = individualId.getRequired("individual_id") + fun individualId(): Optional = individualId.getOptional("individual_id") /** * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the @@ -757,23 +756,7 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [PayStatement]. - * - * The following fields are required: - * ```java - * .earnings() - * .employeeDeductions() - * .employerContributions() - * .grossPay() - * .individualId() - * .netPay() - * .paymentMethod() - * .taxes() - * .totalHours() - * .type() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [PayStatement]. */ @JvmStatic fun builder() = Builder() } @@ -783,13 +766,13 @@ private constructor( private var earnings: JsonField>? = null private var employeeDeductions: JsonField>? = null private var employerContributions: JsonField>? = null - private var grossPay: JsonField? = null - private var individualId: JsonField? = null - private var netPay: JsonField? = null - private var paymentMethod: JsonField? = null + private var grossPay: JsonField = JsonMissing.of() + private var individualId: JsonField = JsonMissing.of() + private var netPay: JsonField = JsonMissing.of() + private var paymentMethod: JsonField = JsonMissing.of() private var taxes: JsonField>? = null - private var totalHours: JsonField? = null - private var type: JsonField? = null + private var totalHours: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -1058,39 +1041,19 @@ private constructor( * Returns an immutable instance of [PayStatement]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .earnings() - * .employeeDeductions() - * .employerContributions() - * .grossPay() - * .individualId() - * .netPay() - * .paymentMethod() - * .taxes() - * .totalHours() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): PayStatement = PayStatement( - checkRequired("earnings", earnings).map { it.toImmutable() }, - checkRequired("employeeDeductions", employeeDeductions).map { - it.toImmutable() - }, - checkRequired("employerContributions", employerContributions).map { - it.toImmutable() - }, - checkRequired("grossPay", grossPay), - checkRequired("individualId", individualId), - checkRequired("netPay", netPay), - checkRequired("paymentMethod", paymentMethod), - checkRequired("taxes", taxes).map { it.toImmutable() }, - checkRequired("totalHours", totalHours), - checkRequired("type", type), + (earnings ?: JsonMissing.of()).map { it.toImmutable() }, + (employeeDeductions ?: JsonMissing.of()).map { it.toImmutable() }, + (employerContributions ?: JsonMissing.of()).map { it.toImmutable() }, + grossPay, + individualId, + netPay, + paymentMethod, + (taxes ?: JsonMissing.of()).map { it.toImmutable() }, + totalHours, + type, additionalProperties.toMutableMap(), ) } @@ -1148,27 +1111,27 @@ private constructor( class Earning private constructor( private val amount: JsonField, + private val attributes: JsonField, private val currency: JsonField, private val hours: JsonField, private val name: JsonField, private val type: JsonField, - private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @JsonProperty("hours") @ExcludeMissing hours: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), - ) : this(amount, currency, hours, name, type, attributes, mutableMapOf()) + ) : this(amount, attributes, currency, hours, name, type, mutableMapOf()) /** * The earnings amount in cents. @@ -1178,6 +1141,12 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun attributes(): Optional = attributes.getOptional("attributes") + /** * The earnings currency code. * @@ -1211,12 +1180,6 @@ private constructor( */ fun type(): Optional = type.getOptional("type") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * Returns the raw JSON value of [amount]. * @@ -1224,6 +1187,16 @@ private constructor( */ @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + /** * Returns the raw JSON value of [currency]. * @@ -1253,16 +1226,6 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - /** - * Returns the raw JSON value of [attributes]. - * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -1277,40 +1240,29 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Earning]. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .hours() - * .name() - * .type() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Earning]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Earning]. */ class Builder internal constructor() { - private var amount: JsonField? = null - private var currency: JsonField? = null - private var hours: JsonField? = null - private var name: JsonField? = null - private var type: JsonField? = null + private var amount: JsonField = JsonMissing.of() private var attributes: JsonField = JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var hours: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(earning: Earning) = apply { amount = earning.amount + attributes = earning.attributes currency = earning.currency hours = earning.hours name = earning.name type = earning.type - attributes = earning.attributes additionalProperties = earning.additionalProperties.toMutableMap() } @@ -1336,6 +1288,24 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } + fun attributes(attributes: Attributes?) = + attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = + attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + /** The earnings currency code. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -1406,24 +1376,6 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } - fun attributes(attributes: Attributes?) = - attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = - attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1450,26 +1402,15 @@ private constructor( * Returns an immutable instance of [Earning]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .hours() - * .name() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): Earning = Earning( - checkRequired("amount", amount), - checkRequired("currency", currency), - checkRequired("hours", hours), - checkRequired("name", name), - checkRequired("type", type), + amount, attributes, + currency, + hours, + name, + type, additionalProperties.toMutableMap(), ) } @@ -1482,11 +1423,11 @@ private constructor( } amount() + attributes().ifPresent { it.validate() } currency() hours() name() type().ifPresent { it.validate() } - attributes().ifPresent { it.validate() } validated = true } @@ -1507,352 +1448,137 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (hours.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) - /** The type of earning. */ - class Type @JsonCreator private constructor(private val value: JsonField) : - Enum { + class Attributes + private constructor( + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of() + ) : this(metadata, 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 (e.g. + * if the server responded with an unexpected value). */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + fun metadata(): Optional = metadata.getOptional("metadata") - companion object { + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("metadata") + @ExcludeMissing + fun _metadata(): JsonField = metadata - @JvmField val SALARY = of("salary") + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } - @JvmField val WAGE = of("wage") + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) - @JvmField val REIMBURSEMENT = of("reimbursement") + fun toBuilder() = Builder().from(this) - @JvmField val OVERTIME = of("overtime") + companion object { - @JvmField val SEVERANCE = of("severance") + /** Returns a mutable builder for constructing an instance of [Attributes]. */ + @JvmStatic fun builder() = Builder() + } - @JvmField val DOUBLE_OVERTIME = of("double_overtime") + /** A builder for [Attributes]. */ + class Builder internal constructor() { - @JvmField val PTO = of("pto") + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() - @JvmField val SICK = of("sick") + @JvmSynthetic + internal fun from(attributes: Attributes) = apply { + metadata = attributes.metadata + additionalProperties = attributes.additionalProperties.toMutableMap() + } - @JvmField val BONUS = of("bonus") + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) - @JvmField val COMMISSION = of("commission") + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - @JvmField val TIPS = of("tips") + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - @JvmField val _1099 = of("1099") + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } - @JvmField val OTHER = of("other") + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } - /** An enum containing [Type]'s known values. */ - enum class Known { - SALARY, - WAGE, - REIMBURSEMENT, - OVERTIME, - SEVERANCE, - DOUBLE_OVERTIME, - PTO, - SICK, - BONUS, - COMMISSION, - TIPS, - _1099, - OTHER, - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } - /** - * 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 { - SALARY, - WAGE, - REIMBURSEMENT, - OVERTIME, - SEVERANCE, - DOUBLE_OVERTIME, - PTO, - SICK, - BONUS, - COMMISSION, - TIPS, - _1099, - OTHER, /** - * An enum member indicating that [Type] was instantiated with an unknown value. + * Returns an immutable instance of [Attributes]. + * + * Further updates to this [Builder] will not mutate the returned instance. */ - _UNKNOWN, + fun build(): Attributes = + Attributes(metadata, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Attributes = apply { + if (validated) { + return@apply + } + + metadata().ifPresent { it.validate() } + validated = true } + fun isValid(): Boolean = + try { + validate() + true + } catch (e: FinchInvalidDataException) { + false + } + /** - * Returns an enum member corresponding to this class instance's value, or - * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * Returns a score indicating how many valid values are contained in this object + * recursively. * - * 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) { - SALARY -> Value.SALARY - WAGE -> Value.WAGE - REIMBURSEMENT -> Value.REIMBURSEMENT - OVERTIME -> Value.OVERTIME - SEVERANCE -> Value.SEVERANCE - DOUBLE_OVERTIME -> Value.DOUBLE_OVERTIME - PTO -> Value.PTO - SICK -> Value.SICK - BONUS -> Value.BONUS - COMMISSION -> Value.COMMISSION - TIPS -> Value.TIPS - _1099 -> Value._1099 - OTHER -> Value.OTHER - 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) { - SALARY -> Known.SALARY - WAGE -> Known.WAGE - REIMBURSEMENT -> Known.REIMBURSEMENT - OVERTIME -> Known.OVERTIME - SEVERANCE -> Known.SEVERANCE - DOUBLE_OVERTIME -> Known.DOUBLE_OVERTIME - PTO -> Known.PTO - SICK -> Known.SICK - BONUS -> Known.BONUS - COMMISSION -> Known.COMMISSION - TIPS -> Known.TIPS - _1099 -> Known._1099 - OTHER -> Known.OTHER - 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() - } - - class Attributes - private constructor( - private val metadata: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("metadata") - @ExcludeMissing - metadata: JsonField = JsonMissing.of() - ) : this(metadata, 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 metadata(): Metadata = metadata.getRequired("metadata") - - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("metadata") - @ExcludeMissing - fun _metadata(): JsonField = metadata - - @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 [Attributes]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [Attributes]. */ - class Builder internal constructor() { - - private var metadata: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(attributes: Attributes) = apply { - metadata = attributes.metadata - additionalProperties = attributes.additionalProperties.toMutableMap() - } - - fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or - * not yet supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - - 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 [Attributes]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Attributes = - Attributes( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Attributes = apply { - if (validated) { - return@apply - } - - metadata().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. + * Used for best match union deserialization. */ @JvmSynthetic internal fun validity(): Int = (metadata.asKnown().getOrNull()?.validity() ?: 0) @@ -1875,11 +1601,10 @@ private constructor( * key-value pairs where the values can be of any type (string, number, boolean, * object, array, etc.). * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). */ - fun metadata(): InnerMetadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -1905,21 +1630,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Metadata]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -1973,19 +1691,9 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): Metadata = - Metadata( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + Metadata(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -1995,7 +1703,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -2171,38 +1879,238 @@ private constructor( "Attributes{metadata=$metadata, additionalProperties=$additionalProperties}" } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + /** The type of earning. */ + class Type @JsonCreator private constructor(private val value: JsonField) : + Enum { - return /* spotless:off */ other is Earning && amount == other.amount && currency == other.currency && hours == other.hours && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ - } + /** + * 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 - /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, currency, hours, name, type, attributes, additionalProperties) } - /* spotless:on */ + companion object { - override fun hashCode(): Int = hashCode + @JvmField val SALARY = of("salary") - override fun toString() = - "Earning{amount=$amount, currency=$currency, hours=$hours, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" - } + @JvmField val WAGE = of("wage") - class EmployeeDeduction - private constructor( - private val amount: JsonField, - private val currency: JsonField, + @JvmField val REIMBURSEMENT = of("reimbursement") + + @JvmField val OVERTIME = of("overtime") + + @JvmField val SEVERANCE = of("severance") + + @JvmField val DOUBLE_OVERTIME = of("double_overtime") + + @JvmField val PTO = of("pto") + + @JvmField val SICK = of("sick") + + @JvmField val BONUS = of("bonus") + + @JvmField val COMMISSION = of("commission") + + @JvmField val TIPS = of("tips") + + @JvmField val _1099 = of("1099") + + @JvmField val OTHER = of("other") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + SALARY, + WAGE, + REIMBURSEMENT, + OVERTIME, + SEVERANCE, + DOUBLE_OVERTIME, + PTO, + SICK, + BONUS, + COMMISSION, + TIPS, + _1099, + OTHER, + } + + /** + * 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 { + SALARY, + WAGE, + REIMBURSEMENT, + OVERTIME, + SEVERANCE, + DOUBLE_OVERTIME, + PTO, + SICK, + BONUS, + COMMISSION, + TIPS, + _1099, + OTHER, + /** + * 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) { + SALARY -> Value.SALARY + WAGE -> Value.WAGE + REIMBURSEMENT -> Value.REIMBURSEMENT + OVERTIME -> Value.OVERTIME + SEVERANCE -> Value.SEVERANCE + DOUBLE_OVERTIME -> Value.DOUBLE_OVERTIME + PTO -> Value.PTO + SICK -> Value.SICK + BONUS -> Value.BONUS + COMMISSION -> Value.COMMISSION + TIPS -> Value.TIPS + _1099 -> Value._1099 + OTHER -> Value.OTHER + 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) { + SALARY -> Known.SALARY + WAGE -> Known.WAGE + REIMBURSEMENT -> Known.REIMBURSEMENT + OVERTIME -> Known.OVERTIME + SEVERANCE -> Known.SEVERANCE + DOUBLE_OVERTIME -> Known.DOUBLE_OVERTIME + PTO -> Known.PTO + SICK -> Known.SICK + BONUS -> Known.BONUS + COMMISSION -> Known.COMMISSION + TIPS -> Known.TIPS + _1099 -> Known._1099 + OTHER -> Known.OTHER + 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 Earning && amount == other.amount && attributes == other.attributes && currency == other.currency && hours == other.hours && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, hours, name, type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Earning{amount=$amount, attributes=$attributes, currency=$currency, hours=$hours, name=$name, type=$type, additionalProperties=$additionalProperties}" + } + + class EmployeeDeduction + private constructor( + private val amount: JsonField, + private val attributes: JsonField, + private val currency: JsonField, private val name: JsonField, private val preTax: JsonField, private val type: JsonField, - private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @@ -2213,10 +2121,7 @@ private constructor( @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), - ) : this(amount, currency, name, preTax, type, attributes, mutableMapOf()) + ) : this(amount, attributes, currency, name, preTax, type, mutableMapOf()) /** * The deduction amount in cents. @@ -2226,6 +2131,12 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun attributes(): Optional = attributes.getOptional("attributes") + /** * The deduction currency. * @@ -2258,12 +2169,6 @@ private constructor( */ fun type(): Optional = type.getOptional("type") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * Returns the raw JSON value of [amount]. * @@ -2271,6 +2176,16 @@ private constructor( */ @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + /** * Returns the raw JSON value of [currency]. * @@ -2300,16 +2215,6 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - /** - * Returns the raw JSON value of [attributes]. - * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -2326,15 +2231,6 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [EmployeeDeduction]. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .name() - * .preTax() - * .type() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -2342,22 +2238,22 @@ private constructor( /** A builder for [EmployeeDeduction]. */ class Builder internal constructor() { - private var amount: JsonField? = null - private var currency: JsonField? = null - private var name: JsonField? = null - private var preTax: JsonField? = null - private var type: JsonField? = null + private var amount: JsonField = JsonMissing.of() private var attributes: JsonField = JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var preTax: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(employeeDeduction: EmployeeDeduction) = apply { amount = employeeDeduction.amount + attributes = employeeDeduction.attributes currency = employeeDeduction.currency name = employeeDeduction.name preTax = employeeDeduction.preTax type = employeeDeduction.type - attributes = employeeDeduction.attributes additionalProperties = employeeDeduction.additionalProperties.toMutableMap() } @@ -2383,6 +2279,24 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } + fun attributes(attributes: Attributes?) = + attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = + attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + /** The deduction currency. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -2450,24 +2364,6 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } - fun attributes(attributes: Attributes?) = - attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = - attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -2494,26 +2390,15 @@ private constructor( * Returns an immutable instance of [EmployeeDeduction]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .name() - * .preTax() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): EmployeeDeduction = EmployeeDeduction( - checkRequired("amount", amount), - checkRequired("currency", currency), - checkRequired("name", name), - checkRequired("preTax", preTax), - checkRequired("type", type), + amount, attributes, + currency, + name, + preTax, + type, additionalProperties.toMutableMap(), ) } @@ -2526,11 +2411,11 @@ private constructor( } amount() + attributes().ifPresent { it.validate() } currency() name() preTax() type().ifPresent { it.validate() } - attributes().ifPresent { it.validate() } validated = true } @@ -2551,11 +2436,11 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + (if (preTax.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) class Attributes private constructor( @@ -2571,11 +2456,10 @@ private constructor( ) : this(metadata, 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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). */ - fun metadata(): Metadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -2601,21 +2485,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Attributes]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Attributes]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -2661,19 +2538,9 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): Attributes = - Attributes( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + Attributes(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -2683,7 +2550,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -2722,11 +2589,10 @@ private constructor( * key-value pairs where the values can be of any type (string, number, boolean, * object, array, etc.). * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). */ - fun metadata(): InnerMetadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -2752,21 +2618,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Metadata]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -2820,19 +2679,9 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): Metadata = - Metadata( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + Metadata(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -2842,7 +2691,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -3023,32 +2872,35 @@ private constructor( return true } - return /* spotless:off */ other is EmployeeDeduction && amount == other.amount && currency == other.currency && name == other.name && preTax == other.preTax && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is EmployeeDeduction && amount == other.amount && attributes == other.attributes && currency == other.currency && name == other.name && preTax == other.preTax && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, currency, name, preTax, type, attributes, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, name, preTax, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "EmployeeDeduction{amount=$amount, currency=$currency, name=$name, preTax=$preTax, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" + "EmployeeDeduction{amount=$amount, attributes=$attributes, currency=$currency, name=$name, preTax=$preTax, type=$type, additionalProperties=$additionalProperties}" } class EmployerContribution private constructor( private val amount: JsonField, + private val attributes: JsonField, private val currency: JsonField, private val name: JsonField, private val type: JsonField, - private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @@ -3056,10 +2908,7 @@ private constructor( @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), - ) : this(amount, currency, name, type, attributes, mutableMapOf()) + ) : this(amount, attributes, currency, name, type, mutableMapOf()) /** * The contribution amount in cents. @@ -3069,6 +2918,12 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun attributes(): Optional = attributes.getOptional("attributes") + /** * The contribution currency. * @@ -3093,12 +2948,6 @@ private constructor( */ fun type(): Optional = type.getOptional("type") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * Returns the raw JSON value of [amount]. * @@ -3106,6 +2955,16 @@ private constructor( */ @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + /** * Returns the raw JSON value of [currency]. * @@ -3128,16 +2987,6 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - /** - * Returns the raw JSON value of [attributes]. - * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -3154,14 +3003,6 @@ private constructor( /** * Returns a mutable builder for constructing an instance of [EmployerContribution]. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .name() - * .type() - * ``` */ @JvmStatic fun builder() = Builder() } @@ -3169,20 +3010,20 @@ private constructor( /** A builder for [EmployerContribution]. */ class Builder internal constructor() { - private var amount: JsonField? = null - private var currency: JsonField? = null - private var name: JsonField? = null - private var type: JsonField? = null + private var amount: JsonField = JsonMissing.of() private var attributes: JsonField = JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(employerContribution: EmployerContribution) = apply { amount = employerContribution.amount + attributes = employerContribution.attributes currency = employerContribution.currency name = employerContribution.name type = employerContribution.type - attributes = employerContribution.attributes additionalProperties = employerContribution.additionalProperties.toMutableMap() } @@ -3208,6 +3049,24 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } + fun attributes(attributes: Attributes?) = + attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = + attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + /** The contribution currency. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -3253,24 +3112,6 @@ private constructor( */ fun type(type: JsonField) = apply { this.type = type } - fun attributes(attributes: Attributes?) = - attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = - attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -3297,24 +3138,14 @@ private constructor( * Returns an immutable instance of [EmployerContribution]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .name() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): EmployerContribution = EmployerContribution( - checkRequired("amount", amount), - checkRequired("currency", currency), - checkRequired("name", name), - checkRequired("type", type), + amount, attributes, + currency, + name, + type, additionalProperties.toMutableMap(), ) } @@ -3327,10 +3158,10 @@ private constructor( } amount() + attributes().ifPresent { it.validate() } currency() name() type().ifPresent { it.validate() } - attributes().ifPresent { it.validate() } validated = true } @@ -3351,10 +3182,10 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (amount.asKnown().isPresent) 1 else 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) + (if (currency.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) + (type.asKnown().getOrNull()?.validity() ?: 0) class Attributes private constructor( @@ -3370,11 +3201,10 @@ private constructor( ) : this(metadata, 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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). */ - fun metadata(): Metadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -3400,21 +3230,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Attributes]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Attributes]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -3460,19 +3283,9 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): Attributes = - Attributes( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + Attributes(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -3482,7 +3295,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -3521,11 +3334,10 @@ private constructor( * key-value pairs where the values can be of any type (string, number, boolean, * object, array, etc.). * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). */ - fun metadata(): InnerMetadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -3551,21 +3363,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Metadata]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -3619,19 +3424,9 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): Metadata = - Metadata( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + Metadata(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -3641,7 +3436,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -3822,17 +3617,17 @@ private constructor( return true } - return /* spotless:off */ other is EmployerContribution && amount == other.amount && currency == other.currency && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is EmployerContribution && amount == other.amount && attributes == other.attributes && currency == other.currency && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, currency, name, type, attributes, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, name, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "EmployerContribution{amount=$amount, currency=$currency, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" + "EmployerContribution{amount=$amount, attributes=$attributes, currency=$currency, name=$name, type=$type, additionalProperties=$additionalProperties}" } /** The payment method. */ @@ -3976,17 +3771,20 @@ private constructor( class Tax private constructor( private val amount: JsonField, + private val attributes: JsonField, private val currency: JsonField, private val employer: JsonField, private val name: JsonField, private val type: JsonField, - private val attributes: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), + @JsonProperty("attributes") + @ExcludeMissing + attributes: JsonField = JsonMissing.of(), @JsonProperty("currency") @ExcludeMissing currency: JsonField = JsonMissing.of(), @@ -3995,10 +3793,7 @@ private constructor( employer: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - @JsonProperty("attributes") - @ExcludeMissing - attributes: JsonField = JsonMissing.of(), - ) : this(amount, currency, employer, name, type, attributes, mutableMapOf()) + ) : this(amount, attributes, currency, employer, name, type, mutableMapOf()) /** * The tax amount in cents. @@ -4008,6 +3803,12 @@ private constructor( */ fun amount(): Optional = amount.getOptional("amount") + /** + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun attributes(): Optional = attributes.getOptional("attributes") + /** * The currency code. * @@ -4040,12 +3841,6 @@ private constructor( */ fun type(): Optional = type.getOptional("type") - /** - * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). - */ - fun attributes(): Optional = attributes.getOptional("attributes") - /** * Returns the raw JSON value of [amount]. * @@ -4053,6 +3848,16 @@ private constructor( */ @JsonProperty("amount") @ExcludeMissing fun _amount(): JsonField = amount + /** + * Returns the raw JSON value of [attributes]. + * + * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("attributes") + @ExcludeMissing + fun _attributes(): JsonField = attributes + /** * Returns the raw JSON value of [currency]. * @@ -4083,16 +3888,6 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - /** - * Returns the raw JSON value of [attributes]. - * - * Unlike [attributes], this method doesn't throw if the JSON field has an unexpected - * type. - */ - @JsonProperty("attributes") - @ExcludeMissing - fun _attributes(): JsonField = attributes - @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -4107,40 +3902,29 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Tax]. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .employer() - * .name() - * .type() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Tax]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Tax]. */ class Builder internal constructor() { - private var amount: JsonField? = null - private var currency: JsonField? = null - private var employer: JsonField? = null - private var name: JsonField? = null - private var type: JsonField? = null + private var amount: JsonField = JsonMissing.of() private var attributes: JsonField = JsonMissing.of() + private var currency: JsonField = JsonMissing.of() + private var employer: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tax: Tax) = apply { amount = tax.amount + attributes = tax.attributes currency = tax.currency employer = tax.employer name = tax.name type = tax.type - attributes = tax.attributes additionalProperties = tax.additionalProperties.toMutableMap() } @@ -4166,6 +3950,24 @@ private constructor( */ fun amount(amount: JsonField) = apply { this.amount = amount } + fun attributes(attributes: Attributes?) = + attributes(JsonField.ofNullable(attributes)) + + /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ + fun attributes(attributes: Optional) = + attributes(attributes.getOrNull()) + + /** + * Sets [Builder.attributes] to an arbitrary JSON value. + * + * You should usually call [Builder.attributes] with a well-typed [Attributes] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun attributes(attributes: JsonField) = apply { + this.attributes = attributes + } + /** The currency code. */ fun currency(currency: String?) = currency(JsonField.ofNullable(currency)) @@ -4216,273 +4018,101 @@ private constructor( * 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 type of taxes. */ - 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 attributes(attributes: Attributes?) = - attributes(JsonField.ofNullable(attributes)) - - /** Alias for calling [Builder.attributes] with `attributes.orElse(null)`. */ - fun attributes(attributes: Optional) = - attributes(attributes.getOrNull()) - - /** - * Sets [Builder.attributes] to an arbitrary JSON value. - * - * You should usually call [Builder.attributes] with a well-typed [Attributes] value - * instead. This method is primarily for setting the field to an undocumented or not - * yet supported value. - */ - fun attributes(attributes: JsonField) = apply { - this.attributes = attributes - } - - 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 [Tax]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .amount() - * .currency() - * .employer() - * .name() - * .type() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): Tax = - Tax( - checkRequired("amount", amount), - checkRequired("currency", currency), - checkRequired("employer", employer), - checkRequired("name", name), - checkRequired("type", type), - attributes, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): Tax = apply { - if (validated) { - return@apply - } - - amount() - currency() - employer() - name() - type().ifPresent { it.validate() } - attributes().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 = - (if (amount.asKnown().isPresent) 1 else 0) + - (if (currency.asKnown().isPresent) 1 else 0) + - (if (employer.asKnown().isPresent) 1 else 0) + - (if (name.asKnown().isPresent) 1 else 0) + - (type.asKnown().getOrNull()?.validity() ?: 0) + - (attributes.asKnown().getOrNull()?.validity() ?: 0) - - /** The type of taxes. */ - 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 STATE = of("state") - - @JvmField val FEDERAL = of("federal") - - @JvmField val LOCAL = of("local") - - @JvmField val FICA = of("fica") - - @JvmStatic fun of(value: String) = Type(JsonField.of(value)) - } - - /** An enum containing [Type]'s known values. */ - enum class Known { - STATE, - FEDERAL, - LOCAL, - FICA, - } - - /** - * 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 { - STATE, - FEDERAL, - LOCAL, - FICA, - /** - * 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) { - STATE -> Value.STATE - FEDERAL -> Value.FEDERAL - LOCAL -> Value.LOCAL - FICA -> Value.FICA - 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) { - STATE -> Known.STATE - FEDERAL -> Known.FEDERAL - LOCAL -> Known.LOCAL - FICA -> Known.FICA - else -> throw FinchInvalidDataException("Unknown Type: $value") - } + fun name(name: JsonField) = apply { this.name = name } + + /** The type of taxes. */ + fun type(type: Type?) = type(JsonField.ofNullable(type)) + + /** Alias for calling [Builder.type] with `type.orElse(null)`. */ + fun type(type: Optional) = type(type.getOrNull()) /** - * 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. + * Sets [Builder.type] to an arbitrary JSON value. * - * @throws FinchInvalidDataException if this class instance's value does not have - * the expected primitive type. + * 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 asString(): String = - _value().asString().orElseThrow { - FinchInvalidDataException("Value is not a String") - } + fun type(type: JsonField) = apply { this.type = type } - private var validated: Boolean = false + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } - fun validate(): Type = apply { - if (validated) { - return@apply + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) } - known() - validated = true + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) } - fun isValid(): Boolean = - try { - validate() - true - } catch (e: FinchInvalidDataException) { - false - } + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } /** - * Returns a score indicating how many valid values are contained in this object - * recursively. + * Returns an immutable instance of [Tax]. * - * Used for best match union deserialization. + * Further updates to this [Builder] will not mutate the returned instance. */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + fun build(): Tax = + Tax( + amount, + attributes, + currency, + employer, + name, + type, + additionalProperties.toMutableMap(), + ) + } - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + private var validated: Boolean = false - return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + fun validate(): Tax = apply { + if (validated) { + return@apply } - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() + amount() + attributes().ifPresent { it.validate() } + currency() + employer() + name() + 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 = + (if (amount.asKnown().isPresent) 1 else 0) + + (attributes.asKnown().getOrNull()?.validity() ?: 0) + + (if (currency.asKnown().isPresent) 1 else 0) + + (if (employer.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + class Attributes private constructor( private val metadata: JsonField, @@ -4497,11 +4127,10 @@ private constructor( ) : this(metadata, 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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). */ - fun metadata(): Metadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -4527,21 +4156,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Attributes]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Attributes]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Attributes]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -4587,19 +4209,9 @@ private constructor( * Returns an immutable instance of [Attributes]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): Attributes = - Attributes( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + Attributes(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -4609,7 +4221,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -4648,11 +4260,10 @@ private constructor( * key-value pairs where the values can be of any type (string, number, boolean, * object, array, etc.). * - * @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). + * @throws FinchInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). */ - fun metadata(): InnerMetadata = metadata.getRequired("metadata") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [metadata]. @@ -4678,21 +4289,14 @@ private constructor( companion object { - /** - * Returns a mutable builder for constructing an instance of [Metadata]. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - */ + /** Returns a mutable builder for constructing an instance of [Metadata]. */ @JvmStatic fun builder() = Builder() } /** A builder for [Metadata]. */ class Builder internal constructor() { - private var metadata: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -4746,19 +4350,9 @@ private constructor( * Returns an immutable instance of [Metadata]. * * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .metadata() - * ``` - * - * @throws IllegalStateException if any required field is unset. */ fun build(): Metadata = - Metadata( - checkRequired("metadata", metadata), - additionalProperties.toMutableMap(), - ) + Metadata(metadata, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -4768,7 +4362,7 @@ private constructor( return@apply } - metadata().validate() + metadata().ifPresent { it.validate() } validated = true } @@ -4944,22 +4538,165 @@ private constructor( "Attributes{metadata=$metadata, additionalProperties=$additionalProperties}" } + /** The type of taxes. */ + 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 STATE = of("state") + + @JvmField val FEDERAL = of("federal") + + @JvmField val LOCAL = of("local") + + @JvmField val FICA = of("fica") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + STATE, + FEDERAL, + LOCAL, + FICA, + } + + /** + * 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 { + STATE, + FEDERAL, + LOCAL, + FICA, + /** + * 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) { + STATE -> Value.STATE + FEDERAL -> Value.FEDERAL + LOCAL -> Value.LOCAL + FICA -> Value.FICA + 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) { + STATE -> Known.STATE + FEDERAL -> Known.FEDERAL + LOCAL -> Known.LOCAL + FICA -> Known.FICA + 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 Tax && amount == other.amount && currency == other.currency && employer == other.employer && name == other.name && type == other.type && attributes == other.attributes && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Tax && amount == other.amount && attributes == other.attributes && currency == other.currency && employer == other.employer && name == other.name && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(amount, currency, employer, name, type, attributes, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(amount, attributes, currency, employer, name, type, additionalProperties) } /* spotless:on */ override fun hashCode(): Int = hashCode override fun toString() = - "Tax{amount=$amount, currency=$currency, employer=$employer, name=$name, type=$type, attributes=$attributes, additionalProperties=$additionalProperties}" + "Tax{amount=$amount, attributes=$attributes, currency=$currency, employer=$employer, name=$name, type=$type, additionalProperties=$additionalProperties}" } /** The type of the payment associated with the pay statement. */ 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 17bf547a..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 @@ -27,7 +27,7 @@ internal class CompanyBenefitTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._457) + .type(BenefitType._401K) .build() assertThat(companyBenefit.benefitId()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") @@ -45,7 +45,7 @@ internal class CompanyBenefitTest { ) assertThat(companyBenefit.description()).contains("description") assertThat(companyBenefit.frequency()).contains(BenefitFrequency.ONE_TIME) - assertThat(companyBenefit.type()).contains(BenefitType._457) + assertThat(companyBenefit.type()).contains(BenefitType._401K) } @Test @@ -67,7 +67,7 @@ internal class CompanyBenefitTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._457) + .type(BenefitType._401K) .build() val roundtrippedCompanyBenefit = 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 65de7bff..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 @@ -23,7 +23,7 @@ internal class HrisBenefitCreateParamsTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._457) + .type(BenefitType._401K) .build() } @@ -44,7 +44,7 @@ internal class HrisBenefitCreateParamsTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._457) + .type(BenefitType._401K) .build() val body = params._body() @@ -63,7 +63,7 @@ internal class HrisBenefitCreateParamsTest { ) assertThat(body.description()).contains("description") assertThat(body.frequency()).contains(BenefitFrequency.ONE_TIME) - assertThat(body.type()).contains(BenefitType._457) + assertThat(body.type()).contains(BenefitType._401K) } @Test diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageResponseTest.kt index aca870bd..73041054 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageResponseTest.kt @@ -18,12 +18,12 @@ internal class HrisCompanyPayStatementItemListPageResponseTest { PayStatementItemListResponse.builder() .attributes( PayStatementItemListResponse.Attributes.builder() + .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) - .employer(true) .preTax(true) .type("type") .build() @@ -39,12 +39,12 @@ internal class HrisCompanyPayStatementItemListPageResponseTest { PayStatementItemListResponse.builder() .attributes( PayStatementItemListResponse.Attributes.builder() + .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) - .employer(true) .preTax(true) .type("type") .build() @@ -64,12 +64,12 @@ internal class HrisCompanyPayStatementItemListPageResponseTest { PayStatementItemListResponse.builder() .attributes( PayStatementItemListResponse.Attributes.builder() + .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) - .employer(true) .preTax(true) .type("type") .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 a3dc09f4..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,21 +18,12 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging( - PayStatementResponseBody.Paging.builder() - .offset(0L) - .count(0L) - .build() - ) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -55,15 +46,15 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes .builder() @@ -90,14 +81,15 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes .builder() @@ -125,6 +117,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay( @@ -138,10 +133,6 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -164,6 +155,10 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -183,21 +178,12 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging( - PayStatementResponseBody.Paging.builder() - .offset(0L) - .count(0L) - .build() - ) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -220,15 +206,15 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -253,14 +239,15 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes .builder() @@ -286,6 +273,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay( @@ -297,10 +287,6 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -322,6 +308,10 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -345,21 +335,12 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging( - PayStatementResponseBody.Paging.builder() - .offset(0L) - .count(0L) - .build() - ) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -382,15 +363,15 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes .builder() @@ -417,14 +398,15 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes .builder() @@ -452,6 +434,9 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay( @@ -465,10 +450,6 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -491,6 +472,10 @@ internal class HrisPayStatementRetrieveManyPageResponseTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/MoneyTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/MoneyTest.kt index a9e57056..76045e09 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/MoneyTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/MoneyTest.kt @@ -14,7 +14,7 @@ internal class MoneyTest { val money = Money.builder().amount(0L).currency("currency").build() assertThat(money.amount()).contains(0L) - assertThat(money.currency()).isEqualTo("currency") + assertThat(money.currency()).contains("currency") } @Test diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayGroupListResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayGroupListResponseTest.kt index a0cd4fb7..e696a7ea 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayGroupListResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayGroupListResponseTest.kt @@ -4,6 +4,7 @@ package com.tryfinch.api.models import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.tryfinch.api.core.jsonMapper +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -18,9 +19,9 @@ internal class PayGroupListResponseTest { .addPayFrequency(PayGroupListResponse.PayFrequency.ANNUALLY) .build() - assertThat(payGroupListResponse.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") - assertThat(payGroupListResponse.name()).isEqualTo("name") - assertThat(payGroupListResponse.payFrequencies()) + assertThat(payGroupListResponse.id()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + assertThat(payGroupListResponse.name()).contains("name") + assertThat(payGroupListResponse.payFrequencies().getOrNull()) .containsExactly(PayGroupListResponse.PayFrequency.ANNUALLY) } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementItemListResponseTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementItemListResponseTest.kt index 332a3257..56558e40 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementItemListResponseTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementItemListResponseTest.kt @@ -16,12 +16,12 @@ internal class PayStatementItemListResponseTest { PayStatementItemListResponse.builder() .attributes( PayStatementItemListResponse.Attributes.builder() + .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) - .employer(true) .preTax(true) .type("type") .build() @@ -31,21 +31,21 @@ internal class PayStatementItemListResponseTest { .build() assertThat(payStatementItemListResponse.attributes()) - .isEqualTo( + .contains( PayStatementItemListResponse.Attributes.builder() + .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) - .employer(true) .preTax(true) .type("type") .build() ) assertThat(payStatementItemListResponse.category()) - .isEqualTo(PayStatementItemListResponse.Category.EARNINGS) - assertThat(payStatementItemListResponse.name()).isEqualTo("name") + .contains(PayStatementItemListResponse.Category.EARNINGS) + assertThat(payStatementItemListResponse.name()).contains("name") } @Test @@ -55,12 +55,12 @@ internal class PayStatementItemListResponseTest { PayStatementItemListResponse.builder() .attributes( PayStatementItemListResponse.Attributes.builder() + .employer(true) .metadata( PayStatementItemListResponse.Attributes.Metadata.builder() .putAdditionalProperty("foo", JsonValue.from("bar")) .build() ) - .employer(true) .preTax(true) .type("type") .build() 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 0968a185..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 @@ -5,6 +5,7 @@ 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 org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -14,16 +15,12 @@ internal class PayStatementResponseBodyTest { fun create() { val payStatementResponseBody = PayStatementResponseBody.builder() - .paging(PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -42,15 +39,15 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -71,14 +68,15 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -99,6 +97,9 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -108,10 +109,6 @@ internal class PayStatementResponseBodyTest { .addTax( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -130,6 +127,10 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -139,17 +140,13 @@ internal class PayStatementResponseBodyTest { .build() assertThat(payStatementResponseBody.paging()) - .isEqualTo(PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build()) - assertThat(payStatementResponseBody.payStatements()) + .contains(Paging.builder().offset(0L).count(0L).build()) + assertThat(payStatementResponseBody.payStatements().getOrNull()) .containsExactly( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -168,15 +165,15 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -195,14 +192,15 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -223,6 +221,9 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -232,10 +233,6 @@ internal class PayStatementResponseBodyTest { .addTax( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -253,6 +250,10 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -266,16 +267,12 @@ internal class PayStatementResponseBodyTest { val jsonMapper = jsonMapper() val payStatementResponseBody = PayStatementResponseBody.builder() - .paging(PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -294,15 +291,15 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -323,14 +320,15 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -351,6 +349,9 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -360,10 +361,6 @@ internal class PayStatementResponseBodyTest { .addTax( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -382,6 +379,10 @@ internal class PayStatementResponseBodyTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) 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 2ecf667c..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,18 +16,12 @@ internal class PayStatementResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging( - PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build() - ) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -49,15 +43,15 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -82,14 +76,15 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -114,6 +109,9 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -123,10 +121,6 @@ internal class PayStatementResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -147,6 +141,10 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -160,18 +158,14 @@ internal class PayStatementResponseTest { .build() assertThat(payStatementResponse.body()) - .isEqualTo( + .contains( PayStatementResponseBody.builder() - .paging(PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build()) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -190,15 +184,15 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -219,14 +213,15 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -248,6 +243,9 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -257,10 +255,6 @@ internal class PayStatementResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -279,6 +273,10 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -287,8 +285,8 @@ internal class PayStatementResponseTest { ) .build() ) - assertThat(payStatementResponse.code()).isEqualTo(0L) - assertThat(payStatementResponse.paymentId()).isEqualTo("payment_id") + assertThat(payStatementResponse.code()).contains(0L) + assertThat(payStatementResponse.paymentId()).contains("payment_id") } @Test @@ -298,18 +296,12 @@ internal class PayStatementResponseTest { PayStatementResponse.builder() .body( PayStatementResponseBody.builder() - .paging( - PayStatementResponseBody.Paging.builder().offset(0L).count(0L).build() - ) + .paging(Paging.builder().offset(0L).count(0L).build()) .addPayStatement( PayStatement.builder() .addEarning( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -331,15 +323,15 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -364,14 +356,15 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -396,6 +389,9 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -405,10 +401,6 @@ internal class PayStatementResponseTest { .addTax( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -429,6 +421,10 @@ internal class PayStatementResponseTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) 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 05b154a3..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 @@ -18,10 +18,6 @@ internal class PayStatementTest { .addEarning( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -39,15 +35,15 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -66,14 +62,15 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -92,6 +89,9 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -101,10 +101,6 @@ internal class PayStatementTest { .addTax( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -122,6 +118,10 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -132,10 +132,6 @@ internal class PayStatementTest { .containsExactly( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -153,16 +149,16 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) assertThat(payStatement.employeeDeductions().getOrNull()) .containsExactly( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -181,15 +177,16 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) assertThat(payStatement.employerContributions().getOrNull()) .containsExactly( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -208,11 +205,14 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) assertThat(payStatement.grossPay()) .contains(Money.builder().amount(0L).currency("currency").build()) - assertThat(payStatement.individualId()).isEqualTo("individual_id") + assertThat(payStatement.individualId()).contains("individual_id") assertThat(payStatement.netPay()) .contains(Money.builder().amount(0L).currency("currency").build()) assertThat(payStatement.paymentMethod()).contains(PayStatement.PaymentMethod.CHECK) @@ -220,10 +220,6 @@ internal class PayStatementTest { .containsExactly( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -240,6 +236,10 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) assertThat(payStatement.totalHours()).contains(0.0) @@ -254,10 +254,6 @@ internal class PayStatementTest { .addEarning( PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(PayStatement.Earning.Type.SALARY) .attributes( PayStatement.Earning.Attributes.builder() .metadata( @@ -275,15 +271,15 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( PayStatement.EmployeeDeduction.builder() .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) .attributes( PayStatement.EmployeeDeduction.Attributes.builder() .metadata( @@ -302,14 +298,15 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .name("name") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( PayStatement.EmployerContribution.Attributes.builder() .metadata( @@ -328,6 +325,9 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) @@ -337,10 +337,6 @@ internal class PayStatementTest { .addTax( PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(PayStatement.Tax.Type.STATE) .attributes( PayStatement.Tax.Attributes.builder() .metadata( @@ -358,6 +354,10 @@ internal class PayStatementTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PaymentTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PaymentTest.kt index c21eb02e..fce8572b 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PaymentTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/PaymentTest.kt @@ -30,7 +30,7 @@ internal class PaymentTest { ) .build() - assertThat(payment.id()).isEqualTo("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") + assertThat(payment.id()).contains("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") assertThat(payment.companyDebit()) .contains(Money.builder().amount(0L).currency("currency").build()) assertThat(payment.debitDate()).contains("debit_date") 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 779152df..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 @@ -18,10 +18,6 @@ internal class SandboxPaymentCreateParamsTest { .addEarning( SandboxPaymentCreateParams.PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .attributes( SandboxPaymentCreateParams.PayStatement.Earning.Attributes.builder() .metadata( @@ -44,15 +40,15 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.builder() - .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) + .amount(2000L) .attributes( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.Attributes .builder() @@ -78,14 +74,15 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("usd") + .name("401k test") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( SandboxPaymentCreateParams.PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployerContribution .Attributes @@ -112,19 +109,18 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) - .individualId("individual_id") + .individualId("b2338cfb-472f-4f72-9faa-e028c083144a") .netPay(Money.builder().amount(0L).currency("currency").build()) .paymentMethod(SandboxPaymentCreateParams.PayStatement.PaymentMethod.CHECK) .addTax( SandboxPaymentCreateParams.PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .attributes( SandboxPaymentCreateParams.PayStatement.Tax.Attributes.builder() .metadata( @@ -147,6 +143,10 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -167,10 +167,6 @@ internal class SandboxPaymentCreateParamsTest { .addEarning( SandboxPaymentCreateParams.PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .attributes( SandboxPaymentCreateParams.PayStatement.Earning.Attributes .builder() @@ -195,15 +191,15 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.builder() - .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) + .amount(2000L) .attributes( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction .Attributes @@ -231,14 +227,15 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("usd") + .name("401k test") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( SandboxPaymentCreateParams.PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployerContribution .Attributes @@ -266,19 +263,18 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) - .individualId("individual_id") + .individualId("b2338cfb-472f-4f72-9faa-e028c083144a") .netPay(Money.builder().amount(0L).currency("currency").build()) .paymentMethod(SandboxPaymentCreateParams.PayStatement.PaymentMethod.CHECK) .addTax( SandboxPaymentCreateParams.PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .attributes( SandboxPaymentCreateParams.PayStatement.Tax.Attributes.builder() .metadata( @@ -301,6 +297,10 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) @@ -319,10 +319,6 @@ internal class SandboxPaymentCreateParamsTest { .addEarning( SandboxPaymentCreateParams.PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .attributes( SandboxPaymentCreateParams.PayStatement.Earning.Attributes.builder() .metadata( @@ -345,15 +341,15 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY) .build() ) .addEmployeeDeduction( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.builder() - .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) + .amount(2000L) .attributes( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.Attributes .builder() @@ -379,14 +375,15 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("usd") + .name("401k test") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( SandboxPaymentCreateParams.PayStatement.EmployerContribution.builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployerContribution .Attributes @@ -413,19 +410,18 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) - .individualId("individual_id") + .individualId("b2338cfb-472f-4f72-9faa-e028c083144a") .netPay(Money.builder().amount(0L).currency("currency").build()) .paymentMethod(SandboxPaymentCreateParams.PayStatement.PaymentMethod.CHECK) .addTax( SandboxPaymentCreateParams.PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .attributes( SandboxPaymentCreateParams.PayStatement.Tax.Attributes.builder() .metadata( @@ -448,6 +444,10 @@ internal class SandboxPaymentCreateParamsTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) 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 99d7b0e9..9d4af287 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 @@ -42,7 +42,7 @@ internal class BenefitServiceAsyncTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._457) + .type(BenefitType._401K) .build() ) 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 6405f81b..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 @@ -32,12 +32,6 @@ internal class PaymentServiceAsyncTest { .addEarning( SandboxPaymentCreateParams.PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type( - SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY - ) .attributes( SandboxPaymentCreateParams.PayStatement.Earning.Attributes .builder() @@ -63,15 +57,17 @@ internal class PaymentServiceAsyncTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type( + SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY + ) .build() ) .addEmployeeDeduction( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.builder() - .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) + .amount(2000L) .attributes( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction .Attributes @@ -99,15 +95,16 @@ internal class PaymentServiceAsyncTest { ) .build() ) + .currency("usd") + .name("401k test") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( SandboxPaymentCreateParams.PayStatement.EmployerContribution .builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployerContribution .Attributes @@ -135,10 +132,13 @@ internal class PaymentServiceAsyncTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) - .individualId("individual_id") + .individualId("b2338cfb-472f-4f72-9faa-e028c083144a") .netPay(Money.builder().amount(0L).currency("currency").build()) .paymentMethod( SandboxPaymentCreateParams.PayStatement.PaymentMethod.CHECK @@ -146,10 +146,6 @@ internal class PaymentServiceAsyncTest { .addTax( SandboxPaymentCreateParams.PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .attributes( SandboxPaymentCreateParams.PayStatement.Tax.Attributes .builder() @@ -174,6 +170,10 @@ internal class PaymentServiceAsyncTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) 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 334986ff..ff54482a 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 @@ -42,7 +42,7 @@ internal class BenefitServiceTest { ) .description("description") .frequency(BenefitFrequency.ONE_TIME) - .type(BenefitType._457) + .type(BenefitType._401K) .build() ) 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 8ac4538e..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 @@ -32,12 +32,6 @@ internal class PaymentServiceTest { .addEarning( SandboxPaymentCreateParams.PayStatement.Earning.builder() .amount(0L) - .currency("currency") - .hours(0.0) - .name("name") - .type( - SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY - ) .attributes( SandboxPaymentCreateParams.PayStatement.Earning.Attributes .builder() @@ -63,15 +57,17 @@ internal class PaymentServiceTest { ) .build() ) + .currency("currency") + .hours(0.0) + .name("name") + .type( + SandboxPaymentCreateParams.PayStatement.Earning.Type.SALARY + ) .build() ) .addEmployeeDeduction( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction.builder() - .amount(0L) - .currency("currency") - .name("name") - .preTax(true) - .type(BenefitType._457) + .amount(2000L) .attributes( SandboxPaymentCreateParams.PayStatement.EmployeeDeduction .Attributes @@ -99,15 +95,16 @@ internal class PaymentServiceTest { ) .build() ) + .currency("usd") + .name("401k test") + .preTax(true) + .type(BenefitType._401K) .build() ) .addEmployerContribution( SandboxPaymentCreateParams.PayStatement.EmployerContribution .builder() .amount(0L) - .currency("currency") - .name("name") - .type(BenefitType._457) .attributes( SandboxPaymentCreateParams.PayStatement.EmployerContribution .Attributes @@ -135,10 +132,13 @@ internal class PaymentServiceTest { ) .build() ) + .currency("currency") + .name("name") + .type(BenefitType._401K) .build() ) .grossPay(Money.builder().amount(0L).currency("currency").build()) - .individualId("individual_id") + .individualId("b2338cfb-472f-4f72-9faa-e028c083144a") .netPay(Money.builder().amount(0L).currency("currency").build()) .paymentMethod( SandboxPaymentCreateParams.PayStatement.PaymentMethod.CHECK @@ -146,10 +146,6 @@ internal class PaymentServiceTest { .addTax( SandboxPaymentCreateParams.PayStatement.Tax.builder() .amount(0L) - .currency("currency") - .employer(true) - .name("name") - .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .attributes( SandboxPaymentCreateParams.PayStatement.Tax.Attributes .builder() @@ -174,6 +170,10 @@ internal class PaymentServiceTest { ) .build() ) + .currency("currency") + .employer(true) + .name("name") + .type(SandboxPaymentCreateParams.PayStatement.Tax.Type.STATE) .build() ) .totalHours(0.0) From a887915ba3c11780e90540866c9e95fc3d10b301 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 16 May 2025 04:52:49 +0000 Subject: [PATCH 6/6] release: 7.0.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 21 +++++++++++++++++++++ README.md | 10 +++++----- build.gradle.kts | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 112e32b3..180ef9e3 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "6.0.0" + ".": "7.0.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 38ebf293..a9ad4b1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## 7.0.0 (2025-05-16) + +Full Changelog: [v6.0.0...v7.0.0](https://github.com/Finch-API/finch-api-java/compare/v6.0.0...v7.0.0) + +### ⚠ BREAKING CHANGES + +* **client:** extract auto pagination to shared classes +* **client:** **Migration:** - If you were referencing the `AutoPager` class on a specific `*Page` or `*PageAsync` type, then you should instead reference the shared `AutoPager` and `AutoPagerAsync` types, under the `core` package + - `AutoPagerAsync` now has different usage. You can call `.subscribe(...)` on the returned object instead to get called back each page item. You can also call `onCompleteFuture()` to get a future that completes when all items have been processed. Finally, you can call `.close()` on the returned object to stop auto-paginating early + - If you were referencing `getNextPage` or `getNextPageParams`: + - Swap to `nextPage()` and `nextPageParams()` + - Note that these both now return non-optional types (use `hasNextPage()` before calling these, since they will throw if it's impossible to get another page) + +### Features + +* **api:** api update ([f226da9](https://github.com/Finch-API/finch-api-java/commit/f226da9c89911bb4f3f39f3657c2f725d0773e7a)) +* **api:** api update ([7932861](https://github.com/Finch-API/finch-api-java/commit/79328615d98546e904f7cf99c222f7645ecd9131)) +* **api:** api update ([17bd5c1](https://github.com/Finch-API/finch-api-java/commit/17bd5c172f3ef94e68846f5b18670b42560e1fce)) +* **client:** allow providing some params positionally ([ec6fa40](https://github.com/Finch-API/finch-api-java/commit/ec6fa40e9be337318708f336e853b3f9e551dd47)) +* **client:** extract auto pagination to shared classes ([c4a8874](https://github.com/Finch-API/finch-api-java/commit/c4a8874a3f7799b0d689beaafd00cf1a3727f0ea)) + ## 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) diff --git a/README.md b/README.md index 73331d8e..4ac5dff0 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/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) +[![Maven Central](https://img.shields.io/maven-central/v/com.tryfinch.api/finch-java)](https://central.sonatype.com/artifact/com.tryfinch.api/finch-java/7.0.0) +[![javadoc](https://javadoc.io/badge2/com.tryfinch.api/finch-java/7.0.0/javadoc.svg)](https://javadoc.io/doc/com.tryfinch.api/finch-java/7.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/6.0.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/7.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:6.0.0") +implementation("com.tryfinch.api:finch-java:7.0.0") ``` ### Maven @@ -35,7 +35,7 @@ implementation("com.tryfinch.api:finch-java:6.0.0") com.tryfinch.api finch-java - 6.0.0 + 7.0.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index dcfcd84d..7d01d9e2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.tryfinch.api" - version = "6.0.0" // x-release-please-version + version = "7.0.0" // x-release-please-version } subprojects {