Skip to content

Commit c5e90c0

Browse files
stainless-app[bot]meorphis
authored andcommitted
chore(internal): codegen related update (#71)
1 parent 2f06840 commit c5e90c0

File tree

157 files changed

+3526
-3408
lines changed

Some content is hidden

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

157 files changed

+3526
-3408
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,22 @@ get a map of untyped fields of type `Map<String, JsonValue>`. You can then acces
240240
`._additionalProperties().get("secret_prop").asString()` or use other helpers defined on the `JsonValue` class
241241
to extract it to a desired type.
242242

243+
## Logging
244+
245+
We use the standard [OkHttp logging interceptor](https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor).
246+
247+
You can enable logging by setting the environment variable `ONEBUSAWAY_SDK_LOG` to `info`.
248+
249+
```sh
250+
$ export ONEBUSAWAY_SDK_LOG=info
251+
```
252+
253+
Or to `debug` for more verbose logging.
254+
255+
```sh
256+
$ export ONEBUSAWAY_SDK_LOG=debug
257+
```
258+
243259
## Semantic versioning
244260

245261
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:

onebusaway-sdk-java-client-okhttp/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ plugins {
66
dependencies {
77
api(project(":onebusaway-sdk-java-core"))
88

9-
implementation("com.google.guava:guava:33.0.0-jre")
109
implementation("com.squareup.okhttp3:okhttp:4.12.0")
10+
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
1111

1212
testImplementation(kotlin("test"))
1313
testImplementation("org.assertj:assertj-core:3.25.3")
14-
testImplementation("org.slf4j:slf4j-simple:2.0.12")
1514
}

onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OkHttpClient.kt

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package org.onebusaway.client.okhttp
22

3-
import com.google.common.collect.ListMultimap
4-
import com.google.common.collect.MultimapBuilder
53
import java.io.IOException
64
import java.io.InputStream
75
import java.net.Proxy
86
import java.time.Duration
97
import java.util.concurrent.CompletableFuture
108
import okhttp3.Call
119
import okhttp3.Callback
12-
import okhttp3.Headers
1310
import okhttp3.HttpUrl
1411
import okhttp3.HttpUrl.Companion.toHttpUrl
1512
import okhttp3.MediaType
@@ -18,8 +15,10 @@ import okhttp3.Request
1815
import okhttp3.RequestBody
1916
import okhttp3.RequestBody.Companion.toRequestBody
2017
import okhttp3.Response
18+
import okhttp3.logging.HttpLoggingInterceptor
2119
import okio.BufferedSink
2220
import org.onebusaway.core.RequestOptions
21+
import org.onebusaway.core.http.Headers
2322
import org.onebusaway.core.http.HttpClient
2423
import org.onebusaway.core.http.HttpMethod
2524
import org.onebusaway.core.http.HttpRequest
@@ -32,14 +31,28 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
3231
HttpClient {
3332

3433
private fun getClient(requestOptions: RequestOptions): okhttp3.OkHttpClient {
35-
val timeout = requestOptions.timeout ?: return okHttpClient
36-
return okHttpClient
37-
.newBuilder()
38-
.connectTimeout(timeout)
39-
.readTimeout(timeout)
40-
.writeTimeout(timeout)
41-
.callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
42-
.build()
34+
val clientBuilder = okHttpClient.newBuilder()
35+
36+
val logLevel =
37+
when (System.getenv("ONEBUSAWAY_SDK_LOG")?.lowercase()) {
38+
"info" -> HttpLoggingInterceptor.Level.BASIC
39+
"debug" -> HttpLoggingInterceptor.Level.BODY
40+
else -> null
41+
}
42+
if (logLevel != null) {
43+
clientBuilder.addNetworkInterceptor(HttpLoggingInterceptor().setLevel(logLevel))
44+
}
45+
46+
val timeout = requestOptions.timeout
47+
if (timeout != null) {
48+
clientBuilder
49+
.connectTimeout(timeout)
50+
.readTimeout(timeout)
51+
.writeTimeout(timeout)
52+
.callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
53+
}
54+
55+
return clientBuilder.build()
4356
}
4457

4558
override fun execute(
@@ -95,7 +108,9 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
95108
}
96109

97110
val builder = Request.Builder().url(toUrl()).method(method.name, body)
98-
headers.forEach(builder::header)
111+
headers.names().forEach { name ->
112+
headers.values(name).forEach { builder.header(name, it) }
113+
}
99114

100115
return builder.build()
101116
}
@@ -107,7 +122,9 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
107122

108123
val builder = baseUrl.newBuilder()
109124
pathSegments.forEach(builder::addPathSegment)
110-
queryParams.forEach(builder::addQueryParameter)
125+
queryParams.keys().forEach { key ->
126+
queryParams.values(key).forEach { builder.addQueryParameter(key, it) }
127+
}
111128

112129
return builder.toString()
113130
}
@@ -133,21 +150,18 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
133150
return object : HttpResponse {
134151
override fun statusCode(): Int = code
135152

136-
override fun headers(): ListMultimap<String, String> = headers
153+
override fun headers(): Headers = headers
137154

138155
override fun body(): InputStream = body!!.byteStream()
139156

140157
override fun close() = body!!.close()
141158
}
142159
}
143160

