Skip to content

Commit abe41ab

Browse files
fix(api): add missing @MustBeClosed annotations (#429)
fix(api): switch `CompletableFuture<Void>` to `CompletableFuture<Void?>` fix(client): always provide a body for `PATCH` methods fix(client): add missing validation calls on response chore(internal): minor formatting/style changes chore(internal): rename some tests
1 parent d17227d commit abe41ab

File tree

93 files changed

+517
-488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+517
-488
lines changed

finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/OkHttpClient.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
106106

107107
private fun HttpRequest.toRequest(client: okhttp3.OkHttpClient): Request {
108108
var body: RequestBody? = body?.toRequestBody()
109-
// OkHttpClient always requires a request body for PUT and POST methods.
110-
if (body == null && (method == HttpMethod.PUT || method == HttpMethod.POST)) {
109+
if (body == null && requiresBody(method)) {
111110
body = "".toRequestBody()
112111
}
113112

@@ -134,6 +133,15 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
134133
return builder.build()
135134
}
136135

136+
/** `OkHttpClient` always requires a request body for some methods. */
137+
private fun requiresBody(method: HttpMethod): Boolean =
138+
when (method) {
139+
HttpMethod.POST,
140+
HttpMethod.PUT,
141+
HttpMethod.PATCH -> true
142+
else -> false
143+
}
144+
137145
private fun HttpRequest.toUrl(): String {
138146
url?.let {
139147
return it

finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/AccessTokenServiceAsyncImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ internal constructor(
7272
.thenApply { response ->
7373
response
7474
.use { createHandler.handle(it) }
75-
.apply {
75+
.also {
7676
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
77-
validate()
77+
it.validate()
7878
}
7979
}
8080
}

finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/AccountServiceAsyncImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ internal constructor(
4646
.thenApply { response ->
4747
response
4848
.use { disconnectHandler.handle(it) }
49-
.apply {
49+
.also {
5050
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
51-
validate()
51+
it.validate()
5252
}
5353
}
5454
}
@@ -73,9 +73,9 @@ internal constructor(
7373
.thenApply { response ->
7474
response
7575
.use { introspectHandler.handle(it) }
76-
.apply {
76+
.also {
7777
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
78-
validate()
78+
it.validate()
7979
}
8080
}
8181
}

finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/ProviderServiceAsyncImpl.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@ internal constructor(
4343
.thenApply { response ->
4444
response
4545
.use { listHandler.handle(it) }
46-
.apply {
46+
.also {
4747
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
48-
forEach { it.validate() }
48+
it.forEach { it.validate() }
4949
}
5050
}
51-
.let { ProviderListPageAsync.Response.Builder().items(it).build() }
52-
.let { ProviderListPageAsync.of(this, params, it) }
51+
.let {
52+
ProviderListPageAsync.of(
53+
this,
54+
params,
55+
ProviderListPageAsync.Response.builder().items(it).build()
56+
)
57+
}
5358
}
5459
}
5560
}

finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/RequestForwardingServiceAsyncImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ internal constructor(
4949
.thenApply { response ->
5050
response
5151
.use { forwardHandler.handle(it) }
52-
.apply {
52+
.also {
5353
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
54-
validate()
54+
it.validate()
5555
}
5656
}
5757
}

finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/connect/SessionServiceAsyncImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ internal constructor(
4646
.thenApply { response ->
4747
response
4848
.use { newHandler.handle(it) }
49-
.apply {
49+
.also {
5050
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
51-
validate()
51+
it.validate()
5252
}
5353
}
5454
}
@@ -75,9 +75,9 @@ internal constructor(
7575
.thenApply { response ->
7676
response
7777
.use { reauthenticateHandler.handle(it) }
78-
.apply {
78+
.also {
7979
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
80-
validate()
80+
it.validate()
8181
}
8282
}
8383
}

finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/BenefitServiceAsyncImpl.kt

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ internal constructor(
6565
.thenApply { response ->
6666
response
6767
.use { createHandler.handle(it) }
68-
.apply {
68+
.also {
6969
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
70-
validate()
70+
it.validate()
7171
}
7272
}
7373
}
@@ -92,9 +92,9 @@ internal constructor(
9292
.thenApply { response ->
9393
response
9494
.use { retrieveHandler.handle(it) }
95-
.apply {
95+
.also {
9696
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
97-
validate()
97+
it.validate()
9898
}
9999
}
100100
}
@@ -121,9 +121,9 @@ internal constructor(
121121
.thenApply { response ->
122122
response
123123
.use { updateHandler.handle(it) }
124-
.apply {
124+
.also {
125125
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
126-
validate()
126+
it.validate()
127127
}
128128
}
129129
}
@@ -148,13 +148,18 @@ internal constructor(
148148
.thenApply { response ->
149149
response
150150
.use { listHandler.handle(it) }
151-
.apply {
151+
.also {
152152
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
153-
forEach { it.validate() }
153+
it.forEach { it.validate() }
154154
}
155155
}
156-
.let { HrisBenefitListPageAsync.Response.Builder().items(it).build() }
157-
.let { HrisBenefitListPageAsync.of(this, params, it) }
156+
.let {
157+
HrisBenefitListPageAsync.of(
158+
this,
159+
params,
160+
HrisBenefitListPageAsync.Response.builder().items(it).build()
161+
)
162+
}
158163
}
159164
}
160165

@@ -177,17 +182,20 @@ internal constructor(
177182
.thenApply { response ->
178183
response
179184
.use { listSupportedBenefitsHandler.handle(it) }
180-
.apply {
185+
.also {
181186
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
182-
forEach { it.validate() }
187+
it.forEach { it.validate() }
183188
}
184189
}
185190
.let {
186-
HrisBenefitListSupportedBenefitsPageAsync.Response.Builder()
187-
.items(it)
188-
.build()
191+
HrisBenefitListSupportedBenefitsPageAsync.of(
192+
this,
193+
params,
194+
HrisBenefitListSupportedBenefitsPageAsync.Response.builder()
195+
.items(it)
196+
.build()
197+
)
189198
}
190-
.let { HrisBenefitListSupportedBenefitsPageAsync.of(this, params, it) }
191199
}
192200
}
193201
}

finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/CompanyServiceAsyncImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ internal constructor(
4242
.thenApply { response ->
4343
response
4444
.use { retrieveHandler.handle(it) }
45-
.apply {
45+
.also {
4646
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
47-
validate()
47+
it.validate()
4848
}
4949
}
5050
}

finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DirectoryServiceAsyncImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ internal constructor(
4545
.thenApply { response ->
4646
response
4747
.use { listHandler.handle(it) }
48-
.apply {
48+
.also {
4949
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
50-
validate()
50+
it.validate()
5151
}
5252
}
5353
.let { HrisDirectoryListPageAsync.of(this, params, it) }
@@ -75,9 +75,9 @@ internal constructor(
7575
.thenApply { response ->
7676
response
7777
.use { listIndividualsHandler.handle(it) }
78-
.apply {
78+
.also {
7979
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
80-
validate()
80+
it.validate()
8181
}
8282
}
8383
.let { HrisDirectoryListIndividualsPageAsync.of(this, params, it) }

finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/hris/DocumentServiceAsyncImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ internal constructor(
4646
.thenApply { response ->
4747
response
4848
.use { listHandler.handle(it) }
49-
.apply {
49+
.also {
5050
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
51-
validate()
51+
it.validate()
5252
}
5353
}
5454
}
@@ -77,9 +77,9 @@ internal constructor(
7777
.thenApply { response ->
7878
response
7979
.use { retreiveHandler.handle(it) }
80-
.apply {
80+
.also {
8181
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
82-
validate()
82+
it.validate()
8383
}
8484
}
8585
}

0 commit comments

Comments
 (0)