Skip to content

Commit 8cdf256

Browse files
feat(api): api update
1 parent 5982e36 commit 8cdf256

File tree

4 files changed

+172
-13
lines changed

4 files changed

+172
-13
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 45
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-e33325fb830bdd979e9067a492968e5318a5b520572308a5331acb91274735ac.yml
3-
openapi_spec_hash: 0b203de65d7fd1c68f2d81f02849a803
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-05a1c7485ea6dd75ad2fb1a0628570d88a3e7c4f1e1ecad433711c78deae50e6.yml
3+
openapi_spec_hash: 6d6014d50e18c98219b496bb2a5dab1d
44
config_hash: 53778a0b839c4f6ad34fbba051f5e8a6

finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayStatementItemListResponse.kt

Lines changed: 140 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.tryfinch.api.core.ExcludeMissing
1111
import com.tryfinch.api.core.JsonField
1212
import com.tryfinch.api.core.JsonMissing
1313
import com.tryfinch.api.core.JsonValue
14+
import com.tryfinch.api.core.toImmutable
1415
import com.tryfinch.api.errors.FinchInvalidDataException
1516
import java.util.Collections
1617
import java.util.Objects
@@ -221,7 +222,7 @@ private constructor(
221222
class Attributes
222223
private constructor(
223224
private val employer: JsonField<Boolean>,
224-
private val metadata: JsonValue,
225+
private val metadata: JsonField<Metadata>,
225226
private val preTax: JsonField<Boolean>,
226227
private val type: JsonField<String>,
227228
private val additionalProperties: MutableMap<String, JsonValue>,
@@ -232,7 +233,9 @@ private constructor(
232233
@JsonProperty("employer")
233234
@ExcludeMissing
234235
employer: JsonField<Boolean> = JsonMissing.of(),
235-
@JsonProperty("metadata") @ExcludeMissing metadata: JsonValue = JsonMissing.of(),
236+
@JsonProperty("metadata")
237+
@ExcludeMissing
238+
metadata: JsonField<Metadata> = JsonMissing.of(),
236239
@JsonProperty("pre_tax") @ExcludeMissing preTax: JsonField<Boolean> = JsonMissing.of(),
237240
@JsonProperty("type") @ExcludeMissing type: JsonField<String> = JsonMissing.of(),
238241
) : this(employer, metadata, preTax, type, mutableMapOf())
@@ -248,8 +251,11 @@ private constructor(
248251
/**
249252
* The metadata of the pay statement item derived by the rules engine if available. Each
250253
* attribute will be a key-value pair defined by a rule.
254+
*
255+
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
256+
* server responded with an unexpected value).
251257
*/
252-
@JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonValue = metadata
258+
fun metadata(): Optional<Metadata> = metadata.getOptional("metadata")
253259

254260
/**
255261
* `true` if the pay statement item is pre-tax. This field is only available for employee
@@ -275,6 +281,13 @@ private constructor(
275281
*/
276282
@JsonProperty("employer") @ExcludeMissing fun _employer(): JsonField<Boolean> = employer
277283

284+
/**
285+
* Returns the raw JSON value of [metadata].
286+
*
287+
* Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type.
288+
*/
289+
@JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField<Metadata> = metadata
290+
278291
/**
279292
* Returns the raw JSON value of [preTax].
280293
*
@@ -311,7 +324,7 @@ private constructor(
311324
class Builder internal constructor() {
312325

313326
private var employer: JsonField<Boolean> = JsonMissing.of()
314-
private var metadata: JsonValue = JsonMissing.of()
327+
private var metadata: JsonField<Metadata> = JsonMissing.of()
315328
private var preTax: JsonField<Boolean> = JsonMissing.of()
316329
private var type: JsonField<String> = JsonMissing.of()
317330
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
@@ -354,7 +367,19 @@ private constructor(
354367
* The metadata of the pay statement item derived by the rules engine if available. Each
355368
* attribute will be a key-value pair defined by a rule.
356369
*/
357-
fun metadata(metadata: JsonValue) = apply { this.metadata = metadata }
370+
fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata))
371+
372+
/** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */
373+
fun metadata(metadata: Optional<Metadata>) = metadata(metadata.getOrNull())
374+
375+
/**
376+
* Sets [Builder.metadata] to an arbitrary JSON value.
377+
*
378+
* You should usually call [Builder.metadata] with a well-typed [Metadata] value
379+
* instead. This method is primarily for setting the field to an undocumented or not yet
380+
* supported value.
381+
*/
382+
fun metadata(metadata: JsonField<Metadata>) = apply { this.metadata = metadata }
358383

359384
/**
360385
* `true` if the pay statement item is pre-tax. This field is only available for
@@ -432,6 +457,7 @@ private constructor(
432457
}
433458

434459
employer()
460+
metadata().ifPresent { it.validate() }
435461
preTax()
436462
type()
437463
validated = true
@@ -454,9 +480,118 @@ private constructor(
454480
@JvmSynthetic
455481
internal fun validity(): Int =
456482
(if (employer.asKnown().isPresent) 1 else 0) +
483+
(metadata.asKnown().getOrNull()?.validity() ?: 0) +
457484
(if (preTax.asKnown().isPresent) 1 else 0) +
458485
(if (type.asKnown().isPresent) 1 else 0)
459486

487+
/**
488+
* The metadata of the pay statement item derived by the rules engine if available. Each
489+
* attribute will be a key-value pair defined by a rule.
490+
*/
491+
class Metadata
492+
@JsonCreator
493+
private constructor(
494+
@com.fasterxml.jackson.annotation.JsonValue
495+
private val additionalProperties: Map<String, JsonValue>
496+
) {
497+
498+
@JsonAnyGetter
499+
@ExcludeMissing
500+
fun _additionalProperties(): Map<String, JsonValue> = additionalProperties
501+
502+
fun toBuilder() = Builder().from(this)
503+
504+
companion object {
505+
506+
/** Returns a mutable builder for constructing an instance of [Metadata]. */
507+
@JvmStatic fun builder() = Builder()
508+
}
509+
510+
/** A builder for [Metadata]. */
511+
class Builder internal constructor() {
512+
513+
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
514+
515+
@JvmSynthetic
516+
internal fun from(metadata: Metadata) = apply {
517+
additionalProperties = metadata.additionalProperties.toMutableMap()
518+
}
519+
520+
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
521+
this.additionalProperties.clear()
522+
putAllAdditionalProperties(additionalProperties)
523+
}
524+
525+
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
526+
additionalProperties.put(key, value)
527+
}
528+
529+
fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
530+
apply {
531+
this.additionalProperties.putAll(additionalProperties)
532+
}
533+
534+
fun removeAdditionalProperty(key: String) = apply {
535+
additionalProperties.remove(key)
536+
}
537+
538+
fun removeAllAdditionalProperties(keys: Set<String>) = apply {
539+
keys.forEach(::removeAdditionalProperty)
540+
}
541+
542+
/**
543+
* Returns an immutable instance of [Metadata].
544+
*
545+
* Further updates to this [Builder] will not mutate the returned instance.
546+
*/
547+
fun build(): Metadata = Metadata(additionalProperties.toImmutable())
548+
}
549+
550+
private var validated: Boolean = false
551+
552+
fun validate(): Metadata = apply {
553+
if (validated) {
554+
return@apply
555+
}
556+
557+
validated = true
558+
}
559+
560+
fun isValid(): Boolean =
561+
try {
562+
validate()
563+
true
564+
} catch (e: FinchInvalidDataException) {
565+
false
566+
}
567+
568+
/**
569+
* Returns a score indicating how many valid values are contained in this object
570+
* recursively.
571+
*
572+
* Used for best match union deserialization.
573+
*/
574+
@JvmSynthetic
575+
internal fun validity(): Int =
576+
additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() }
577+
578+
override fun equals(other: Any?): Boolean {
579+
if (this === other) {
580+
return true
581+
}
582+
583+
return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */
584+
}
585+
586+
/* spotless:off */
587+
private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
588+
/* spotless:on */
589+
590+
override fun hashCode(): Int = hashCode
591+
592+
override fun toString() = "Metadata{additionalProperties=$additionalProperties}"
593+
}
594+
460595
override fun equals(other: Any?): Boolean {
461596
if (this === other) {
462597
return true

finch-java-core/src/test/kotlin/com/tryfinch/api/models/HrisCompanyPayStatementItemListPageResponseTest.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ internal class HrisCompanyPayStatementItemListPageResponseTest {
1919
.attributes(
2020
PayStatementItemListResponse.Attributes.builder()
2121
.employer(true)
22-
.metadata(JsonValue.from(mapOf<String, Any>()))
22+
.metadata(
23+
PayStatementItemListResponse.Attributes.Metadata.builder()
24+
.putAdditionalProperty("foo", JsonValue.from("bar"))
25+
.build()
26+
)
2327
.preTax(true)
2428
.type("type")
2529
.build()
@@ -36,7 +40,11 @@ internal class HrisCompanyPayStatementItemListPageResponseTest {
3640
.attributes(
3741
PayStatementItemListResponse.Attributes.builder()
3842
.employer(true)
39-
.metadata(JsonValue.from(mapOf<String, Any>()))
43+
.metadata(
44+
PayStatementItemListResponse.Attributes.Metadata.builder()
45+
.putAdditionalProperty("foo", JsonValue.from("bar"))
46+
.build()
47+
)
4048
.preTax(true)
4149
.type("type")
4250
.build()
@@ -57,7 +65,11 @@ internal class HrisCompanyPayStatementItemListPageResponseTest {
5765
.attributes(
5866
PayStatementItemListResponse.Attributes.builder()
5967
.employer(true)
60-
.metadata(JsonValue.from(mapOf<String, Any>()))
68+
.metadata(
69+
PayStatementItemListResponse.Attributes.Metadata.builder()
70+
.putAdditionalProperty("foo", JsonValue.from("bar"))
71+
.build()
72+
)
6173
.preTax(true)
6274
.type("type")
6375
.build()

finch-java-core/src/test/kotlin/com/tryfinch/api/models/PayStatementItemListResponseTest.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ internal class PayStatementItemListResponseTest {
1717
.attributes(
1818
PayStatementItemListResponse.Attributes.builder()
1919
.employer(true)
20-
.metadata(JsonValue.from(mapOf<String, Any>()))
20+
.metadata(
21+
PayStatementItemListResponse.Attributes.Metadata.builder()
22+
.putAdditionalProperty("foo", JsonValue.from("bar"))
23+
.build()
24+
)
2125
.preTax(true)
2226
.type("type")
2327
.build()
@@ -30,7 +34,11 @@ internal class PayStatementItemListResponseTest {
3034
.contains(
3135
PayStatementItemListResponse.Attributes.builder()
3236
.employer(true)
33-
.metadata(JsonValue.from(mapOf<String, Any>()))
37+
.metadata(
38+
PayStatementItemListResponse.Attributes.Metadata.builder()
39+
.putAdditionalProperty("foo", JsonValue.from("bar"))
40+
.build()
41+
)
3442
.preTax(true)
3543
.type("type")
3644
.build()
@@ -48,7 +56,11 @@ internal class PayStatementItemListResponseTest {
4856
.attributes(
4957
PayStatementItemListResponse.Attributes.builder()
5058
.employer(true)
51-
.metadata(JsonValue.from(mapOf<String, Any>()))
59+
.metadata(
60+
PayStatementItemListResponse.Attributes.Metadata.builder()
61+
.putAdditionalProperty("foo", JsonValue.from("bar"))
62+
.build()
63+
)
5264
.preTax(true)
5365
.type("type")
5466
.build()

0 commit comments

Comments
 (0)