Skip to content

Commit 9a4335c

Browse files
fix(api): add missing @MustBeClosed annotations (#65)
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 6fae9aa commit 9a4335c

Some content is hidden

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

52 files changed

+300
-321
lines changed

terminal-java-client-okhttp/src/main/kotlin/shop/terminal/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

terminal-java-core/src/main/kotlin/shop/terminal/api/services/async/AddressServiceAsyncImpl.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ internal constructor(
4848
.thenApply { response ->
4949
response
5050
.use { createHandler.handle(it) }
51-
.apply {
51+
.also {
5252
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
53-
validate()
53+
it.validate()
5454
}
5555
}
5656
}
@@ -75,9 +75,9 @@ internal constructor(
7575
.thenApply { response ->
7676
response
7777
.use { listHandler.handle(it) }
78-
.apply {
78+
.also {
7979
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
80-
validate()
80+
it.validate()
8181
}
8282
}
8383
}
@@ -103,9 +103,9 @@ internal constructor(
103103
.thenApply { response ->
104104
response
105105
.use { deleteHandler.handle(it) }
106-
.apply {
106+
.also {
107107
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
108-
validate()
108+
it.validate()
109109
}
110110
}
111111
}

terminal-java-core/src/main/kotlin/shop/terminal/api/services/async/AppServiceAsyncImpl.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ internal constructor(
5050
.thenApply { response ->
5151
response
5252
.use { createHandler.handle(it) }
53-
.apply {
53+
.also {
5454
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
55-
validate()
55+
it.validate()
5656
}
5757
}
5858
}
@@ -77,9 +77,9 @@ internal constructor(
7777
.thenApply { response ->
7878
response
7979
.use { listHandler.handle(it) }
80-
.apply {
80+
.also {
8181
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
82-
validate()
82+
it.validate()
8383
}
8484
}
8585
}
@@ -105,9 +105,9 @@ internal constructor(
105105
.thenApply { response ->
106106
response
107107
.use { deleteHandler.handle(it) }
108-
.apply {
108+
.also {
109109
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
110-
validate()
110+
it.validate()
111111
}
112112
}
113113
}
@@ -132,9 +132,9 @@ internal constructor(
132132
.thenApply { response ->
133133
response
134134
.use { getHandler.handle(it) }
135-
.apply {
135+
.also {
136136
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
137-
validate()
137+
it.validate()
138138
}
139139
}
140140
}

terminal-java-core/src/main/kotlin/shop/terminal/api/services/async/CardServiceAsyncImpl.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ internal constructor(
4848
.thenApply { response ->
4949
response
5050
.use { createHandler.handle(it) }
51-
.apply {
51+
.also {
5252
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
53-
validate()
53+
it.validate()
5454
}
5555
}
5656
}
@@ -75,9 +75,9 @@ internal constructor(
7575
.thenApply { response ->
7676
response
7777
.use { listHandler.handle(it) }
78-
.apply {
78+
.also {
7979
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
80-
validate()
80+
it.validate()
8181
}
8282
}
8383
}
@@ -103,9 +103,9 @@ internal constructor(
103103
.thenApply { response ->
104104
response
105105
.use { deleteHandler.handle(it) }
106-
.apply {
106+
.also {
107107
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
108-
validate()
108+
it.validate()
109109
}
110110
}
111111
}

terminal-java-core/src/main/kotlin/shop/terminal/api/services/async/CartServiceAsyncImpl.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ internal constructor(
5252
.thenApply { response ->
5353
response
5454
.use { convertHandler.handle(it) }
55-
.apply {
55+
.also {
5656
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
57-
validate()
57+
it.validate()
5858
}
5959
}
6060
}
@@ -79,9 +79,9 @@ internal constructor(
7979
.thenApply { response ->
8080
response
8181
.use { getHandler.handle(it) }
82-
.apply {
82+
.also {
8383
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
84-
validate()
84+
it.validate()
8585
}
8686
}
8787
}
@@ -107,9 +107,9 @@ internal constructor(
107107
.thenApply { response ->
108108
response
109109
.use { setAddressHandler.handle(it) }
110-
.apply {
110+
.also {
111111
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
112-
validate()
112+
it.validate()
113113
}
114114
}
115115
}
@@ -135,9 +135,9 @@ internal constructor(
135135
.thenApply { response ->
136136
response
137137
.use { setCardHandler.handle(it) }
138-
.apply {
138+
.also {
139139
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
140-
validate()
140+
it.validate()
141141
}
142142
}
143143
}
@@ -163,9 +163,9 @@ internal constructor(
163163
.thenApply { response ->
164164
response
165165
.use { setItemHandler.handle(it) }
166-
.apply {
166+
.also {
167167
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
168-
validate()
168+
it.validate()
169169
}
170170
}
171171
}

terminal-java-core/src/main/kotlin/shop/terminal/api/services/async/EmailServiceAsyncImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ internal constructor(
4444
.thenApply { response ->
4545
response
4646
.use { createHandler.handle(it) }
47-
.apply {
47+
.also {
4848
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
49-
validate()
49+
it.validate()
5050
}
5151
}
5252
}

terminal-java-core/src/main/kotlin/shop/terminal/api/services/async/OrderServiceAsyncImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ internal constructor(
4444
.thenApply { response ->
4545
response
4646
.use { listHandler.handle(it) }
47-
.apply {
47+
.also {
4848
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
49-
validate()
49+
it.validate()
5050
}
5151
}
5252
}
@@ -71,9 +71,9 @@ internal constructor(
7171
.thenApply { response ->
7272
response
7373
.use { getHandler.handle(it) }
74-
.apply {
74+
.also {
7575
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
76-
validate()
76+
it.validate()
7777
}
7878
}
7979
}

terminal-java-core/src/main/kotlin/shop/terminal/api/services/async/ProductServiceAsyncImpl.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 { listHandler.handle(it) }
45-
.apply {
45+
.also {
4646
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
47-
validate()
47+
it.validate()
4848
}
4949
}
5050
}

terminal-java-core/src/main/kotlin/shop/terminal/api/services/async/ProfileServiceAsyncImpl.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 { updateHandler.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 { meHandler.handle(it) }
76-
.apply {
76+
.also {
7777
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
78-
validate()
78+
it.validate()
7979
}
8080
}
8181
}

terminal-java-core/src/main/kotlin/shop/terminal/api/services/async/SubscriptionServiceAsyncImpl.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ internal constructor(
4949
.thenApply { response ->
5050
response
5151
.use { createHandler.handle(it) }
52-
.apply {
52+
.also {
5353
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
54-
validate()
54+
it.validate()
5555
}
5656
}
5757
}
@@ -77,9 +77,9 @@ internal constructor(
7777
.thenApply { response ->
7878
response
7979
.use { listHandler.handle(it) }
80-
.apply {
80+
.also {
8181
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
82-
validate()
82+
it.validate()
8383
}
8484
}
8585
}
@@ -106,9 +106,9 @@ internal constructor(
106106
.thenApply { response ->
107107
response
108108
.use { deleteHandler.handle(it) }
109-
.apply {
109+
.also {
110110
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
111-
validate()
111+
it.validate()
112112
}
113113
}
114114
}

0 commit comments

Comments
 (0)