144-
private fun Headers.toHeaders(): ListMultimap<String, String> {
145-
val headers =
146-
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER)
147-
.arrayListValues()
148-
.build<String, String>()
149-
forEach { pair -> headers.put(pair.first, pair.second) }
150-
return headers
161+
private fun okhttp3.Headers.toHeaders(): Headers {
162+
val headersBuilder = Headers.builder()
163+
forEach { (name, value) -> headersBuilder.put(name, value) }
164+
return headersBuilder.build()
151165
}
152166

153167
companion object {

onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClient.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import java.time.Duration
99
import org.onebusaway.client.OnebusawaySdkClient
1010
import org.onebusaway.client.OnebusawaySdkClientImpl
1111
import org.onebusaway.core.ClientOptions
12+
import org.onebusaway.core.http.Headers
13+
import org.onebusaway.core.http.QueryParams
1214

1315
class OnebusawaySdkOkHttpClient private constructor() {
1416

@@ -36,6 +38,8 @@ class OnebusawaySdkOkHttpClient private constructor() {
3638

3739
fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
3840

41+
fun headers(headers: Headers) = apply { clientOptions.headers(headers) }
42+
3943
fun headers(headers: Map<String, Iterable<String>>) = apply {
4044
clientOptions.headers(headers)
4145
}
@@ -46,6 +50,8 @@ class OnebusawaySdkOkHttpClient private constructor() {
4650
clientOptions.putHeaders(name, values)
4751
}
4852

53+
fun putAllHeaders(headers: Headers) = apply { clientOptions.putAllHeaders(headers) }
54+
4955
fun putAllHeaders(headers: Map<String, Iterable<String>>) = apply {
5056
clientOptions.putAllHeaders(headers)
5157
}
@@ -58,6 +64,8 @@ class OnebusawaySdkOkHttpClient private constructor() {
5864
clientOptions.replaceHeaders(name, values)
5965
}
6066

67+
fun replaceAllHeaders(headers: Headers) = apply { clientOptions.replaceAllHeaders(headers) }
68+
6169
fun replaceAllHeaders(headers: Map<String, Iterable<String>>) = apply {
6270
clientOptions.replaceAllHeaders(headers)
6371
}
@@ -66,6 +74,8 @@ class OnebusawaySdkOkHttpClient private constructor() {
6674

6775
fun removeAllHeaders(names: Set<String>) = apply { clientOptions.removeAllHeaders(names) }
6876

77+
fun queryParams(queryParams: QueryParams) = apply { clientOptions.queryParams(queryParams) }
78+
6979
fun queryParams(queryParams: Map<String, Iterable<String>>) = apply {
7080
clientOptions.queryParams(queryParams)
7181
}
@@ -78,6 +88,10 @@ class OnebusawaySdkOkHttpClient private constructor() {
7888
clientOptions.putQueryParams(key, values)
7989
}
8090

91+
fun putAllQueryParams(queryParams: QueryParams) = apply {
92+
clientOptions.putAllQueryParams(queryParams)
93+
}
94+
8195
fun putAllQueryParams(queryParams: Map<String, Iterable<String>>) = apply {
8296
clientOptions.putAllQueryParams(queryParams)
8397
}
@@ -90,6 +104,10 @@ class OnebusawaySdkOkHttpClient private constructor() {
90104
clientOptions.replaceQueryParams(key, values)
91105
}
92106

107+
fun replaceAllQueryParams(queryParams: QueryParams) = apply {
108+
clientOptions.replaceAllQueryParams(queryParams)
109+
}
110+
93111
fun replaceAllQueryParams(queryParams: Map<String, Iterable<String>>) = apply {
94112
clientOptions.replaceAllQueryParams(queryParams)
95113
}

onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClientAsync.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import java.time.Duration
99
import org.onebusaway.client.OnebusawaySdkClientAsync
1010
import org.onebusaway.client.OnebusawaySdkClientAsyncImpl
1111
import org.onebusaway.core.ClientOptions
12+
import org.onebusaway.core.http.Headers
13+
import org.onebusaway.core.http.QueryParams
1214

1315
class OnebusawaySdkOkHttpClientAsync private constructor() {
1416

@@ -36,6 +38,8 @@ class OnebusawaySdkOkHttpClientAsync private constructor() {
3638

3739
fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
3840

41+
fun headers(headers: Headers) = apply { clientOptions.headers(headers) }
42+
3943
fun headers(headers: Map<String, Iterable<String>>) = apply {
4044
clientOptions.headers(headers)
4145
}
@@ -46,6 +50,8 @@ class OnebusawaySdkOkHttpClientAsync private constructor() {
4650
clientOptions.putHeaders(name, values)
4751
}
4852

53+
fun putAllHeaders(headers: Headers) = apply { clientOptions.putAllHeaders(headers) }
54+
4955
fun putAllHeaders(headers: Map<String, Iterable<String>>) = apply {
5056
clientOptions.putAllHeaders(headers)
5157
}
@@ -58,6 +64,8 @@ class OnebusawaySdkOkHttpClientAsync private constructor() {
5864
clientOptions.replaceHeaders(name, values)
5965
}
6066

67+
fun replaceAllHeaders(headers: Headers) = apply { clientOptions.replaceAllHeaders(headers) }
68+
6169
fun replaceAllHeaders(headers: Map<String, Iterable<String>>) = apply {
6270
clientOptions.replaceAllHeaders(headers)
6371
}
@@ -66,6 +74,8 @@ class OnebusawaySdkOkHttpClientAsync private constructor() {
6674

6775
fun removeAllHeaders(names: Set<String>) = apply { clientOptions.removeAllHeaders(names) }
6876

77+
fun queryParams(queryParams: QueryParams) = apply { clientOptions.queryParams(queryParams) }
78+
6979
fun queryParams(queryParams: Map<String, Iterable<String>>) = apply {
7080
clientOptions.queryParams(queryParams)
7181
}
@@ -78,6 +88,10 @@ class OnebusawaySdkOkHttpClientAsync private constructor() {
7888
clientOptions.putQueryParams(key, values)
7989
}
8090

91+
fun putAllQueryParams(queryParams: QueryParams) = apply {
92+
clientOptions.putAllQueryParams(queryParams)
93+
}
94+
8195
fun putAllQueryParams(queryParams: Map<String, Iterable<String>>) = apply {
8296
clientOptions.putAllQueryParams(queryParams)
8397
}
@@ -90,6 +104,10 @@ class OnebusawaySdkOkHttpClientAsync private constructor() {
90104
clientOptions.replaceQueryParams(key, values)
91105
}
92106

107+
fun replaceAllQueryParams(queryParams: QueryParams) = apply {
108+
clientOptions.replaceAllQueryParams(queryParams)
109+
}
110+
93111
fun replaceAllQueryParams(queryParams: Map<String, Iterable<String>>) = apply {
94112
clientOptions.replaceAllQueryParams(queryParams)
95113
}

onebusaway-sdk-java-core/build.gradle.kts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ plugins {
44
}
55

66
dependencies {
7-
api("com.fasterxml.jackson.core:jackson-core:2.14.3")
8-
api("com.fasterxml.jackson.core:jackson-databind:2.14.3")
9-
api("com.google.guava:guava:33.0.0-jre")
7+
api("com.fasterxml.jackson.core:jackson-core:2.18.1")
8+
api("com.fasterxml.jackson.core:jackson-databind:2.18.1")
109

11-
implementation("com.fasterxml.jackson.core:jackson-annotations:2.14.3")
12-
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.14.3")
13-
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.3")
14-
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.3")
10+
implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.1")
11+
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.1")
12+
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.1")
13+
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.1")
1514
implementation("org.apache.httpcomponents.core5:httpcore5:5.2.4")
1615
implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1")
1716

1817
testImplementation(kotlin("test"))
1918
testImplementation(project(":onebusaway-sdk-java-client-okhttp"))
2019
testImplementation("com.github.tomakehurst:wiremock-jre8:2.35.2")
2120
testImplementation("org.assertj:assertj-core:3.25.3")
22-
testImplementation("org.assertj:assertj-guava:3.25.3")
23-
testImplementation("org.slf4j:slf4j-simple:2.0.12")
2421
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
2522
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.3")
23+
testImplementation("org.mockito:mockito-core:5.14.2")
24+
testImplementation("org.mockito:mockito-junit-jupiter:5.14.2")
25+
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
2626
}

onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientAsyncImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ constructor(
1313
) : OnebusawaySdkClientAsync {
1414

1515
private val clientOptionsWithUserAgent =
16-
if (clientOptions.headers.containsKey("User-Agent")) clientOptions
16+
if (clientOptions.headers.names().contains("User-Agent")) clientOptions
1717
else
1818
clientOptions
1919
.toBuilder()

onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ constructor(
1313
) : OnebusawaySdkClient {
1414

1515
private val clientOptionsWithUserAgent =
16-
if (clientOptions.headers.containsKey("User-Agent")) clientOptions
16+
if (clientOptions.headers.names().contains("User-Agent")) clientOptions
1717
else
1818
clientOptions
1919
.toBuilder()

0 commit comments

Comments
 (0)