diff --git a/openlayer-java-client-okhttp/build.gradle.kts b/openlayer-java-client-okhttp/build.gradle.kts index 2788dd9..a295ce5 100644 --- a/openlayer-java-client-okhttp/build.gradle.kts +++ b/openlayer-java-client-okhttp/build.gradle.kts @@ -6,7 +6,6 @@ plugins { dependencies { api(project(":openlayer-java-core")) - implementation("com.google.guava:guava:33.0.0-jre") implementation("com.squareup.okhttp3:okhttp:4.12.0") testImplementation(kotlin("test")) diff --git a/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OkHttpClient.kt b/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OkHttpClient.kt index 4922400..f7db194 100644 --- a/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OkHttpClient.kt +++ b/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OkHttpClient.kt @@ -1,8 +1,7 @@ package com.openlayer.api.client.okhttp -import com.google.common.collect.ListMultimap -import com.google.common.collect.MultimapBuilder import com.openlayer.api.core.RequestOptions +import com.openlayer.api.core.http.Headers import com.openlayer.api.core.http.HttpClient import com.openlayer.api.core.http.HttpMethod import com.openlayer.api.core.http.HttpRequest @@ -16,7 +15,6 @@ import java.time.Duration import java.util.concurrent.CompletableFuture import okhttp3.Call import okhttp3.Callback -import okhttp3.Headers import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.MediaType @@ -95,7 +93,9 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val } val builder = Request.Builder().url(toUrl()).method(method.name, body) - headers.forEach(builder::header) + headers.names().forEach { name -> + headers.values(name).forEach { builder.header(name, it) } + } return builder.build() } @@ -107,7 +107,9 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val val builder = baseUrl.newBuilder() pathSegments.forEach(builder::addPathSegment) - queryParams.forEach(builder::addQueryParameter) + queryParams.keys().forEach { key -> + queryParams.values(key).forEach { builder.addQueryParameter(key, it) } + } return builder.toString() } @@ -133,7 +135,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val return object : HttpResponse { override fun statusCode(): Int = code - override fun headers(): ListMultimap = headers + override fun headers(): Headers = headers override fun body(): InputStream = body!!.byteStream() @@ -141,13 +143,10 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val } } - private fun Headers.toHeaders(): ListMultimap { - val headers = - MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER) - .arrayListValues() - .build() - forEach { pair -> headers.put(pair.first, pair.second) } - return headers + private fun okhttp3.Headers.toHeaders(): Headers { + val headersBuilder = Headers.builder() + forEach { (name, value) -> headersBuilder.put(name, value) } + return headersBuilder.build() } companion object { diff --git a/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OpenlayerOkHttpClient.kt b/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OpenlayerOkHttpClient.kt index ca008cf..6369d21 100644 --- a/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OpenlayerOkHttpClient.kt +++ b/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OpenlayerOkHttpClient.kt @@ -6,6 +6,8 @@ import com.fasterxml.jackson.databind.json.JsonMapper import com.openlayer.api.client.OpenlayerClient import com.openlayer.api.client.OpenlayerClientImpl import com.openlayer.api.core.ClientOptions +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import java.net.Proxy import java.time.Clock import java.time.Duration @@ -36,6 +38,8 @@ class OpenlayerOkHttpClient private constructor() { fun clock(clock: Clock) = apply { clientOptions.clock(clock) } + fun headers(headers: Headers) = apply { clientOptions.headers(headers) } + fun headers(headers: Map>) = apply { clientOptions.headers(headers) } @@ -46,11 +50,73 @@ class OpenlayerOkHttpClient private constructor() { clientOptions.putHeaders(name, values) } + fun putAllHeaders(headers: Headers) = apply { clientOptions.putAllHeaders(headers) } + fun putAllHeaders(headers: Map>) = apply { clientOptions.putAllHeaders(headers) } - fun removeHeader(name: String) = apply { clientOptions.removeHeader(name) } + fun replaceHeaders(name: String, value: String) = apply { + clientOptions.replaceHeaders(name, value) + } + + fun replaceHeaders(name: String, values: Iterable) = apply { + clientOptions.replaceHeaders(name, values) + } + + fun replaceAllHeaders(headers: Headers) = apply { clientOptions.replaceAllHeaders(headers) } + + fun replaceAllHeaders(headers: Map>) = apply { + clientOptions.replaceAllHeaders(headers) + } + + fun removeHeaders(name: String) = apply { clientOptions.removeHeaders(name) } + + fun removeAllHeaders(names: Set) = apply { clientOptions.removeAllHeaders(names) } + + fun queryParams(queryParams: QueryParams) = apply { clientOptions.queryParams(queryParams) } + + fun queryParams(queryParams: Map>) = apply { + clientOptions.queryParams(queryParams) + } + + fun putQueryParam(key: String, value: String) = apply { + clientOptions.putQueryParam(key, value) + } + + fun putQueryParams(key: String, values: Iterable) = apply { + clientOptions.putQueryParams(key, values) + } + + fun putAllQueryParams(queryParams: QueryParams) = apply { + clientOptions.putAllQueryParams(queryParams) + } + + fun putAllQueryParams(queryParams: Map>) = apply { + clientOptions.putAllQueryParams(queryParams) + } + + fun replaceQueryParams(key: String, value: String) = apply { + clientOptions.replaceQueryParams(key, value) + } + + fun replaceQueryParams(key: String, values: Iterable) = apply { + clientOptions.replaceQueryParams(key, values) + } + + fun replaceAllQueryParams(queryParams: QueryParams) = apply { + clientOptions.replaceAllQueryParams(queryParams) + } + + fun replaceAllQueryParams(queryParams: Map>) = apply { + clientOptions.replaceAllQueryParams(queryParams) + } + + fun removeQueryParams(key: String) = apply { clientOptions.removeQueryParams(key) } + + fun removeAllQueryParams(keys: Set) = apply { + clientOptions.removeAllQueryParams(keys) + } fun timeout(timeout: Duration) = apply { this.timeout = timeout } diff --git a/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OpenlayerOkHttpClientAsync.kt b/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OpenlayerOkHttpClientAsync.kt index 7cce64f..3bd8ace 100644 --- a/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OpenlayerOkHttpClientAsync.kt +++ b/openlayer-java-client-okhttp/src/main/kotlin/com/openlayer/api/client/okhttp/OpenlayerOkHttpClientAsync.kt @@ -6,6 +6,8 @@ import com.fasterxml.jackson.databind.json.JsonMapper import com.openlayer.api.client.OpenlayerClientAsync import com.openlayer.api.client.OpenlayerClientAsyncImpl import com.openlayer.api.core.ClientOptions +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import java.net.Proxy import java.time.Clock import java.time.Duration @@ -36,6 +38,8 @@ class OpenlayerOkHttpClientAsync private constructor() { fun clock(clock: Clock) = apply { clientOptions.clock(clock) } + fun headers(headers: Headers) = apply { clientOptions.headers(headers) } + fun headers(headers: Map>) = apply { clientOptions.headers(headers) } @@ -46,11 +50,73 @@ class OpenlayerOkHttpClientAsync private constructor() { clientOptions.putHeaders(name, values) } + fun putAllHeaders(headers: Headers) = apply { clientOptions.putAllHeaders(headers) } + fun putAllHeaders(headers: Map>) = apply { clientOptions.putAllHeaders(headers) } - fun removeHeader(name: String) = apply { clientOptions.removeHeader(name) } + fun replaceHeaders(name: String, value: String) = apply { + clientOptions.replaceHeaders(name, value) + } + + fun replaceHeaders(name: String, values: Iterable) = apply { + clientOptions.replaceHeaders(name, values) + } + + fun replaceAllHeaders(headers: Headers) = apply { clientOptions.replaceAllHeaders(headers) } + + fun replaceAllHeaders(headers: Map>) = apply { + clientOptions.replaceAllHeaders(headers) + } + + fun removeHeaders(name: String) = apply { clientOptions.removeHeaders(name) } + + fun removeAllHeaders(names: Set) = apply { clientOptions.removeAllHeaders(names) } + + fun queryParams(queryParams: QueryParams) = apply { clientOptions.queryParams(queryParams) } + + fun queryParams(queryParams: Map>) = apply { + clientOptions.queryParams(queryParams) + } + + fun putQueryParam(key: String, value: String) = apply { + clientOptions.putQueryParam(key, value) + } + + fun putQueryParams(key: String, values: Iterable) = apply { + clientOptions.putQueryParams(key, values) + } + + fun putAllQueryParams(queryParams: QueryParams) = apply { + clientOptions.putAllQueryParams(queryParams) + } + + fun putAllQueryParams(queryParams: Map>) = apply { + clientOptions.putAllQueryParams(queryParams) + } + + fun replaceQueryParams(key: String, value: String) = apply { + clientOptions.replaceQueryParams(key, value) + } + + fun replaceQueryParams(key: String, values: Iterable) = apply { + clientOptions.replaceQueryParams(key, values) + } + + fun replaceAllQueryParams(queryParams: QueryParams) = apply { + clientOptions.replaceAllQueryParams(queryParams) + } + + fun replaceAllQueryParams(queryParams: Map>) = apply { + clientOptions.replaceAllQueryParams(queryParams) + } + + fun removeQueryParams(key: String) = apply { clientOptions.removeQueryParams(key) } + + fun removeAllQueryParams(keys: Set) = apply { + clientOptions.removeAllQueryParams(keys) + } fun timeout(timeout: Duration) = apply { this.timeout = timeout } diff --git a/openlayer-java-core/build.gradle.kts b/openlayer-java-core/build.gradle.kts index 20066b7..1c5b4ba 100644 --- a/openlayer-java-core/build.gradle.kts +++ b/openlayer-java-core/build.gradle.kts @@ -6,7 +6,6 @@ plugins { dependencies { api("com.fasterxml.jackson.core:jackson-core:2.14.3") api("com.fasterxml.jackson.core:jackson-databind:2.14.3") - api("com.google.guava:guava:33.0.0-jre") implementation("com.fasterxml.jackson.core:jackson-annotations:2.14.3") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.14.3") diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/client/OpenlayerClientAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/client/OpenlayerClientAsyncImpl.kt index 5a08ebf..869906f 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/client/OpenlayerClientAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/client/OpenlayerClientAsyncImpl.kt @@ -13,7 +13,7 @@ constructor( ) : OpenlayerClientAsync { private val clientOptionsWithUserAgent = - if (clientOptions.headers.containsKey("User-Agent")) clientOptions + if (clientOptions.headers.names().contains("User-Agent")) clientOptions else clientOptions .toBuilder() diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/client/OpenlayerClientImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/client/OpenlayerClientImpl.kt index b805ba6..47335ac 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/client/OpenlayerClientImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/client/OpenlayerClientImpl.kt @@ -13,7 +13,7 @@ constructor( ) : OpenlayerClient { private val clientOptionsWithUserAgent = - if (clientOptions.headers.containsKey("User-Agent")) clientOptions + if (clientOptions.headers.names().contains("User-Agent")) clientOptions else clientOptions .toBuilder() diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/ClientOptions.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/ClientOptions.kt index 9af25ea..9dbd51c 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/ClientOptions.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/ClientOptions.kt @@ -3,10 +3,10 @@ package com.openlayer.api.core import com.fasterxml.jackson.databind.json.JsonMapper -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap +import com.openlayer.api.core.http.Headers import com.openlayer.api.core.http.HttpClient import com.openlayer.api.core.http.PhantomReachableClosingHttpClient +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.core.http.RetryingHttpClient import java.time.Clock @@ -17,11 +17,11 @@ private constructor( @get:JvmName("jsonMapper") val jsonMapper: JsonMapper, @get:JvmName("clock") val clock: Clock, @get:JvmName("baseUrl") val baseUrl: String, - @get:JvmName("apiKey") val apiKey: String?, - @get:JvmName("headers") val headers: ListMultimap, - @get:JvmName("queryParams") val queryParams: ListMultimap, + @get:JvmName("headers") val headers: Headers, + @get:JvmName("queryParams") val queryParams: QueryParams, @get:JvmName("responseValidation") val responseValidation: Boolean, @get:JvmName("maxRetries") val maxRetries: Int, + @get:JvmName("apiKey") val apiKey: String?, ) { fun toBuilder() = Builder().from(this) @@ -38,11 +38,11 @@ private constructor( class Builder { private var httpClient: HttpClient? = null - private var jsonMapper: JsonMapper? = null + private var jsonMapper: JsonMapper = jsonMapper() private var clock: Clock = Clock.systemUTC() private var baseUrl: String = PRODUCTION_URL - private var headers: MutableMap> = mutableMapOf() - private var queryParams: MutableMap> = mutableMapOf() + private var headers: Headers.Builder = Headers.builder() + private var queryParams: QueryParams.Builder = QueryParams.builder() private var responseValidation: Boolean = false private var maxRetries: Int = 2 private var apiKey: String? = null @@ -53,14 +53,8 @@ private constructor( jsonMapper = clientOptions.jsonMapper clock = clientOptions.clock baseUrl = clientOptions.baseUrl - headers = - clientOptions.headers.asMap().mapValuesTo(mutableMapOf()) { (_, value) -> - value.toMutableList() - } - queryParams = - clientOptions.queryParams.asMap().mapValuesTo(mutableMapOf()) { (_, value) -> - value.toMutableList() - } + headers = clientOptions.headers.toBuilder() + queryParams = clientOptions.queryParams.toBuilder() responseValidation = clientOptions.responseValidation maxRetries = clientOptions.maxRetries apiKey = clientOptions.apiKey @@ -70,47 +64,89 @@ private constructor( fun jsonMapper(jsonMapper: JsonMapper) = apply { this.jsonMapper = jsonMapper } + fun clock(clock: Clock) = apply { this.clock = clock } + fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl } - fun clock(clock: Clock) = apply { this.clock = clock } + fun headers(headers: Headers) = apply { + this.headers.clear() + putAllHeaders(headers) + } fun headers(headers: Map>) = apply { this.headers.clear() putAllHeaders(headers) } - fun putHeader(name: String, value: String) = apply { - this.headers.getOrPut(name) { mutableListOf() }.add(value) + fun putHeader(name: String, value: String) = apply { headers.put(name, value) } + + fun putHeaders(name: String, values: Iterable) = apply { headers.put(name, values) } + + fun putAllHeaders(headers: Headers) = apply { this.headers.putAll(headers) } + + fun putAllHeaders(headers: Map>) = apply { + this.headers.putAll(headers) } - fun putHeaders(name: String, values: Iterable) = apply { - this.headers.getOrPut(name) { mutableListOf() }.addAll(values) + fun replaceHeaders(name: String, value: String) = apply { headers.replace(name, value) } + + fun replaceHeaders(name: String, values: Iterable) = apply { + headers.replace(name, values) } - fun putAllHeaders(headers: Map>) = apply { - headers.forEach(this::putHeaders) + fun replaceAllHeaders(headers: Headers) = apply { this.headers.replaceAll(headers) } + + fun replaceAllHeaders(headers: Map>) = apply { + this.headers.replaceAll(headers) } - fun removeHeader(name: String) = apply { this.headers.put(name, mutableListOf()) } + fun removeHeaders(name: String) = apply { headers.remove(name) } + + fun removeAllHeaders(names: Set) = apply { headers.removeAll(names) } + + fun queryParams(queryParams: QueryParams) = apply { + this.queryParams.clear() + putAllQueryParams(queryParams) + } fun queryParams(queryParams: Map>) = apply { this.queryParams.clear() putAllQueryParams(queryParams) } - fun putQueryParam(name: String, value: String) = apply { - this.queryParams.getOrPut(name) { mutableListOf() }.add(value) + fun putQueryParam(key: String, value: String) = apply { queryParams.put(key, value) } + + fun putQueryParams(key: String, values: Iterable) = apply { + queryParams.put(key, values) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.queryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAllQueryParams(queryParams: QueryParams) = apply { + this.queryParams.putAll(queryParams) } fun putAllQueryParams(queryParams: Map>) = apply { - queryParams.forEach(this::putQueryParams) + this.queryParams.putAll(queryParams) } - fun removeQueryParam(name: String) = apply { this.queryParams.put(name, mutableListOf()) } + fun replaceQueryParams(key: String, value: String) = apply { + queryParams.replace(key, value) + } + + fun replaceQueryParams(key: String, values: Iterable) = apply { + queryParams.replace(key, values) + } + + fun replaceAllQueryParams(queryParams: QueryParams) = apply { + this.queryParams.replaceAll(queryParams) + } + + fun replaceAllQueryParams(queryParams: Map>) = apply { + this.queryParams.replaceAll(queryParams) + } + + fun removeQueryParams(key: String) = apply { queryParams.remove(key) } + + fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) } fun responseValidation(responseValidation: Boolean) = apply { this.responseValidation = responseValidation @@ -125,8 +161,8 @@ private constructor( fun build(): ClientOptions { checkNotNull(httpClient) { "`httpClient` is required but was not set" } - val headers = ArrayListMultimap.create() - val queryParams = ArrayListMultimap.create() + val headers = Headers.builder() + val queryParams = QueryParams.builder() headers.put("X-Stainless-Lang", "java") headers.put("X-Stainless-Arch", getOsArch()) headers.put("X-Stainless-OS", getOsName()) @@ -134,11 +170,13 @@ private constructor( headers.put("X-Stainless-Package-Version", getPackageVersion()) headers.put("X-Stainless-Runtime", "JRE") headers.put("X-Stainless-Runtime-Version", getJavaVersion()) - if (!apiKey.isNullOrEmpty()) { - headers.put("Authorization", "Bearer ${apiKey}") + apiKey?.let { + if (!it.isEmpty()) { + headers.put("Authorization", "Bearer $it") + } } - this.headers.forEach(headers::replaceValues) - this.queryParams.forEach(queryParams::replaceValues) + headers.replaceAll(this.headers.build()) + queryParams.replaceAll(this.queryParams.build()) return ClientOptions( httpClient!!, @@ -149,14 +187,14 @@ private constructor( .maxRetries(maxRetries) .build() ), - jsonMapper ?: jsonMapper(), + jsonMapper, clock, baseUrl, - apiKey, - headers.toImmutable(), - queryParams.toImmutable(), + headers.build(), + queryParams.build(), responseValidation, maxRetries, + apiKey, ) } } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/Utils.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/Utils.kt index 535cb02..7c5ab9d 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/Utils.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/Utils.kt @@ -2,10 +2,9 @@ package com.openlayer.api.core -import com.google.common.collect.ImmutableListMultimap -import com.google.common.collect.ListMultimap import com.openlayer.api.errors.OpenlayerInvalidDataException import java.util.Collections +import java.util.SortedMap @JvmSynthetic internal fun T?.getOrThrow(name: String): T = @@ -20,7 +19,8 @@ internal fun Map.toImmutable(): Map = if (isEmpty()) Collections.emptyMap() else Collections.unmodifiableMap(toMap()) @JvmSynthetic -internal fun ListMultimap.toImmutable(): ListMultimap = - ImmutableListMultimap.copyOf(this) +internal fun , V> SortedMap.toImmutable(): SortedMap = + if (isEmpty()) Collections.emptySortedMap() + else Collections.unmodifiableSortedMap(toSortedMap(comparator())) internal interface Enum diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/handlers/ErrorHandler.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/handlers/ErrorHandler.kt index 69326c1..5e44208 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/handlers/ErrorHandler.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/handlers/ErrorHandler.kt @@ -3,7 +3,7 @@ package com.openlayer.api.core.handlers import com.fasterxml.jackson.databind.json.JsonMapper -import com.google.common.collect.ListMultimap +import com.openlayer.api.core.http.Headers import com.openlayer.api.core.http.HttpResponse import com.openlayer.api.core.http.HttpResponse.Handler import com.openlayer.api.errors.BadRequestException @@ -116,7 +116,7 @@ private fun HttpResponse.buffered(): HttpResponse { return object : HttpResponse { override fun statusCode(): Int = this@buffered.statusCode() - override fun headers(): ListMultimap = this@buffered.headers() + override fun headers(): Headers = this@buffered.headers() override fun body(): InputStream = ByteArrayInputStream(body) diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/Headers.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/Headers.kt new file mode 100644 index 0000000..8b934c1 --- /dev/null +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/Headers.kt @@ -0,0 +1,92 @@ +package com.openlayer.api.core.http + +import com.openlayer.api.core.toImmutable +import java.util.TreeMap + +class Headers +private constructor( + private val map: Map>, + @get:JvmName("size") val size: Int +) { + + fun isEmpty(): Boolean = map.isEmpty() + + fun names(): Set = map.keys + + fun values(name: String): List = map[name].orEmpty() + + fun toBuilder(): Builder = Builder().putAll(map) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private val map: MutableMap> = + TreeMap(String.CASE_INSENSITIVE_ORDER) + private var size: Int = 0 + + fun put(name: String, value: String) = apply { + map.getOrPut(name) { mutableListOf() }.add(value) + size++ + } + + fun put(name: String, values: Iterable) = apply { values.forEach { put(name, it) } } + + fun putAll(headers: Map>) = apply { headers.forEach(::put) } + + fun putAll(headers: Headers) = apply { + headers.names().forEach { put(it, headers.values(it)) } + } + + fun remove(name: String) = apply { size -= map.remove(name).orEmpty().size } + + fun removeAll(names: Set) = apply { names.forEach(::remove) } + + fun clear() = apply { + map.clear() + size = 0 + } + + fun replace(name: String, value: String) = apply { + remove(name) + put(name, value) + } + + fun replace(name: String, values: Iterable) = apply { + remove(name) + put(name, values) + } + + fun replaceAll(headers: Map>) = apply { + headers.forEach(::replace) + } + + fun replaceAll(headers: Headers) = apply { + headers.names().forEach { replace(it, headers.values(it)) } + } + + fun build() = + Headers( + map.mapValuesTo(TreeMap(String.CASE_INSENSITIVE_ORDER)) { (_, values) -> + values.toImmutable() + } + .toImmutable(), + size + ) + } + + override fun hashCode(): Int = map.hashCode() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Headers && map == other.map + } + + override fun toString(): String = "Headers{map=$map}" +} diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpRequest.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpRequest.kt index dbb6e3e..1acfcbc 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpRequest.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpRequest.kt @@ -1,9 +1,5 @@ package com.openlayer.api.core.http -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap -import com.google.common.collect.Multimap -import com.google.common.collect.MultimapBuilder import com.openlayer.api.core.toImmutable class HttpRequest @@ -11,13 +7,15 @@ private constructor( @get:JvmName("method") val method: HttpMethod, @get:JvmName("url") val url: String?, @get:JvmName("pathSegments") val pathSegments: List, - @get:JvmName("queryParams") val queryParams: ListMultimap, - @get:JvmName("headers") val headers: ListMultimap, + @get:JvmName("headers") val headers: Headers, + @get:JvmName("queryParams") val queryParams: QueryParams, @get:JvmName("body") val body: HttpRequestBody?, ) { + fun toBuilder(): Builder = Builder().from(this) + override fun toString(): String = - "HttpRequest{method=$method, pathSegments=$pathSegments, queryParams=$queryParams, headers=$headers, body=$body}" + "HttpRequest{method=$method, url=$url, pathSegments=$pathSegments, headers=$headers, queryParams=$queryParams, body=$body}" companion object { @JvmStatic fun builder() = Builder() @@ -27,56 +25,111 @@ private constructor( private var method: HttpMethod? = null private var url: String? = null - private var pathSegments: MutableList = ArrayList() - private var queryParams: ListMultimap = ArrayListMultimap.create() + private var pathSegments: MutableList = mutableListOf() + private var headers: Headers.Builder = Headers.builder() + private var queryParams: QueryParams.Builder = QueryParams.builder() private var body: HttpRequestBody? = null - private var headers: ListMultimap = - MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).arrayListValues().build() + + @JvmSynthetic + internal fun from(request: HttpRequest) = apply { + method = request.method + url = request.url + pathSegments = request.pathSegments.toMutableList() + headers = request.headers.toBuilder() + queryParams = request.queryParams.toBuilder() + body = request.body + } fun method(method: HttpMethod) = apply { this.method = method } fun url(url: String) = apply { this.url = url } - fun addPathSegment(pathSegment: String) = apply { this.pathSegments.add(pathSegment) } + fun addPathSegment(pathSegment: String) = apply { pathSegments.add(pathSegment) } fun addPathSegments(vararg pathSegments: String) = apply { - for (pathSegment in pathSegments) { - this.pathSegments.add(pathSegment) - } + this.pathSegments.addAll(pathSegments) } - fun putQueryParam(name: String, value: String) = apply { - this.queryParams.replaceValues(name, listOf(value)) + fun headers(headers: Headers) = apply { + this.headers.clear() + putAllHeaders(headers) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.queryParams.replaceValues(name, values) + fun headers(headers: Map>) = apply { + this.headers.clear() + putAllHeaders(headers) } - fun putAllQueryParams(queryParams: Map>) = apply { - queryParams.forEach(this::putQueryParams) + fun putHeader(name: String, value: String) = apply { headers.put(name, value) } + + fun putHeaders(name: String, values: Iterable) = apply { headers.put(name, values) } + + fun putAllHeaders(headers: Headers) = apply { this.headers.putAll(headers) } + + fun putAllHeaders(headers: Map>) = apply { + this.headers.putAll(headers) } - fun putAllQueryParams(queryParams: Multimap) = apply { - queryParams.asMap().forEach(this::putQueryParams) + fun replaceHeaders(name: String, value: String) = apply { headers.replace(name, value) } + + fun replaceHeaders(name: String, values: Iterable) = apply { + headers.replace(name, values) } - fun putHeader(name: String, value: String) = apply { - this.headers.replaceValues(name, listOf(value)) + fun replaceAllHeaders(headers: Headers) = apply { this.headers.replaceAll(headers) } + + fun replaceAllHeaders(headers: Map>) = apply { + this.headers.replaceAll(headers) } - fun putHeaders(name: String, values: Iterable) = apply { - this.headers.replaceValues(name, values) + fun removeHeaders(name: String) = apply { headers.remove(name) } + + fun removeAllHeaders(names: Set) = apply { headers.removeAll(names) } + + fun queryParams(queryParams: QueryParams) = apply { + this.queryParams.clear() + putAllQueryParams(queryParams) } - fun putAllHeaders(headers: Map>) = apply { - headers.forEach(this::putHeaders) + fun queryParams(queryParams: Map>) = apply { + this.queryParams.clear() + putAllQueryParams(queryParams) } - fun putAllHeaders(headers: Multimap) = apply { - headers.asMap().forEach(this::putHeaders) + fun putQueryParam(key: String, value: String) = apply { queryParams.put(key, value) } + + fun putQueryParams(key: String, values: Iterable) = apply { + queryParams.put(key, values) } + fun putAllQueryParams(queryParams: QueryParams) = apply { + this.queryParams.putAll(queryParams) + } + + fun putAllQueryParams(queryParams: Map>) = apply { + this.queryParams.putAll(queryParams) + } + + fun replaceQueryParams(key: String, value: String) = apply { + queryParams.replace(key, value) + } + + fun replaceQueryParams(key: String, values: Iterable) = apply { + queryParams.replace(key, values) + } + + fun replaceAllQueryParams(queryParams: QueryParams) = apply { + this.queryParams.replaceAll(queryParams) + } + + fun replaceAllQueryParams(queryParams: Map>) = apply { + this.queryParams.replaceAll(queryParams) + } + + fun removeQueryParams(key: String) = apply { queryParams.remove(key) } + + fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) } + fun body(body: HttpRequestBody) = apply { this.body = body } fun build(): HttpRequest = @@ -84,8 +137,8 @@ private constructor( checkNotNull(method) { "`method` is required but was not set" }, url, pathSegments.toImmutable(), - queryParams.toImmutable(), - headers, + headers.build(), + queryParams.build(), body, ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpResponse.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpResponse.kt index 5c5f3ce..098bc98 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpResponse.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/HttpResponse.kt @@ -1,6 +1,5 @@ package com.openlayer.api.core.http -import com.google.common.collect.ListMultimap import java.io.InputStream import java.lang.AutoCloseable @@ -8,7 +7,7 @@ interface HttpResponse : AutoCloseable { fun statusCode(): Int - fun headers(): ListMultimap + fun headers(): Headers fun body(): InputStream diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/QueryParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/QueryParams.kt new file mode 100644 index 0000000..4a53fb0 --- /dev/null +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/QueryParams.kt @@ -0,0 +1,86 @@ +package com.openlayer.api.core.http + +import com.openlayer.api.core.toImmutable + +class QueryParams +private constructor( + private val map: Map>, + @get:JvmName("size") val size: Int +) { + + fun isEmpty(): Boolean = map.isEmpty() + + fun keys(): Set = map.keys + + fun values(key: String): List = map[key].orEmpty() + + fun toBuilder(): Builder = Builder().putAll(map) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private val map: MutableMap> = mutableMapOf() + private var size: Int = 0 + + fun put(key: String, value: String) = apply { + map.getOrPut(key) { mutableListOf() }.add(value) + size++ + } + + fun put(key: String, values: Iterable) = apply { values.forEach { put(key, it) } } + + fun putAll(queryParams: Map>) = apply { + queryParams.forEach(::put) + } + + fun putAll(queryParams: QueryParams) = apply { + queryParams.keys().forEach { put(it, queryParams.values(it)) } + } + + fun replace(key: String, value: String) = apply { + remove(key) + put(key, value) + } + + fun replace(key: String, values: Iterable) = apply { + remove(key) + put(key, values) + } + + fun replaceAll(queryParams: Map>) = apply { + queryParams.forEach(::replace) + } + + fun replaceAll(queryParams: QueryParams) = apply { + queryParams.keys().forEach { replace(it, queryParams.values(it)) } + } + + fun remove(key: String) = apply { size -= map.remove(key).orEmpty().size } + + fun removeAll(keys: Set) = apply { keys.forEach(::remove) } + + fun clear() = apply { + map.clear() + size = 0 + } + + fun build() = + QueryParams(map.mapValues { (_, values) -> values.toImmutable() }.toImmutable(), size) + } + + override fun hashCode(): Int = map.hashCode() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is QueryParams && map == other.map + } + + override fun toString(): String = "QueryParams{map=$map}" +} diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/RetryingHttpClient.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/RetryingHttpClient.kt index 4d12aec..56feff5 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/RetryingHttpClient.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/core/http/RetryingHttpClient.kt @@ -35,21 +35,22 @@ private constructor( return httpClient.execute(request, requestOptions) } - maybeAddIdempotencyHeader(request) + var modifiedRequest = maybeAddIdempotencyHeader(request) // Don't send the current retry count in the headers if the caller set their own value. - val shouldSendRetryCount = !request.headers.containsKey("x-stainless-retry-count") + val shouldSendRetryCount = + !modifiedRequest.headers.names().contains("X-Stainless-Retry-Count") var retries = 0 while (true) { if (shouldSendRetryCount) { - setRetryCountHeader(request, retries) + modifiedRequest = setRetryCountHeader(modifiedRequest, retries) } val response = try { - val response = httpClient.execute(request, requestOptions) + val response = httpClient.execute(modifiedRequest, requestOptions) if (++retries > maxRetries || !shouldRetry(response)) { return response } @@ -76,10 +77,11 @@ private constructor( return httpClient.executeAsync(request, requestOptions) } - maybeAddIdempotencyHeader(request) + val modifiedRequest = maybeAddIdempotencyHeader(request) // Don't send the current retry count in the headers if the caller set their own value. - val shouldSendRetryCount = !request.headers.containsKey("x-stainless-retry-count") + val shouldSendRetryCount = + !modifiedRequest.headers.names().contains("X-Stainless-Retry-Count") var retries = 0 @@ -87,12 +89,11 @@ private constructor( request: HttpRequest, requestOptions: RequestOptions, ): CompletableFuture { - if (shouldSendRetryCount) { - setRetryCountHeader(request, retries) - } + val requestWithRetryCount = + if (shouldSendRetryCount) setRetryCountHeader(request, retries) else request return httpClient - .executeAsync(request, requestOptions) + .executeAsync(requestWithRetryCount, requestOptions) .handleAsync( fun( response: HttpResponse?, @@ -112,7 +113,7 @@ private constructor( val backoffMillis = getRetryBackoffMillis(retries, response) return sleepAsync(backoffMillis.toMillis()).thenCompose { - executeWithRetries(request, requestOptions) + executeWithRetries(requestWithRetryCount, requestOptions) } }, ) { @@ -122,7 +123,7 @@ private constructor( .thenCompose(Function.identity()) } - return executeWithRetries(request, requestOptions) + return executeWithRetries(modifiedRequest, requestOptions) } override fun close() = httpClient.close() @@ -132,23 +133,26 @@ private constructor( // the body data aren't available on subsequent attempts. request.body?.repeatable() ?: true - private fun setRetryCountHeader(request: HttpRequest, retries: Int) { - request.headers.removeAll("x-stainless-retry-count") - request.headers.put("x-stainless-retry-count", retries.toString()) - } + private fun setRetryCountHeader(request: HttpRequest, retries: Int): HttpRequest = + request.toBuilder().replaceHeaders("X-Stainless-Retry-Count", retries.toString()).build() private fun idempotencyKey(): String = "stainless-java-retry-${UUID.randomUUID()}" - private fun maybeAddIdempotencyHeader(request: HttpRequest) { - if (idempotencyHeader != null && !request.headers.containsKey(idempotencyHeader)) { - // Set a header to uniquely identify the request when retried - request.headers.put(idempotencyHeader, idempotencyKey()) + private fun maybeAddIdempotencyHeader(request: HttpRequest): HttpRequest { + if (idempotencyHeader == null || request.headers.names().contains(idempotencyHeader)) { + return request } + + return request + .toBuilder() + // Set a header to uniquely identify the request when retried. + .putHeader(idempotencyHeader, idempotencyKey()) + .build() } private fun shouldRetry(response: HttpResponse): Boolean { // Note: this is not a standard header - val shouldRetryHeader = response.headers().get("x-should-retry").getOrNull(0) + val shouldRetryHeader = response.headers().values("X-Should-Retry").getOrNull(0) val statusCode = response.statusCode() return when { @@ -180,11 +184,11 @@ private constructor( ?.headers() ?.let { headers -> headers - .get("Retry-After-Ms") + .values("Retry-After-Ms") .getOrNull(0) ?.toFloatOrNull() ?.times(TimeUnit.MILLISECONDS.toNanos(1)) - ?: headers.get("Retry-After").getOrNull(0)?.let { retryAfter -> + ?: headers.values("Retry-After").getOrNull(0)?.let { retryAfter -> retryAfter.toFloatOrNull()?.times(TimeUnit.SECONDS.toNanos(1)) ?: try { ChronoUnit.MILLIS.between( diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/BadRequestException.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/BadRequestException.kt index 6c25d62..cddebd0 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/BadRequestException.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/BadRequestException.kt @@ -1,9 +1,9 @@ package com.openlayer.api.errors -import com.google.common.collect.ListMultimap +import com.openlayer.api.core.http.Headers class BadRequestException( - headers: ListMultimap, + headers: Headers, body: String, error: OpenlayerError, ) : OpenlayerServiceException(400, headers, body, error) diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/InternalServerException.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/InternalServerException.kt index f22438b..ba8c911 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/InternalServerException.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/InternalServerException.kt @@ -1,10 +1,10 @@ package com.openlayer.api.errors -import com.google.common.collect.ListMultimap +import com.openlayer.api.core.http.Headers class InternalServerException( statusCode: Int, - headers: ListMultimap, + headers: Headers, body: String, error: OpenlayerError, ) : OpenlayerServiceException(statusCode, headers, body, error) diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/NotFoundException.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/NotFoundException.kt index aa9f8c8..0786e63 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/NotFoundException.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/NotFoundException.kt @@ -1,9 +1,9 @@ package com.openlayer.api.errors -import com.google.common.collect.ListMultimap +import com.openlayer.api.core.http.Headers class NotFoundException( - headers: ListMultimap, + headers: Headers, body: String, error: OpenlayerError, ) : OpenlayerServiceException(404, headers, body, error) diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/OpenlayerError.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/OpenlayerError.kt index b324349..582b268 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/OpenlayerError.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/OpenlayerError.kt @@ -13,14 +13,12 @@ import java.util.Objects @JsonDeserialize(builder = OpenlayerError.Builder::class) @NoAutoDetect class OpenlayerError -constructor( - private val additionalProperties: Map, +private constructor( + @JsonAnyGetter + @get:JvmName("additionalProperties") + val additionalProperties: Map, ) { - @JsonAnyGetter fun additionalProperties(): Map = additionalProperties - - fun toBuilder() = Builder() - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -35,6 +33,8 @@ constructor( override fun toString() = "OpenlayerError{additionalProperties=$additionalProperties}" + fun toBuilder() = Builder().from(this) + companion object { @JvmStatic fun builder() = Builder() @@ -44,22 +44,31 @@ constructor( private var additionalProperties: MutableMap = mutableMapOf() - fun from(error: OpenlayerError) = apply { additionalProperties(error.additionalProperties) } + @JvmSynthetic + internal fun from(openlayerError: OpenlayerError) = apply { + additionalProperties = openlayerError.additionalProperties.toMutableMap() + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + 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) + } + fun build(): OpenlayerError = OpenlayerError(additionalProperties.toImmutable()) } } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/OpenlayerServiceException.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/OpenlayerServiceException.kt index 6e962cb..586f9be 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/OpenlayerServiceException.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/OpenlayerServiceException.kt @@ -1,12 +1,12 @@ package com.openlayer.api.errors -import com.google.common.collect.ListMultimap +import com.openlayer.api.core.http.Headers abstract class OpenlayerServiceException @JvmOverloads constructor( private val statusCode: Int, - private val headers: ListMultimap, + private val headers: Headers, private val body: String, private val error: OpenlayerError, message: String = "$statusCode: $error", @@ -15,7 +15,7 @@ constructor( fun statusCode(): Int = statusCode - fun headers(): ListMultimap = headers + fun headers(): Headers = headers fun body(): String = body diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/PermissionDeniedException.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/PermissionDeniedException.kt index 0e14695..89f54d4 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/PermissionDeniedException.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/PermissionDeniedException.kt @@ -1,9 +1,9 @@ package com.openlayer.api.errors -import com.google.common.collect.ListMultimap +import com.openlayer.api.core.http.Headers class PermissionDeniedException( - headers: ListMultimap, + headers: Headers, body: String, error: OpenlayerError, ) : OpenlayerServiceException(403, headers, body, error) diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/RateLimitException.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/RateLimitException.kt index 16c010e..27bfad4 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/RateLimitException.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/RateLimitException.kt @@ -1,9 +1,9 @@ package com.openlayer.api.errors -import com.google.common.collect.ListMultimap +import com.openlayer.api.core.http.Headers class RateLimitException( - headers: ListMultimap, + headers: Headers, body: String, error: OpenlayerError, ) : OpenlayerServiceException(429, headers, body, error) diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnauthorizedException.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnauthorizedException.kt index 6a09f5e..ba6f77e 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnauthorizedException.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnauthorizedException.kt @@ -1,9 +1,9 @@ package com.openlayer.api.errors -import com.google.common.collect.ListMultimap +import com.openlayer.api.core.http.Headers class UnauthorizedException( - headers: ListMultimap, + headers: Headers, body: String, error: OpenlayerError, ) : OpenlayerServiceException(401, headers, body, error) diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnexpectedStatusCodeException.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnexpectedStatusCodeException.kt index 26697c3..b4cab62 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnexpectedStatusCodeException.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnexpectedStatusCodeException.kt @@ -1,10 +1,10 @@ package com.openlayer.api.errors -import com.google.common.collect.ListMultimap +import com.openlayer.api.core.http.Headers class UnexpectedStatusCodeException( statusCode: Int, - headers: ListMultimap, + headers: Headers, body: String, error: OpenlayerError, ) : OpenlayerServiceException(statusCode, headers, body, error) diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnprocessableEntityException.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnprocessableEntityException.kt index 19ffac5..e7d2ecd 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnprocessableEntityException.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/errors/UnprocessableEntityException.kt @@ -1,9 +1,9 @@ package com.openlayer.api.errors -import com.google.common.collect.ListMultimap +import com.openlayer.api.core.http.Headers class UnprocessableEntityException( - headers: ListMultimap, + headers: Headers, body: String, error: OpenlayerError, ) : OpenlayerServiceException(422, headers, body, error) diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitTestResultListParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitTestResultListParams.kt index ff85530..2f44b32 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitTestResultListParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/CommitTestResultListParams.kt @@ -7,7 +7,8 @@ import com.openlayer.api.core.Enum import com.openlayer.api.core.JsonField import com.openlayer.api.core.JsonValue import com.openlayer.api.core.NoAutoDetect -import com.openlayer.api.core.toImmutable +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.errors.OpenlayerInvalidDataException import com.openlayer.api.models.* import java.util.Objects @@ -21,8 +22,8 @@ constructor( private val perPage: Long?, private val status: Status?, private val type: Type?, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, ) { fun projectVersionId(): String = projectVersionId @@ -37,20 +38,20 @@ constructor( fun type(): Optional = Optional.ofNullable(type) + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.includeArchived?.let { params.put("includeArchived", listOf(it.toString())) } - this.page?.let { params.put("page", listOf(it.toString())) } - this.perPage?.let { params.put("perPage", listOf(it.toString())) } - this.status?.let { params.put("status", listOf(it.toString())) } - this.type?.let { params.put("type", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.includeArchived?.let { queryParams.put("includeArchived", listOf(it.toString())) } + this.page?.let { queryParams.put("page", listOf(it.toString())) } + this.perPage?.let { queryParams.put("perPage", listOf(it.toString())) } + this.status?.let { queryParams.put("status", listOf(it.toString())) } + this.type?.let { queryParams.put("type", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - fun getPathParam(index: Int): String { return when (index) { 0 -> projectVersionId @@ -58,24 +59,24 @@ constructor( } } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is CommitTestResultListParams && this.projectVersionId == other.projectVersionId && this.includeArchived == other.includeArchived && this.page == other.page && this.perPage == other.perPage && this.status == other.status && this.type == other.type && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders /* spotless:on */ + return /* spotless:off */ other is CommitTestResultListParams && this.projectVersionId == other.projectVersionId && this.includeArchived == other.includeArchived && this.page == other.page && this.perPage == other.perPage && this.status == other.status && this.type == other.type && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(projectVersionId, includeArchived, page, perPage, status, type, additionalQueryParams, additionalHeaders) /* spotless:on */ + return /* spotless:off */ Objects.hash(projectVersionId, includeArchived, page, perPage, status, type, additionalHeaders, additionalQueryParams) /* spotless:on */ } override fun toString() = - "CommitTestResultListParams{projectVersionId=$projectVersionId, includeArchived=$includeArchived, page=$page, perPage=$perPage, status=$status, type=$type, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders}" + "CommitTestResultListParams{projectVersionId=$projectVersionId, includeArchived=$includeArchived, page=$page, perPage=$perPage, status=$status, type=$type, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" fun toBuilder() = Builder().from(this) @@ -93,8 +94,8 @@ constructor( private var perPage: Long? = null private var status: Status? = null private var type: Type? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(commitTestResultListParams: CommitTestResultListParams) = apply { @@ -104,8 +105,8 @@ constructor( this.perPage = commitTestResultListParams.perPage this.status = commitTestResultListParams.status this.type = commitTestResultListParams.type - additionalQueryParams(commitTestResultListParams.additionalQueryParams) additionalHeaders(commitTestResultListParams.additionalHeaders) + additionalQueryParams(commitTestResultListParams.additionalQueryParams) } fun projectVersionId(projectVersionId: String) = apply { @@ -135,45 +136,103 @@ constructor( */ fun type(type: Type) = apply { this.type = type } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun build(): CommitTestResultListParams = CommitTestResultListParams( @@ -183,8 +242,8 @@ constructor( perPage, status, type, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineDataStreamParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineDataStreamParams.kt index dd8d2c9..e30f47a 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineDataStreamParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineDataStreamParams.kt @@ -20,6 +20,8 @@ import com.openlayer.api.core.JsonMissing import com.openlayer.api.core.JsonValue import com.openlayer.api.core.NoAutoDetect import com.openlayer.api.core.getOrThrow +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.core.toImmutable import com.openlayer.api.errors.OpenlayerInvalidDataException import com.openlayer.api.models.* @@ -31,8 +33,8 @@ constructor( private val inferencePipelineId: String, private val config: Config, private val rows: List, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) { @@ -51,9 +53,9 @@ constructor( ) } - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -153,9 +155,9 @@ constructor( "InferencePipelineDataStreamBody{config=$config, rows=$rows, additionalProperties=$additionalProperties}" } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams fun _additionalBodyProperties(): Map = additionalBodyProperties @@ -164,15 +166,15 @@ constructor( return true } - return /* spotless:off */ other is InferencePipelineDataStreamParams && this.inferencePipelineId == other.inferencePipelineId && this.config == other.config && this.rows == other.rows && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return /* spotless:off */ other is InferencePipelineDataStreamParams && this.inferencePipelineId == other.inferencePipelineId && this.config == other.config && this.rows == other.rows && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(inferencePipelineId, config, rows, additionalQueryParams, additionalHeaders, additionalBodyProperties) /* spotless:on */ + return /* spotless:off */ Objects.hash(inferencePipelineId, config, rows, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ } override fun toString() = - "InferencePipelineDataStreamParams{inferencePipelineId=$inferencePipelineId, config=$config, rows=$rows, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}" + "InferencePipelineDataStreamParams{inferencePipelineId=$inferencePipelineId, config=$config, rows=$rows, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" fun toBuilder() = Builder().from(this) @@ -187,8 +189,8 @@ constructor( private var inferencePipelineId: String? = null private var config: Config? = null private var rows: MutableList = mutableListOf() - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() private var additionalBodyProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -197,8 +199,8 @@ constructor( this.inferencePipelineId = inferencePipelineDataStreamParams.inferencePipelineId this.config = inferencePipelineDataStreamParams.config this.rows(inferencePipelineDataStreamParams.rows) - additionalQueryParams(inferencePipelineDataStreamParams.additionalQueryParams) additionalHeaders(inferencePipelineDataStreamParams.additionalHeaders) + additionalQueryParams(inferencePipelineDataStreamParams.additionalQueryParams) additionalBodyProperties(inferencePipelineDataStreamParams.additionalBodyProperties) } @@ -236,53 +238,111 @@ constructor( /** A list of inference data points with inputs and outputs */ fun addRow(row: Row) = apply { this.rows.add(row) } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { this.additionalBodyProperties.clear() - this.additionalBodyProperties.putAll(additionalBodyProperties) + putAllAdditionalBodyProperties(additionalBodyProperties) } fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - this.additionalBodyProperties.put(key, value) + additionalBodyProperties.put(key, value) } fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = @@ -290,6 +350,14 @@ constructor( this.additionalBodyProperties.putAll(additionalBodyProperties) } + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + fun build(): InferencePipelineDataStreamParams = InferencePipelineDataStreamParams( checkNotNull(inferencePipelineId) { @@ -297,8 +365,8 @@ constructor( }, checkNotNull(config) { "`config` is required but was not set" }, checkNotNull(rows) { "`rows` is required but was not set" }.toImmutable(), - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), additionalBodyProperties.toImmutable(), ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineDeleteParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineDeleteParams.kt index 7aecc8f..709bf37 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineDeleteParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineDeleteParams.kt @@ -4,6 +4,8 @@ package com.openlayer.api.models import com.openlayer.api.core.JsonValue import com.openlayer.api.core.NoAutoDetect +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.core.toImmutable import com.openlayer.api.models.* import java.util.Objects @@ -12,8 +14,8 @@ import java.util.Optional class InferencePipelineDeleteParams constructor( private val inferencePipelineId: String, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) { @@ -24,9 +26,9 @@ constructor( return Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) } - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -35,9 +37,9 @@ constructor( } } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams fun _additionalBodyProperties(): Map = additionalBodyProperties @@ -46,15 +48,15 @@ constructor( return true } - return /* spotless:off */ other is InferencePipelineDeleteParams && this.inferencePipelineId == other.inferencePipelineId && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return /* spotless:off */ other is InferencePipelineDeleteParams && this.inferencePipelineId == other.inferencePipelineId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(inferencePipelineId, additionalQueryParams, additionalHeaders, additionalBodyProperties) /* spotless:on */ + return /* spotless:off */ Objects.hash(inferencePipelineId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ } override fun toString() = - "InferencePipelineDeleteParams{inferencePipelineId=$inferencePipelineId, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}" + "InferencePipelineDeleteParams{inferencePipelineId=$inferencePipelineId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" fun toBuilder() = Builder().from(this) @@ -67,15 +69,15 @@ constructor( class Builder { private var inferencePipelineId: String? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() private var additionalBodyProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(inferencePipelineDeleteParams: InferencePipelineDeleteParams) = apply { this.inferencePipelineId = inferencePipelineDeleteParams.inferencePipelineId - additionalQueryParams(inferencePipelineDeleteParams.additionalQueryParams) additionalHeaders(inferencePipelineDeleteParams.additionalHeaders) + additionalQueryParams(inferencePipelineDeleteParams.additionalQueryParams) additionalBodyProperties(inferencePipelineDeleteParams.additionalBodyProperties) } @@ -83,53 +85,111 @@ constructor( this.inferencePipelineId = inferencePipelineId } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { this.additionalBodyProperties.clear() - this.additionalBodyProperties.putAll(additionalBodyProperties) + putAllAdditionalBodyProperties(additionalBodyProperties) } fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - this.additionalBodyProperties.put(key, value) + additionalBodyProperties.put(key, value) } fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = @@ -137,13 +197,21 @@ constructor( this.additionalBodyProperties.putAll(additionalBodyProperties) } + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + fun build(): InferencePipelineDeleteParams = InferencePipelineDeleteParams( checkNotNull(inferencePipelineId) { "`inferencePipelineId` is required but was not set" }, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), additionalBodyProperties.toImmutable(), ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineRetrieveParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineRetrieveParams.kt index df34f15..950a922 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineRetrieveParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineRetrieveParams.kt @@ -3,22 +3,23 @@ package com.openlayer.api.models import com.openlayer.api.core.NoAutoDetect -import com.openlayer.api.core.toImmutable +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.models.* import java.util.Objects class InferencePipelineRetrieveParams constructor( private val inferencePipelineId: String, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, ) { fun inferencePipelineId(): String = inferencePipelineId - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -27,24 +28,24 @@ constructor( } } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is InferencePipelineRetrieveParams && this.inferencePipelineId == other.inferencePipelineId && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders /* spotless:on */ + return /* spotless:off */ other is InferencePipelineRetrieveParams && this.inferencePipelineId == other.inferencePipelineId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(inferencePipelineId, additionalQueryParams, additionalHeaders) /* spotless:on */ + return /* spotless:off */ Objects.hash(inferencePipelineId, additionalHeaders, additionalQueryParams) /* spotless:on */ } override fun toString() = - "InferencePipelineRetrieveParams{inferencePipelineId=$inferencePipelineId, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders}" + "InferencePipelineRetrieveParams{inferencePipelineId=$inferencePipelineId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" fun toBuilder() = Builder().from(this) @@ -57,68 +58,126 @@ constructor( class Builder { private var inferencePipelineId: String? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(inferencePipelineRetrieveParams: InferencePipelineRetrieveParams) = apply { this.inferencePipelineId = inferencePipelineRetrieveParams.inferencePipelineId - additionalQueryParams(inferencePipelineRetrieveParams.additionalQueryParams) additionalHeaders(inferencePipelineRetrieveParams.additionalHeaders) + additionalQueryParams(inferencePipelineRetrieveParams.additionalQueryParams) } fun inferencePipelineId(inferencePipelineId: String) = apply { this.inferencePipelineId = inferencePipelineId } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun build(): InferencePipelineRetrieveParams = InferencePipelineRetrieveParams( checkNotNull(inferencePipelineId) { "`inferencePipelineId` is required but was not set" }, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineRowUpdateParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineRowUpdateParams.kt index 0a29a72..7062d0b 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineRowUpdateParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineRowUpdateParams.kt @@ -9,6 +9,8 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.openlayer.api.core.ExcludeMissing import com.openlayer.api.core.JsonValue import com.openlayer.api.core.NoAutoDetect +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.core.toImmutable import com.openlayer.api.models.* import java.util.Objects @@ -20,8 +22,8 @@ constructor( private val inferenceId: String, private val row: JsonValue, private val config: Config?, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) { @@ -42,16 +44,16 @@ constructor( ) } + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.inferenceId.let { params.put("inferenceId", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.inferenceId.let { queryParams.put("inferenceId", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - fun getPathParam(index: Int): String { return when (index) { 0 -> inferencePipelineId @@ -144,9 +146,9 @@ constructor( "InferencePipelineRowUpdateBody{row=$row, config=$config, additionalProperties=$additionalProperties}" } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams fun _additionalBodyProperties(): Map = additionalBodyProperties @@ -155,15 +157,15 @@ constructor( return true } - return /* spotless:off */ other is InferencePipelineRowUpdateParams && this.inferencePipelineId == other.inferencePipelineId && this.row == other.row && this.config == other.config && this.inferenceId == other.inferenceId && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return /* spotless:off */ other is InferencePipelineRowUpdateParams && this.inferencePipelineId == other.inferencePipelineId && this.row == other.row && this.config == other.config && this.inferenceId == other.inferenceId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(inferencePipelineId, row, config, inferenceId, additionalQueryParams, additionalHeaders, additionalBodyProperties) /* spotless:on */ + return /* spotless:off */ Objects.hash(inferencePipelineId, row, config, inferenceId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ } override fun toString() = - "InferencePipelineRowUpdateParams{inferencePipelineId=$inferencePipelineId, row=$row, config=$config, inferenceId=$inferenceId, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}" + "InferencePipelineRowUpdateParams{inferencePipelineId=$inferencePipelineId, row=$row, config=$config, inferenceId=$inferenceId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" fun toBuilder() = Builder().from(this) @@ -179,8 +181,8 @@ constructor( private var inferenceId: String? = null private var row: JsonValue? = null private var config: Config? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() private var additionalBodyProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -190,8 +192,8 @@ constructor( this.inferenceId = inferencePipelineRowUpdateParams.inferenceId this.row = inferencePipelineRowUpdateParams.row this.config = inferencePipelineRowUpdateParams.config - additionalQueryParams(inferencePipelineRowUpdateParams.additionalQueryParams) additionalHeaders(inferencePipelineRowUpdateParams.additionalHeaders) + additionalQueryParams(inferencePipelineRowUpdateParams.additionalQueryParams) additionalBodyProperties(inferencePipelineRowUpdateParams.additionalBodyProperties) } @@ -206,53 +208,111 @@ constructor( fun config(config: Config) = apply { this.config = config } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { this.additionalBodyProperties.clear() - this.additionalBodyProperties.putAll(additionalBodyProperties) + putAllAdditionalBodyProperties(additionalBodyProperties) } fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - this.additionalBodyProperties.put(key, value) + additionalBodyProperties.put(key, value) } fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = @@ -260,6 +320,14 @@ constructor( this.additionalBodyProperties.putAll(additionalBodyProperties) } + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + fun build(): InferencePipelineRowUpdateParams = InferencePipelineRowUpdateParams( checkNotNull(inferencePipelineId) { @@ -268,8 +336,8 @@ constructor( checkNotNull(inferenceId) { "`inferenceId` is required but was not set" }, checkNotNull(row) { "`row` is required but was not set" }, config, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), additionalBodyProperties.toImmutable(), ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineTestResultListParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineTestResultListParams.kt index 82a6a55..183f81f 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineTestResultListParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineTestResultListParams.kt @@ -7,7 +7,8 @@ import com.openlayer.api.core.Enum import com.openlayer.api.core.JsonField import com.openlayer.api.core.JsonValue import com.openlayer.api.core.NoAutoDetect -import com.openlayer.api.core.toImmutable +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.errors.OpenlayerInvalidDataException import com.openlayer.api.models.* import java.util.Objects @@ -20,8 +21,8 @@ constructor( private val perPage: Long?, private val status: Status?, private val type: Type?, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, ) { fun inferencePipelineId(): String = inferencePipelineId @@ -34,19 +35,19 @@ constructor( fun type(): Optional = Optional.ofNullable(type) + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.page?.let { params.put("page", listOf(it.toString())) } - this.perPage?.let { params.put("perPage", listOf(it.toString())) } - this.status?.let { params.put("status", listOf(it.toString())) } - this.type?.let { params.put("type", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.page?.let { queryParams.put("page", listOf(it.toString())) } + this.perPage?.let { queryParams.put("perPage", listOf(it.toString())) } + this.status?.let { queryParams.put("status", listOf(it.toString())) } + this.type?.let { queryParams.put("type", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - fun getPathParam(index: Int): String { return when (index) { 0 -> inferencePipelineId @@ -54,24 +55,24 @@ constructor( } } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is InferencePipelineTestResultListParams && this.inferencePipelineId == other.inferencePipelineId && this.page == other.page && this.perPage == other.perPage && this.status == other.status && this.type == other.type && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders /* spotless:on */ + return /* spotless:off */ other is InferencePipelineTestResultListParams && this.inferencePipelineId == other.inferencePipelineId && this.page == other.page && this.perPage == other.perPage && this.status == other.status && this.type == other.type && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(inferencePipelineId, page, perPage, status, type, additionalQueryParams, additionalHeaders) /* spotless:on */ + return /* spotless:off */ Objects.hash(inferencePipelineId, page, perPage, status, type, additionalHeaders, additionalQueryParams) /* spotless:on */ } override fun toString() = - "InferencePipelineTestResultListParams{inferencePipelineId=$inferencePipelineId, page=$page, perPage=$perPage, status=$status, type=$type, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders}" + "InferencePipelineTestResultListParams{inferencePipelineId=$inferencePipelineId, page=$page, perPage=$perPage, status=$status, type=$type, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" fun toBuilder() = Builder().from(this) @@ -88,8 +89,8 @@ constructor( private var perPage: Long? = null private var status: Status? = null private var type: Type? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from( @@ -100,8 +101,8 @@ constructor( this.perPage = inferencePipelineTestResultListParams.perPage this.status = inferencePipelineTestResultListParams.status this.type = inferencePipelineTestResultListParams.type - additionalQueryParams(inferencePipelineTestResultListParams.additionalQueryParams) additionalHeaders(inferencePipelineTestResultListParams.additionalHeaders) + additionalQueryParams(inferencePipelineTestResultListParams.additionalQueryParams) } fun inferencePipelineId(inferencePipelineId: String) = apply { @@ -126,45 +127,103 @@ constructor( */ fun type(type: Type) = apply { this.type = type } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun build(): InferencePipelineTestResultListParams = InferencePipelineTestResultListParams( @@ -175,8 +234,8 @@ constructor( perPage, status, type, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineUpdateParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineUpdateParams.kt index 4f4f8a7..f5810d6 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineUpdateParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/InferencePipelineUpdateParams.kt @@ -9,6 +9,8 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.openlayer.api.core.ExcludeMissing import com.openlayer.api.core.JsonValue import com.openlayer.api.core.NoAutoDetect +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.core.toImmutable import com.openlayer.api.models.* import java.util.Objects @@ -20,8 +22,8 @@ constructor( private val description: String?, private val name: String?, private val referenceDatasetUri: String?, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) { @@ -43,9 +45,9 @@ constructor( ) } - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -163,9 +165,9 @@ constructor( "InferencePipelineUpdateBody{description=$description, name=$name, referenceDatasetUri=$referenceDatasetUri, additionalProperties=$additionalProperties}" } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams fun _additionalBodyProperties(): Map = additionalBodyProperties @@ -174,15 +176,15 @@ constructor( return true } - return /* spotless:off */ other is InferencePipelineUpdateParams && this.inferencePipelineId == other.inferencePipelineId && this.description == other.description && this.name == other.name && this.referenceDatasetUri == other.referenceDatasetUri && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return /* spotless:off */ other is InferencePipelineUpdateParams && this.inferencePipelineId == other.inferencePipelineId && this.description == other.description && this.name == other.name && this.referenceDatasetUri == other.referenceDatasetUri && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(inferencePipelineId, description, name, referenceDatasetUri, additionalQueryParams, additionalHeaders, additionalBodyProperties) /* spotless:on */ + return /* spotless:off */ Objects.hash(inferencePipelineId, description, name, referenceDatasetUri, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ } override fun toString() = - "InferencePipelineUpdateParams{inferencePipelineId=$inferencePipelineId, description=$description, name=$name, referenceDatasetUri=$referenceDatasetUri, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}" + "InferencePipelineUpdateParams{inferencePipelineId=$inferencePipelineId, description=$description, name=$name, referenceDatasetUri=$referenceDatasetUri, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" fun toBuilder() = Builder().from(this) @@ -198,8 +200,8 @@ constructor( private var description: String? = null private var name: String? = null private var referenceDatasetUri: String? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() private var additionalBodyProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -208,8 +210,8 @@ constructor( this.description = inferencePipelineUpdateParams.description this.name = inferencePipelineUpdateParams.name this.referenceDatasetUri = inferencePipelineUpdateParams.referenceDatasetUri - additionalQueryParams(inferencePipelineUpdateParams.additionalQueryParams) additionalHeaders(inferencePipelineUpdateParams.additionalHeaders) + additionalQueryParams(inferencePipelineUpdateParams.additionalQueryParams) additionalBodyProperties(inferencePipelineUpdateParams.additionalBodyProperties) } @@ -231,53 +233,111 @@ constructor( this.referenceDatasetUri = referenceDatasetUri } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { this.additionalBodyProperties.clear() - this.additionalBodyProperties.putAll(additionalBodyProperties) + putAllAdditionalBodyProperties(additionalBodyProperties) } fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - this.additionalBodyProperties.put(key, value) + additionalBodyProperties.put(key, value) } fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = @@ -285,6 +345,14 @@ constructor( this.additionalBodyProperties.putAll(additionalBodyProperties) } + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + fun build(): InferencePipelineUpdateParams = InferencePipelineUpdateParams( checkNotNull(inferencePipelineId) { @@ -293,8 +361,8 @@ constructor( description, name, referenceDatasetUri, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), additionalBodyProperties.toImmutable(), ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCommitCreateParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCommitCreateParams.kt index 8bc883e..173a2b1 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCommitCreateParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCommitCreateParams.kt @@ -12,6 +12,8 @@ import com.openlayer.api.core.ExcludeMissing import com.openlayer.api.core.JsonField import com.openlayer.api.core.JsonValue import com.openlayer.api.core.NoAutoDetect +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.core.toImmutable import com.openlayer.api.errors.OpenlayerInvalidDataException import com.openlayer.api.models.* @@ -26,8 +28,8 @@ constructor( private val storageUri: String, private val archived: Boolean?, private val deploymentStatus: String?, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) { @@ -52,9 +54,9 @@ constructor( ) } - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -176,9 +178,9 @@ constructor( "ProjectCommitCreateBody{commit=$commit, storageUri=$storageUri, archived=$archived, deploymentStatus=$deploymentStatus, additionalProperties=$additionalProperties}" } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams fun _additionalBodyProperties(): Map = additionalBodyProperties @@ -187,15 +189,15 @@ constructor( return true } - return /* spotless:off */ other is ProjectCommitCreateParams && this.projectId == other.projectId && this.commit == other.commit && this.storageUri == other.storageUri && this.archived == other.archived && this.deploymentStatus == other.deploymentStatus && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return /* spotless:off */ other is ProjectCommitCreateParams && this.projectId == other.projectId && this.commit == other.commit && this.storageUri == other.storageUri && this.archived == other.archived && this.deploymentStatus == other.deploymentStatus && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(projectId, commit, storageUri, archived, deploymentStatus, additionalQueryParams, additionalHeaders, additionalBodyProperties) /* spotless:on */ + return /* spotless:off */ Objects.hash(projectId, commit, storageUri, archived, deploymentStatus, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ } override fun toString() = - "ProjectCommitCreateParams{projectId=$projectId, commit=$commit, storageUri=$storageUri, archived=$archived, deploymentStatus=$deploymentStatus, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}" + "ProjectCommitCreateParams{projectId=$projectId, commit=$commit, storageUri=$storageUri, archived=$archived, deploymentStatus=$deploymentStatus, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" fun toBuilder() = Builder().from(this) @@ -212,8 +214,8 @@ constructor( private var storageUri: String? = null private var archived: Boolean? = null private var deploymentStatus: String? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() private var additionalBodyProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -223,8 +225,8 @@ constructor( this.storageUri = projectCommitCreateParams.storageUri this.archived = projectCommitCreateParams.archived this.deploymentStatus = projectCommitCreateParams.deploymentStatus - additionalQueryParams(projectCommitCreateParams.additionalQueryParams) additionalHeaders(projectCommitCreateParams.additionalHeaders) + additionalQueryParams(projectCommitCreateParams.additionalQueryParams) additionalBodyProperties(projectCommitCreateParams.additionalBodyProperties) } @@ -244,53 +246,111 @@ constructor( this.deploymentStatus = deploymentStatus } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { this.additionalBodyProperties.clear() - this.additionalBodyProperties.putAll(additionalBodyProperties) + putAllAdditionalBodyProperties(additionalBodyProperties) } fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - this.additionalBodyProperties.put(key, value) + additionalBodyProperties.put(key, value) } fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = @@ -298,6 +358,14 @@ constructor( this.additionalBodyProperties.putAll(additionalBodyProperties) } + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + fun build(): ProjectCommitCreateParams = ProjectCommitCreateParams( checkNotNull(projectId) { "`projectId` is required but was not set" }, @@ -305,8 +373,8 @@ constructor( checkNotNull(storageUri) { "`storageUri` is required but was not set" }, archived, deploymentStatus, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), additionalBodyProperties.toImmutable(), ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCommitListParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCommitListParams.kt index 054d9e8..e8fa829 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCommitListParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCommitListParams.kt @@ -3,7 +3,8 @@ package com.openlayer.api.models import com.openlayer.api.core.NoAutoDetect -import com.openlayer.api.core.toImmutable +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.models.* import java.util.Objects import java.util.Optional @@ -13,8 +14,8 @@ constructor( private val projectId: String, private val page: Long?, private val perPage: Long?, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, ) { fun projectId(): String = projectId @@ -23,17 +24,17 @@ constructor( fun perPage(): Optional = Optional.ofNullable(perPage) + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.page?.let { params.put("page", listOf(it.toString())) } - this.perPage?.let { params.put("perPage", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.page?.let { queryParams.put("page", listOf(it.toString())) } + this.perPage?.let { queryParams.put("perPage", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - fun getPathParam(index: Int): String { return when (index) { 0 -> projectId @@ -41,24 +42,24 @@ constructor( } } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ProjectCommitListParams && this.projectId == other.projectId && this.page == other.page && this.perPage == other.perPage && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders /* spotless:on */ + return /* spotless:off */ other is ProjectCommitListParams && this.projectId == other.projectId && this.page == other.page && this.perPage == other.perPage && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(projectId, page, perPage, additionalQueryParams, additionalHeaders) /* spotless:on */ + return /* spotless:off */ Objects.hash(projectId, page, perPage, additionalHeaders, additionalQueryParams) /* spotless:on */ } override fun toString() = - "ProjectCommitListParams{projectId=$projectId, page=$page, perPage=$perPage, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders}" + "ProjectCommitListParams{projectId=$projectId, page=$page, perPage=$perPage, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" fun toBuilder() = Builder().from(this) @@ -73,16 +74,16 @@ constructor( private var projectId: String? = null private var page: Long? = null private var perPage: Long? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(projectCommitListParams: ProjectCommitListParams) = apply { this.projectId = projectCommitListParams.projectId this.page = projectCommitListParams.page this.perPage = projectCommitListParams.perPage - additionalQueryParams(projectCommitListParams.additionalQueryParams) additionalHeaders(projectCommitListParams.additionalHeaders) + additionalQueryParams(projectCommitListParams.additionalQueryParams) } fun projectId(projectId: String) = apply { this.projectId = projectId } @@ -93,53 +94,111 @@ constructor( /** Maximum number of items to return per page. */ fun perPage(perPage: Long) = apply { this.perPage = perPage } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun build(): ProjectCommitListParams = ProjectCommitListParams( checkNotNull(projectId) { "`projectId` is required but was not set" }, page, perPage, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCreateParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCreateParams.kt index dc5fa27..07714dd 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCreateParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectCreateParams.kt @@ -12,6 +12,8 @@ import com.openlayer.api.core.ExcludeMissing import com.openlayer.api.core.JsonField import com.openlayer.api.core.JsonValue import com.openlayer.api.core.NoAutoDetect +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.core.toImmutable import com.openlayer.api.errors.OpenlayerInvalidDataException import com.openlayer.api.models.* @@ -24,8 +26,8 @@ constructor( private val name: String, private val taskType: TaskType, private val description: String?, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) { @@ -45,9 +47,9 @@ constructor( ) } - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams @JsonDeserialize(builder = ProjectCreateBody.Builder::class) @NoAutoDetect @@ -149,9 +151,9 @@ constructor( "ProjectCreateBody{name=$name, taskType=$taskType, description=$description, additionalProperties=$additionalProperties}" } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams fun _additionalBodyProperties(): Map = additionalBodyProperties @@ -160,15 +162,15 @@ constructor( return true } - return /* spotless:off */ other is ProjectCreateParams && this.name == other.name && this.taskType == other.taskType && this.description == other.description && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return /* spotless:off */ other is ProjectCreateParams && this.name == other.name && this.taskType == other.taskType && this.description == other.description && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(name, taskType, description, additionalQueryParams, additionalHeaders, additionalBodyProperties) /* spotless:on */ + return /* spotless:off */ Objects.hash(name, taskType, description, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ } override fun toString() = - "ProjectCreateParams{name=$name, taskType=$taskType, description=$description, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}" + "ProjectCreateParams{name=$name, taskType=$taskType, description=$description, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" fun toBuilder() = Builder().from(this) @@ -183,8 +185,8 @@ constructor( private var name: String? = null private var taskType: TaskType? = null private var description: String? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() private var additionalBodyProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -192,8 +194,8 @@ constructor( this.name = projectCreateParams.name this.taskType = projectCreateParams.taskType this.description = projectCreateParams.description - additionalQueryParams(projectCreateParams.additionalQueryParams) additionalHeaders(projectCreateParams.additionalHeaders) + additionalQueryParams(projectCreateParams.additionalQueryParams) additionalBodyProperties(projectCreateParams.additionalBodyProperties) } @@ -206,53 +208,111 @@ constructor( /** The project description. */ fun description(description: String) = apply { this.description = description } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { this.additionalBodyProperties.clear() - this.additionalBodyProperties.putAll(additionalBodyProperties) + putAllAdditionalBodyProperties(additionalBodyProperties) } fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - this.additionalBodyProperties.put(key, value) + additionalBodyProperties.put(key, value) } fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = @@ -260,13 +320,21 @@ constructor( this.additionalBodyProperties.putAll(additionalBodyProperties) } + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + fun build(): ProjectCreateParams = ProjectCreateParams( checkNotNull(name) { "`name` is required but was not set" }, checkNotNull(taskType) { "`taskType` is required but was not set" }, description, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), additionalBodyProperties.toImmutable(), ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectInferencePipelineCreateParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectInferencePipelineCreateParams.kt index bcb0647..cc96492 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectInferencePipelineCreateParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectInferencePipelineCreateParams.kt @@ -12,6 +12,8 @@ import com.openlayer.api.core.ExcludeMissing import com.openlayer.api.core.JsonField import com.openlayer.api.core.JsonValue import com.openlayer.api.core.NoAutoDetect +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.core.toImmutable import com.openlayer.api.errors.OpenlayerInvalidDataException import com.openlayer.api.models.* @@ -23,8 +25,8 @@ constructor( private val projectId: String, private val description: String?, private val name: String, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) { @@ -43,9 +45,9 @@ constructor( ) } - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -145,9 +147,9 @@ constructor( "ProjectInferencePipelineCreateBody{description=$description, name=$name, additionalProperties=$additionalProperties}" } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams fun _additionalBodyProperties(): Map = additionalBodyProperties @@ -156,15 +158,15 @@ constructor( return true } - return /* spotless:off */ other is ProjectInferencePipelineCreateParams && this.projectId == other.projectId && this.description == other.description && this.name == other.name && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return /* spotless:off */ other is ProjectInferencePipelineCreateParams && this.projectId == other.projectId && this.description == other.description && this.name == other.name && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(projectId, description, name, additionalQueryParams, additionalHeaders, additionalBodyProperties) /* spotless:on */ + return /* spotless:off */ Objects.hash(projectId, description, name, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ } override fun toString() = - "ProjectInferencePipelineCreateParams{projectId=$projectId, description=$description, name=$name, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}" + "ProjectInferencePipelineCreateParams{projectId=$projectId, description=$description, name=$name, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" fun toBuilder() = Builder().from(this) @@ -179,8 +181,8 @@ constructor( private var projectId: String? = null private var description: String? = null private var name: String? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() private var additionalBodyProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -190,8 +192,8 @@ constructor( this.projectId = projectInferencePipelineCreateParams.projectId this.description = projectInferencePipelineCreateParams.description this.name = projectInferencePipelineCreateParams.name - additionalQueryParams(projectInferencePipelineCreateParams.additionalQueryParams) additionalHeaders(projectInferencePipelineCreateParams.additionalHeaders) + additionalQueryParams(projectInferencePipelineCreateParams.additionalQueryParams) additionalBodyProperties(projectInferencePipelineCreateParams.additionalBodyProperties) } @@ -203,53 +205,111 @@ constructor( /** The inference pipeline name. */ fun name(name: String) = apply { this.name = name } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { this.additionalBodyProperties.clear() - this.additionalBodyProperties.putAll(additionalBodyProperties) + putAllAdditionalBodyProperties(additionalBodyProperties) } fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - this.additionalBodyProperties.put(key, value) + additionalBodyProperties.put(key, value) } fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = @@ -257,13 +317,21 @@ constructor( this.additionalBodyProperties.putAll(additionalBodyProperties) } + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + fun build(): ProjectInferencePipelineCreateParams = ProjectInferencePipelineCreateParams( checkNotNull(projectId) { "`projectId` is required but was not set" }, description, checkNotNull(name) { "`name` is required but was not set" }, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), additionalBodyProperties.toImmutable(), ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectInferencePipelineListParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectInferencePipelineListParams.kt index 11a6f61..a31fa56 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectInferencePipelineListParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectInferencePipelineListParams.kt @@ -3,7 +3,8 @@ package com.openlayer.api.models import com.openlayer.api.core.NoAutoDetect -import com.openlayer.api.core.toImmutable +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.models.* import java.util.Objects import java.util.Optional @@ -14,8 +15,8 @@ constructor( private val name: String?, private val page: Long?, private val perPage: Long?, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, ) { fun projectId(): String = projectId @@ -26,18 +27,18 @@ constructor( fun perPage(): Optional = Optional.ofNullable(perPage) + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.name?.let { params.put("name", listOf(it.toString())) } - this.page?.let { params.put("page", listOf(it.toString())) } - this.perPage?.let { params.put("perPage", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.name?.let { queryParams.put("name", listOf(it.toString())) } + this.page?.let { queryParams.put("page", listOf(it.toString())) } + this.perPage?.let { queryParams.put("perPage", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - fun getPathParam(index: Int): String { return when (index) { 0 -> projectId @@ -45,24 +46,24 @@ constructor( } } - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ProjectInferencePipelineListParams && this.projectId == other.projectId && this.name == other.name && this.page == other.page && this.perPage == other.perPage && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders /* spotless:on */ + return /* spotless:off */ other is ProjectInferencePipelineListParams && this.projectId == other.projectId && this.name == other.name && this.page == other.page && this.perPage == other.perPage && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(projectId, name, page, perPage, additionalQueryParams, additionalHeaders) /* spotless:on */ + return /* spotless:off */ Objects.hash(projectId, name, page, perPage, additionalHeaders, additionalQueryParams) /* spotless:on */ } override fun toString() = - "ProjectInferencePipelineListParams{projectId=$projectId, name=$name, page=$page, perPage=$perPage, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders}" + "ProjectInferencePipelineListParams{projectId=$projectId, name=$name, page=$page, perPage=$perPage, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" fun toBuilder() = Builder().from(this) @@ -78,8 +79,8 @@ constructor( private var name: String? = null private var page: Long? = null private var perPage: Long? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(projectInferencePipelineListParams: ProjectInferencePipelineListParams) = @@ -88,8 +89,8 @@ constructor( this.name = projectInferencePipelineListParams.name this.page = projectInferencePipelineListParams.page this.perPage = projectInferencePipelineListParams.perPage - additionalQueryParams(projectInferencePipelineListParams.additionalQueryParams) additionalHeaders(projectInferencePipelineListParams.additionalHeaders) + additionalQueryParams(projectInferencePipelineListParams.additionalQueryParams) } fun projectId(projectId: String) = apply { this.projectId = projectId } @@ -103,45 +104,103 @@ constructor( /** Maximum number of items to return per page. */ fun perPage(perPage: Long) = apply { this.perPage = perPage } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun build(): ProjectInferencePipelineListParams = ProjectInferencePipelineListParams( @@ -149,8 +208,8 @@ constructor( name, page, perPage, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectListParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectListParams.kt index f4ee878..549ccf6 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectListParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/ProjectListParams.kt @@ -7,7 +7,8 @@ import com.openlayer.api.core.Enum import com.openlayer.api.core.JsonField import com.openlayer.api.core.JsonValue import com.openlayer.api.core.NoAutoDetect -import com.openlayer.api.core.toImmutable +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.errors.OpenlayerInvalidDataException import com.openlayer.api.models.* import java.util.Objects @@ -19,8 +20,8 @@ constructor( private val page: Long?, private val perPage: Long?, private val taskType: TaskType?, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, ) { fun name(): Optional = Optional.ofNullable(name) @@ -31,37 +32,37 @@ constructor( fun taskType(): Optional = Optional.ofNullable(taskType) + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.name?.let { params.put("name", listOf(it.toString())) } - this.page?.let { params.put("page", listOf(it.toString())) } - this.perPage?.let { params.put("perPage", listOf(it.toString())) } - this.taskType?.let { params.put("taskType", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.name?.let { queryParams.put("name", listOf(it.toString())) } + this.page?.let { queryParams.put("page", listOf(it.toString())) } + this.perPage?.let { queryParams.put("perPage", listOf(it.toString())) } + this.taskType?.let { queryParams.put("taskType", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams override fun equals(other: Any?): Boolean { if (this === other) { return true } - return /* spotless:off */ other is ProjectListParams && this.name == other.name && this.page == other.page && this.perPage == other.perPage && this.taskType == other.taskType && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders /* spotless:on */ + return /* spotless:off */ other is ProjectListParams && this.name == other.name && this.page == other.page && this.perPage == other.perPage && this.taskType == other.taskType && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(name, page, perPage, taskType, additionalQueryParams, additionalHeaders) /* spotless:on */ + return /* spotless:off */ Objects.hash(name, page, perPage, taskType, additionalHeaders, additionalQueryParams) /* spotless:on */ } override fun toString() = - "ProjectListParams{name=$name, page=$page, perPage=$perPage, taskType=$taskType, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders}" + "ProjectListParams{name=$name, page=$page, perPage=$perPage, taskType=$taskType, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" fun toBuilder() = Builder().from(this) @@ -77,8 +78,8 @@ constructor( private var page: Long? = null private var perPage: Long? = null private var taskType: TaskType? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(projectListParams: ProjectListParams) = apply { @@ -86,8 +87,8 @@ constructor( this.page = projectListParams.page this.perPage = projectListParams.perPage this.taskType = projectListParams.taskType - additionalQueryParams(projectListParams.additionalQueryParams) additionalHeaders(projectListParams.additionalHeaders) + additionalQueryParams(projectListParams.additionalQueryParams) } /** Filter list of items by project name. */ @@ -102,45 +103,103 @@ constructor( /** Filter list of items by task type. */ fun taskType(taskType: TaskType) = apply { this.taskType = taskType } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun build(): ProjectListParams = ProjectListParams( @@ -148,8 +207,8 @@ constructor( page, perPage, taskType, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/StoragePresignedUrlCreateParams.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/StoragePresignedUrlCreateParams.kt index 0e38f68..942acb5 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/StoragePresignedUrlCreateParams.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/models/StoragePresignedUrlCreateParams.kt @@ -4,6 +4,8 @@ package com.openlayer.api.models import com.openlayer.api.core.JsonValue import com.openlayer.api.core.NoAutoDetect +import com.openlayer.api.core.http.Headers +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.core.toImmutable import com.openlayer.api.models.* import java.util.Objects @@ -12,8 +14,8 @@ import java.util.Optional class StoragePresignedUrlCreateParams constructor( private val objectName: String, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, private val additionalBodyProperties: Map, ) { @@ -24,19 +26,19 @@ constructor( return Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) } + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.objectName.let { params.put("objectName", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.objectName.let { queryParams.put("objectName", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams fun _additionalBodyProperties(): Map = additionalBodyProperties @@ -45,15 +47,15 @@ constructor( return true } - return /* spotless:off */ other is StoragePresignedUrlCreateParams && this.objectName == other.objectName && this.additionalQueryParams == other.additionalQueryParams && this.additionalHeaders == other.additionalHeaders && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return /* spotless:off */ other is StoragePresignedUrlCreateParams && this.objectName == other.objectName && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ } override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(objectName, additionalQueryParams, additionalHeaders, additionalBodyProperties) /* spotless:on */ + return /* spotless:off */ Objects.hash(objectName, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ } override fun toString() = - "StoragePresignedUrlCreateParams{objectName=$objectName, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}" + "StoragePresignedUrlCreateParams{objectName=$objectName, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" fun toBuilder() = Builder().from(this) @@ -66,69 +68,127 @@ constructor( class Builder { private var objectName: String? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() private var additionalBodyProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(storagePresignedUrlCreateParams: StoragePresignedUrlCreateParams) = apply { this.objectName = storagePresignedUrlCreateParams.objectName - additionalQueryParams(storagePresignedUrlCreateParams.additionalQueryParams) additionalHeaders(storagePresignedUrlCreateParams.additionalHeaders) + additionalQueryParams(storagePresignedUrlCreateParams.additionalQueryParams) additionalBodyProperties(storagePresignedUrlCreateParams.additionalBodyProperties) } /** The name of the object. */ fun objectName(objectName: String) = apply { this.objectName = objectName } - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) } - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) } - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) } - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) } - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { this.additionalBodyProperties.clear() - this.additionalBodyProperties.putAll(additionalBodyProperties) + putAllAdditionalBodyProperties(additionalBodyProperties) } fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - this.additionalBodyProperties.put(key, value) + additionalBodyProperties.put(key, value) } fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = @@ -136,11 +196,19 @@ constructor( this.additionalBodyProperties.putAll(additionalBodyProperties) } + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + fun build(): StoragePresignedUrlCreateParams = StoragePresignedUrlCreateParams( checkNotNull(objectName) { "`objectName` is required but was not set" }, - additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(), - additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), additionalBodyProperties.toImmutable(), ) } diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/InferencePipelineServiceAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/InferencePipelineServiceAsyncImpl.kt index e462991..62b8afb 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/InferencePipelineServiceAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/InferencePipelineServiceAsyncImpl.kt @@ -61,9 +61,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("inference-pipelines", params.getPathParam(0)) .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response -> @@ -91,9 +91,9 @@ constructor( .method(HttpMethod.PUT) .addPathSegments("inference-pipelines", params.getPathParam(0)) .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response @@ -120,9 +120,9 @@ constructor( .method(HttpMethod.DELETE) .addPathSegments("inference-pipelines", params.getPathParam(0)) .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .apply { params.getBody().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/ProjectServiceAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/ProjectServiceAsyncImpl.kt index 373608c..ac41df9 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/ProjectServiceAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/ProjectServiceAsyncImpl.kt @@ -52,9 +52,9 @@ constructor( .method(HttpMethod.POST) .addPathSegments("projects") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response @@ -82,9 +82,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("projects") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response -> diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/commits/TestResultServiceAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/commits/TestResultServiceAsyncImpl.kt index 5751b5b..9c554b1 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/commits/TestResultServiceAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/commits/TestResultServiceAsyncImpl.kt @@ -36,9 +36,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("versions", params.getPathParam(0), "results") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response -> diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/DataServiceAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/DataServiceAsyncImpl.kt index 8603c03..cc3c822 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/DataServiceAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/DataServiceAsyncImpl.kt @@ -37,9 +37,9 @@ constructor( .method(HttpMethod.POST) .addPathSegments("inference-pipelines", params.getPathParam(0), "data-stream") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/RowServiceAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/RowServiceAsyncImpl.kt index 9e59f90..a54c268 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/RowServiceAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/RowServiceAsyncImpl.kt @@ -37,9 +37,9 @@ constructor( .method(HttpMethod.PUT) .addPathSegments("inference-pipelines", params.getPathParam(0), "rows") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/TestResultServiceAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/TestResultServiceAsyncImpl.kt index 86768cd..2474a45 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/TestResultServiceAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/inferencePipelines/TestResultServiceAsyncImpl.kt @@ -36,9 +36,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("inference-pipelines", params.getPathParam(0), "results") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response -> diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/projects/CommitServiceAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/projects/CommitServiceAsyncImpl.kt index 9dcce15..b0440f4 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/projects/CommitServiceAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/projects/CommitServiceAsyncImpl.kt @@ -39,9 +39,9 @@ constructor( .method(HttpMethod.POST) .addPathSegments("projects", params.getPathParam(0), "versions") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response @@ -70,9 +70,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("projects", params.getPathParam(0), "versions") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response -> diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/projects/InferencePipelineServiceAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/projects/InferencePipelineServiceAsyncImpl.kt index 684645c..e02d123 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/projects/InferencePipelineServiceAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/projects/InferencePipelineServiceAsyncImpl.kt @@ -39,9 +39,9 @@ constructor( .method(HttpMethod.POST) .addPathSegments("projects", params.getPathParam(0), "inference-pipelines") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response @@ -70,9 +70,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("projects", params.getPathParam(0), "inference-pipelines") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response -> diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/storage/PresignedUrlServiceAsyncImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/storage/PresignedUrlServiceAsyncImpl.kt index 8eba2ce..89153fd 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/storage/PresignedUrlServiceAsyncImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/async/storage/PresignedUrlServiceAsyncImpl.kt @@ -37,9 +37,9 @@ constructor( .method(HttpMethod.POST) .addPathSegments("storage", "presigned-url") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .apply { params.getBody().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/InferencePipelineServiceImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/InferencePipelineServiceImpl.kt index 1a94ff3..40eb3ee 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/InferencePipelineServiceImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/InferencePipelineServiceImpl.kt @@ -58,9 +58,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("inference-pipelines", params.getPathParam(0)) .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> response @@ -87,9 +87,9 @@ constructor( .method(HttpMethod.PUT) .addPathSegments("inference-pipelines", params.getPathParam(0)) .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> @@ -112,9 +112,9 @@ constructor( .method(HttpMethod.DELETE) .addPathSegments("inference-pipelines", params.getPathParam(0)) .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .apply { params.getBody().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() clientOptions.httpClient.execute(request, requestOptions).let { response -> diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/ProjectServiceImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/ProjectServiceImpl.kt index 52fe825..b90d15a 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/ProjectServiceImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/ProjectServiceImpl.kt @@ -51,9 +51,9 @@ constructor( .method(HttpMethod.POST) .addPathSegments("projects") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> @@ -80,9 +80,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("projects") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> response diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/commits/TestResultServiceImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/commits/TestResultServiceImpl.kt index 6adb5c2..272c1f5 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/commits/TestResultServiceImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/commits/TestResultServiceImpl.kt @@ -35,9 +35,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("versions", params.getPathParam(0), "results") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> response diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/DataServiceImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/DataServiceImpl.kt index e403f4e..b330931 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/DataServiceImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/DataServiceImpl.kt @@ -36,9 +36,9 @@ constructor( .method(HttpMethod.POST) .addPathSegments("inference-pipelines", params.getPathParam(0), "data-stream") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/RowServiceImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/RowServiceImpl.kt index 4ea0120..537d7da 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/RowServiceImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/RowServiceImpl.kt @@ -36,9 +36,9 @@ constructor( .method(HttpMethod.PUT) .addPathSegments("inference-pipelines", params.getPathParam(0), "rows") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/TestResultServiceImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/TestResultServiceImpl.kt index 1fdc808..ac76753 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/TestResultServiceImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/inferencePipelines/TestResultServiceImpl.kt @@ -35,9 +35,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("inference-pipelines", params.getPathParam(0), "results") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> response diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/projects/CommitServiceImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/projects/CommitServiceImpl.kt index b7b7716..283067f 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/projects/CommitServiceImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/projects/CommitServiceImpl.kt @@ -38,9 +38,9 @@ constructor( .method(HttpMethod.POST) .addPathSegments("projects", params.getPathParam(0), "versions") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> @@ -68,9 +68,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("projects", params.getPathParam(0), "versions") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> response diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/projects/InferencePipelineServiceImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/projects/InferencePipelineServiceImpl.kt index c0bd16f..2226840 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/projects/InferencePipelineServiceImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/projects/InferencePipelineServiceImpl.kt @@ -38,9 +38,9 @@ constructor( .method(HttpMethod.POST) .addPathSegments("projects", params.getPathParam(0), "inference-pipelines") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .body(json(clientOptions.jsonMapper, params.getBody())) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> @@ -68,9 +68,9 @@ constructor( .method(HttpMethod.GET) .addPathSegments("projects", params.getPathParam(0), "inference-pipelines") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> response diff --git a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/storage/PresignedUrlServiceImpl.kt b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/storage/PresignedUrlServiceImpl.kt index ff12abd..e89676f 100644 --- a/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/storage/PresignedUrlServiceImpl.kt +++ b/openlayer-java-core/src/main/kotlin/com/openlayer/api/services/blocking/storage/PresignedUrlServiceImpl.kt @@ -36,9 +36,9 @@ constructor( .method(HttpMethod.POST) .addPathSegments("storage", "presigned-url") .putAllQueryParams(clientOptions.queryParams) - .putAllQueryParams(params.getQueryParams()) + .replaceAllQueryParams(params.getQueryParams()) .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) + .replaceAllHeaders(params.getHeaders()) .apply { params.getBody().ifPresent { body(json(clientOptions.jsonMapper, it)) } } .build() return clientOptions.httpClient.execute(request, requestOptions).let { response -> diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/core/http/HeadersTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/core/http/HeadersTest.kt new file mode 100644 index 0000000..0780679 --- /dev/null +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/core/http/HeadersTest.kt @@ -0,0 +1,274 @@ +package com.openlayer.api.core.http + +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.catchThrowable +import org.assertj.core.api.Assumptions.assumeThat +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class HeadersTest { + + enum class TestCase( + val headers: Headers, + val expectedMap: Map>, + val expectedSize: Int + ) { + EMPTY(Headers.builder().build(), expectedMap = mapOf(), expectedSize = 0), + PUT_ONE( + Headers.builder().put("name", "value").build(), + expectedMap = mapOf("name" to listOf("value")), + expectedSize = 1 + ), + PUT_MULTIPLE( + Headers.builder().put("name", listOf("value1", "value2")).build(), + expectedMap = mapOf("name" to listOf("value1", "value2")), + expectedSize = 2 + ), + MULTIPLE_PUT( + Headers.builder().put("name1", "value").put("name2", "value").build(), + expectedMap = mapOf("name1" to listOf("value"), "name2" to listOf("value")), + expectedSize = 2 + ), + MULTIPLE_PUT_SAME_NAME( + Headers.builder().put("name", "value1").put("name", "value2").build(), + expectedMap = mapOf("name" to listOf("value1", "value2")), + expectedSize = 2 + ), + MULTIPLE_PUT_MULTIPLE( + Headers.builder() + .put("name", listOf("value1", "value2")) + .put("name", listOf("value1", "value2")) + .build(), + expectedMap = mapOf("name" to listOf("value1", "value2", "value1", "value2")), + expectedSize = 4 + ), + PUT_CASE_INSENSITIVE( + Headers.builder() + .put("name", "value1") + .put("NAME", "value2") + .put("nAmE", "value3") + .build(), + expectedMap = mapOf("name" to listOf("value1", "value2", "value3")), + expectedSize = 3 + ), + PUT_ALL_MAP( + Headers.builder() + .putAll( + mapOf( + "name1" to listOf("value1", "value2"), + "name2" to listOf("value1", "value2") + ) + ) + .build(), + expectedMap = + mapOf("name1" to listOf("value1", "value2"), "name2" to listOf("value1", "value2")), + expectedSize = 4 + ), + PUT_ALL_HEADERS( + Headers.builder().putAll(Headers.builder().put("name", "value").build()).build(), + expectedMap = mapOf("name" to listOf("value")), + expectedSize = 1 + ), + PUT_ALL_CASE_INSENSITIVE( + Headers.builder() + .putAll( + mapOf( + "name" to listOf("value1"), + "NAME" to listOf("value2"), + "nAmE" to listOf("value3") + ) + ) + .build(), + expectedMap = mapOf("name" to listOf("value1", "value2", "value3")), + expectedSize = 3 + ), + REMOVE_ABSENT( + Headers.builder().remove("name").build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + REMOVE_PRESENT_ONE( + Headers.builder().put("name", "value").remove("name").build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + REMOVE_PRESENT_MULTIPLE( + Headers.builder().put("name", listOf("value1", "value2")).remove("name").build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + REMOVE_CASE_INSENSITIVE( + Headers.builder().put("name", listOf("value1", "value2")).remove("NAME").build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + REMOVE_ALL( + Headers.builder() + .put("name1", "value") + .put("name3", "value") + .removeAll(setOf("name1", "name2", "name3")) + .build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + REMOVE_ALL_CASE_INSENSITIVE( + Headers.builder() + .put("name1", "value") + .put("name3", "value") + .removeAll(setOf("NAME1", "nAmE3")) + .build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + CLEAR( + Headers.builder().put("name1", "value").put("name2", "value").clear().build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + REPLACE_ONE_ABSENT( + Headers.builder().replace("name", "value").build(), + expectedMap = mapOf("name" to listOf("value")), + expectedSize = 1 + ), + REPLACE_ONE_PRESENT_ONE( + Headers.builder().put("name", "value1").replace("name", "value2").build(), + expectedMap = mapOf("name" to listOf("value2")), + expectedSize = 1 + ), + REPLACE_ONE_PRESENT_MULTIPLE( + Headers.builder() + .put("name", listOf("value1", "value2")) + .replace("name", "value3") + .build(), + expectedMap = mapOf("name" to listOf("value3")), + expectedSize = 1 + ), + REPLACE_MULTIPLE_ABSENT( + Headers.builder().replace("name", listOf("value1", "value2")).build(), + expectedMap = mapOf("name" to listOf("value1", "value2")), + expectedSize = 2 + ), + REPLACE_MULTIPLE_PRESENT_ONE( + Headers.builder() + .put("name", "value1") + .replace("name", listOf("value2", "value3")) + .build(), + expectedMap = mapOf("name" to listOf("value2", "value3")), + expectedSize = 2 + ), + REPLACE_MULTIPLE_PRESENT_MULTIPLE( + Headers.builder() + .put("name", listOf("value1", "value2")) + .replace("name", listOf("value3", "value4")) + .build(), + expectedMap = mapOf("name" to listOf("value3", "value4")), + expectedSize = 2 + ), + REPLACE_CASE_INSENSITIVE( + Headers.builder() + .put("name", "value1") + .replace("NAME", listOf("value2", "value3")) + .build(), + expectedMap = mapOf("NAME" to listOf("value2", "value3")), + expectedSize = 2 + ), + REPLACE_ALL_MAP( + Headers.builder() + .put("name1", "value1") + .put("name2", "value1") + .put("name3", "value1") + .replaceAll(mapOf("name1" to listOf("value2"), "name3" to listOf("value2"))) + .build(), + expectedMap = + mapOf( + "name1" to listOf("value2"), + "name2" to listOf("value1"), + "name3" to listOf("value2") + ), + expectedSize = 3 + ), + REPLACE_ALL_HEADERS( + Headers.builder() + .put("name1", "value1") + .put("name2", "value1") + .put("name3", "value1") + .replaceAll(Headers.builder().put("name1", "value2").put("name3", "value2").build()) + .build(), + expectedMap = + mapOf( + "name1" to listOf("value2"), + "name2" to listOf("value1"), + "name3" to listOf("value2") + ), + expectedSize = 3 + ), + REPLACE_ALL_CASE_INSENSITIVE( + Headers.builder() + .put("name1", "value1") + .put("name2", "value1") + .replaceAll(mapOf("NAME1" to listOf("value2"), "nAmE2" to listOf("value2"))) + .build(), + expectedMap = mapOf("NAME1" to listOf("value2"), "nAmE2" to listOf("value2")), + expectedSize = 2 + ) + } + + @ParameterizedTest + @EnumSource + fun namesAndValues(testCase: TestCase) { + val map = mutableMapOf>() + val headers = testCase.headers + headers.names().forEach { name -> map[name] = headers.values(name) } + + assertThat(map).isEqualTo(testCase.expectedMap) + } + + @ParameterizedTest + @EnumSource + fun caseInsensitiveNames(testCase: TestCase) { + val headers = testCase.headers + + for (name in headers.names()) { + assertThat(headers.values(name)).isEqualTo(headers.values(name.lowercase())) + assertThat(headers.values(name)).isEqualTo(headers.values(name.uppercase())) + } + } + + @ParameterizedTest + @EnumSource + fun size(testCase: TestCase) { + val size = testCase.headers.size + + assertThat(size).isEqualTo(testCase.expectedSize) + } + + @ParameterizedTest + @EnumSource + fun namesAreImmutable(testCase: TestCase) { + val headers = testCase.headers + val headerNamesCopy = headers.names().toSet() + + val throwable = catchThrowable { + (headers.names() as MutableSet).add("another name") + } + + assertThat(throwable).isInstanceOf(UnsupportedOperationException::class.java) + assertThat(headers.names()).isEqualTo(headerNamesCopy) + } + + @ParameterizedTest + @EnumSource + fun valuesAreImmutable(testCase: TestCase) { + val headers = testCase.headers + assumeThat(headers.size).isNotEqualTo(0) + val name = headers.names().first() + val headerValuesCopy = headers.values(name).toList() + + val throwable = catchThrowable { + (headers.values(name) as MutableList).add("another value") + } + + assertThat(throwable).isInstanceOf(UnsupportedOperationException::class.java) + assertThat(headers.values(name)).isEqualTo(headerValuesCopy) + } +} diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/core/http/HttpRequestTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/core/http/HttpRequestTest.kt deleted file mode 100644 index fe7fc1c..0000000 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/core/http/HttpRequestTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.openlayer.api.core.http - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class HttpRequestTest { - - @Test - fun caseInsensitiveHeadersAccessors() { - val request = - HttpRequest.builder() - .method(HttpMethod.POST) - .putHeader("something_lowercase", "lowercase") - .putHeader("Something_Capitalized", "Capitalized") - .putHeader("SOMETHING_UPPERCASE", "UPPERCASE") - .build() - assertThat(request.headers.get("SOMETHING_LOWERCASE").getOrNull(0)).isEqualTo("lowercase") - assertThat(request.headers.get("something_capitalized").getOrNull(0)) - .isEqualTo("Capitalized") - assertThat(request.headers.get("Something_Uppercase").getOrNull(0)).isEqualTo("UPPERCASE") - } -} diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/core/http/QueryParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/core/http/QueryParamsTest.kt new file mode 100644 index 0000000..7db575e --- /dev/null +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/core/http/QueryParamsTest.kt @@ -0,0 +1,212 @@ +package com.openlayer.api.core.http + +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.catchThrowable +import org.assertj.core.api.Assumptions.assumeThat +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class QueryParamsTest { + + enum class TestCase( + val queryParams: QueryParams, + val expectedMap: Map>, + val expectedSize: Int + ) { + EMPTY(QueryParams.builder().build(), expectedMap = mapOf(), expectedSize = 0), + PUT_ONE( + QueryParams.builder().put("key", "value").build(), + expectedMap = mapOf("key" to listOf("value")), + expectedSize = 1 + ), + PUT_MULTIPLE( + QueryParams.builder().put("key", listOf("value1", "value2")).build(), + expectedMap = mapOf("key" to listOf("value1", "value2")), + expectedSize = 2 + ), + MULTIPLE_PUT( + QueryParams.builder().put("key1", "value").put("key2", "value").build(), + expectedMap = mapOf("key1" to listOf("value"), "key2" to listOf("value")), + expectedSize = 2 + ), + MULTIPLE_PUT_SAME_NAME( + QueryParams.builder().put("key", "value1").put("key", "value2").build(), + expectedMap = mapOf("key" to listOf("value1", "value2")), + expectedSize = 2 + ), + MULTIPLE_PUT_MULTIPLE( + QueryParams.builder() + .put("key", listOf("value1", "value2")) + .put("key", listOf("value1", "value2")) + .build(), + expectedMap = mapOf("key" to listOf("value1", "value2", "value1", "value2")), + expectedSize = 4 + ), + PUT_ALL_MAP( + QueryParams.builder() + .putAll( + mapOf( + "key1" to listOf("value1", "value2"), + "key2" to listOf("value1", "value2") + ) + ) + .build(), + expectedMap = + mapOf("key1" to listOf("value1", "value2"), "key2" to listOf("value1", "value2")), + expectedSize = 4 + ), + PUT_ALL_HEADERS( + QueryParams.builder().putAll(QueryParams.builder().put("key", "value").build()).build(), + expectedMap = mapOf("key" to listOf("value")), + expectedSize = 1 + ), + REMOVE_ABSENT( + QueryParams.builder().remove("key").build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + REMOVE_PRESENT_ONE( + QueryParams.builder().put("key", "value").remove("key").build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + REMOVE_PRESENT_MULTIPLE( + QueryParams.builder().put("key", listOf("value1", "value2")).remove("key").build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + REMOVE_ALL( + QueryParams.builder() + .put("key1", "value") + .put("key3", "value") + .removeAll(setOf("key1", "key2", "key3")) + .build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + CLEAR( + QueryParams.builder().put("key1", "value").put("key2", "value").clear().build(), + expectedMap = mapOf(), + expectedSize = 0 + ), + REPLACE_ONE_ABSENT( + QueryParams.builder().replace("key", "value").build(), + expectedMap = mapOf("key" to listOf("value")), + expectedSize = 1 + ), + REPLACE_ONE_PRESENT_ONE( + QueryParams.builder().put("key", "value1").replace("key", "value2").build(), + expectedMap = mapOf("key" to listOf("value2")), + expectedSize = 1 + ), + REPLACE_ONE_PRESENT_MULTIPLE( + QueryParams.builder() + .put("key", listOf("value1", "value2")) + .replace("key", "value3") + .build(), + expectedMap = mapOf("key" to listOf("value3")), + expectedSize = 1 + ), + REPLACE_MULTIPLE_ABSENT( + QueryParams.builder().replace("key", listOf("value1", "value2")).build(), + expectedMap = mapOf("key" to listOf("value1", "value2")), + expectedSize = 2 + ), + REPLACE_MULTIPLE_PRESENT_ONE( + QueryParams.builder() + .put("key", "value1") + .replace("key", listOf("value2", "value3")) + .build(), + expectedMap = mapOf("key" to listOf("value2", "value3")), + expectedSize = 2 + ), + REPLACE_MULTIPLE_PRESENT_MULTIPLE( + QueryParams.builder() + .put("key", listOf("value1", "value2")) + .replace("key", listOf("value3", "value4")) + .build(), + expectedMap = mapOf("key" to listOf("value3", "value4")), + expectedSize = 2 + ), + REPLACE_ALL_MAP( + QueryParams.builder() + .put("key1", "value1") + .put("key2", "value1") + .put("key3", "value1") + .replaceAll(mapOf("key1" to listOf("value2"), "key3" to listOf("value2"))) + .build(), + expectedMap = + mapOf( + "key1" to listOf("value2"), + "key2" to listOf("value1"), + "key3" to listOf("value2") + ), + expectedSize = 3 + ), + REPLACE_ALL_HEADERS( + QueryParams.builder() + .put("key1", "value1") + .put("key2", "value1") + .put("key3", "value1") + .replaceAll( + QueryParams.builder().put("key1", "value2").put("key3", "value2").build() + ) + .build(), + expectedMap = + mapOf( + "key1" to listOf("value2"), + "key2" to listOf("value1"), + "key3" to listOf("value2") + ), + expectedSize = 3 + ) + } + + @ParameterizedTest + @EnumSource + fun keysAndValues(testCase: TestCase) { + val map = mutableMapOf>() + val queryParams = testCase.queryParams + queryParams.keys().forEach { key -> map[key] = queryParams.values(key) } + + assertThat(map).isEqualTo(testCase.expectedMap) + } + + @ParameterizedTest + @EnumSource + fun size(testCase: TestCase) { + val size = testCase.queryParams.size + + assertThat(size).isEqualTo(testCase.expectedSize) + } + + @ParameterizedTest + @EnumSource + fun keysAreImmutable(testCase: TestCase) { + val queryParams = testCase.queryParams + val queryParamKeysCopy = queryParams.keys().toSet() + + val throwable = catchThrowable { + (queryParams.keys() as MutableSet).add("another key") + } + + assertThat(throwable).isInstanceOf(UnsupportedOperationException::class.java) + assertThat(queryParams.keys()).isEqualTo(queryParamKeysCopy) + } + + @ParameterizedTest + @EnumSource + fun valuesAreImmutable(testCase: TestCase) { + val queryParams = testCase.queryParams + assumeThat(queryParams.size).isNotEqualTo(0) + val key = queryParams.keys().first() + val queryParamValuesCopy = queryParams.values(key).toList() + + val throwable = catchThrowable { + (queryParams.values(key) as MutableList).add("another value") + } + + assertThat(throwable).isInstanceOf(UnsupportedOperationException::class.java) + assertThat(queryParams.values(key)).isEqualTo(queryParamValuesCopy) + } +} diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitTestResultListParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitTestResultListParamsTest.kt index a011d78..01f9c0f 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitTestResultListParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/CommitTestResultListParamsTest.kt @@ -2,6 +2,7 @@ package com.openlayer.api.models +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.models.* import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -31,13 +32,13 @@ class CommitTestResultListParamsTest { .status(CommitTestResultListParams.Status.RUNNING) .type(CommitTestResultListParams.Type.INTEGRITY) .build() - val expected = mutableMapOf>() - expected.put("includeArchived", listOf("true")) - expected.put("page", listOf("123")) - expected.put("perPage", listOf("100")) - expected.put("status", listOf(CommitTestResultListParams.Status.RUNNING.toString())) - expected.put("type", listOf(CommitTestResultListParams.Type.INTEGRITY.toString())) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("includeArchived", "true") + expected.put("page", "123") + expected.put("perPage", "100") + expected.put("status", CommitTestResultListParams.Status.RUNNING.toString()) + expected.put("type", CommitTestResultListParams.Type.INTEGRITY.toString()) + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test @@ -46,8 +47,8 @@ class CommitTestResultListParamsTest { CommitTestResultListParams.builder() .projectVersionId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/InferencePipelineRowUpdateParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/InferencePipelineRowUpdateParamsTest.kt index f4a70bf..85150f7 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/InferencePipelineRowUpdateParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/InferencePipelineRowUpdateParamsTest.kt @@ -3,6 +3,7 @@ package com.openlayer.api.models import com.openlayer.api.core.JsonValue +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.models.* import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -44,9 +45,9 @@ class InferencePipelineRowUpdateParamsTest { ) .inferenceId("inferenceId") .build() - val expected = mutableMapOf>() - expected.put("inferenceId", listOf("inferenceId")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("inferenceId", "inferenceId") + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test @@ -57,9 +58,9 @@ class InferencePipelineRowUpdateParamsTest { .row(JsonValue.from(mapOf())) .inferenceId("inferenceId") .build() - val expected = mutableMapOf>() - expected.put("inferenceId", listOf("inferenceId")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("inferenceId", "inferenceId") + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/InferencePipelineTestResultListParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/InferencePipelineTestResultListParamsTest.kt index 6de2ac0..e71d307 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/InferencePipelineTestResultListParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/InferencePipelineTestResultListParamsTest.kt @@ -2,6 +2,7 @@ package com.openlayer.api.models +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.models.* import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -29,18 +30,12 @@ class InferencePipelineTestResultListParamsTest { .status(InferencePipelineTestResultListParams.Status.RUNNING) .type(InferencePipelineTestResultListParams.Type.INTEGRITY) .build() - val expected = mutableMapOf>() - expected.put("page", listOf("123")) - expected.put("perPage", listOf("100")) - expected.put( - "status", - listOf(InferencePipelineTestResultListParams.Status.RUNNING.toString()) - ) - expected.put( - "type", - listOf(InferencePipelineTestResultListParams.Type.INTEGRITY.toString()) - ) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("page", "123") + expected.put("perPage", "100") + expected.put("status", InferencePipelineTestResultListParams.Status.RUNNING.toString()) + expected.put("type", InferencePipelineTestResultListParams.Type.INTEGRITY.toString()) + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test @@ -49,8 +44,8 @@ class InferencePipelineTestResultListParamsTest { InferencePipelineTestResultListParams.builder() .inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectCommitListParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectCommitListParamsTest.kt index 17d2e0a..1b5e9c5 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectCommitListParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectCommitListParamsTest.kt @@ -2,6 +2,7 @@ package com.openlayer.api.models +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.models.* import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -25,10 +26,10 @@ class ProjectCommitListParamsTest { .page(123L) .perPage(100L) .build() - val expected = mutableMapOf>() - expected.put("page", listOf("123")) - expected.put("perPage", listOf("100")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("page", "123") + expected.put("perPage", "100") + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test @@ -37,8 +38,8 @@ class ProjectCommitListParamsTest { ProjectCommitListParams.builder() .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectInferencePipelineListParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectInferencePipelineListParamsTest.kt index 671b802..0197e06 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectInferencePipelineListParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectInferencePipelineListParamsTest.kt @@ -2,6 +2,7 @@ package com.openlayer.api.models +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.models.* import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -27,11 +28,11 @@ class ProjectInferencePipelineListParamsTest { .page(123L) .perPage(100L) .build() - val expected = mutableMapOf>() - expected.put("name", listOf("name")) - expected.put("page", listOf("123")) - expected.put("perPage", listOf("100")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("name", "name") + expected.put("page", "123") + expected.put("perPage", "100") + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test @@ -40,8 +41,8 @@ class ProjectInferencePipelineListParamsTest { ProjectInferencePipelineListParams.builder() .projectId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") .build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectListParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectListParamsTest.kt index daf73e7..93c9049 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectListParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/ProjectListParamsTest.kt @@ -2,6 +2,7 @@ package com.openlayer.api.models +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.models.* import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -27,18 +28,18 @@ class ProjectListParamsTest { .perPage(100L) .taskType(ProjectListParams.TaskType.LLM_BASE) .build() - val expected = mutableMapOf>() - expected.put("name", listOf("name")) - expected.put("page", listOf("123")) - expected.put("perPage", listOf("100")) - expected.put("taskType", listOf(ProjectListParams.TaskType.LLM_BASE.toString())) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("name", "name") + expected.put("page", "123") + expected.put("perPage", "100") + expected.put("taskType", ProjectListParams.TaskType.LLM_BASE.toString()) + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test fun getQueryParamsWithoutOptionalFields() { val params = ProjectListParams.builder().build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } } diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/StoragePresignedUrlCreateParamsTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/StoragePresignedUrlCreateParamsTest.kt index 6ae03e8..baa5e92 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/StoragePresignedUrlCreateParamsTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/models/StoragePresignedUrlCreateParamsTest.kt @@ -2,6 +2,7 @@ package com.openlayer.api.models +import com.openlayer.api.core.http.QueryParams import com.openlayer.api.models.* import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -16,16 +17,16 @@ class StoragePresignedUrlCreateParamsTest { @Test fun getQueryParams() { val params = StoragePresignedUrlCreateParams.builder().objectName("objectName").build() - val expected = mutableMapOf>() - expected.put("objectName", listOf("objectName")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("objectName", "objectName") + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } @Test fun getQueryParamsWithoutOptionalFields() { val params = StoragePresignedUrlCreateParams.builder().objectName("objectName").build() - val expected = mutableMapOf>() - expected.put("objectName", listOf("objectName")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("objectName", "objectName") + assertThat(params.getQueryParams()).isEqualTo(expected.build()) } } diff --git a/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/ErrorHandlingTest.kt b/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/ErrorHandlingTest.kt index 4dfd4b0..23aee00 100644 --- a/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/ErrorHandlingTest.kt +++ b/openlayer-java-core/src/test/kotlin/com/openlayer/api/services/ErrorHandlingTest.kt @@ -7,16 +7,16 @@ import com.github.tomakehurst.wiremock.client.WireMock.anyUrl import com.github.tomakehurst.wiremock.client.WireMock.get import com.github.tomakehurst.wiremock.client.WireMock.ok import com.github.tomakehurst.wiremock.client.WireMock.post +import com.github.tomakehurst.wiremock.client.WireMock.put import com.github.tomakehurst.wiremock.client.WireMock.status import com.github.tomakehurst.wiremock.client.WireMock.stubFor import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo import com.github.tomakehurst.wiremock.junit5.WireMockTest -import com.google.common.collect.ImmutableListMultimap -import com.google.common.collect.ListMultimap import com.openlayer.api.client.OpenlayerClient import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient import com.openlayer.api.core.JsonString import com.openlayer.api.core.JsonValue +import com.openlayer.api.core.http.Headers import com.openlayer.api.core.jsonMapper import com.openlayer.api.errors.BadRequestException import com.openlayer.api.errors.InternalServerException @@ -140,7 +140,7 @@ class ErrorHandlingTest { assertThatThrownBy({ client.inferencePipelines().data().stream(params) }) .satisfies({ e -> - assertBadRequest(e, ImmutableListMultimap.of("Foo", "Bar"), OPENLAYER_ERROR) + assertBadRequest(e, Headers.builder().put("Foo", "Bar").build(), OPENLAYER_ERROR) }) } @@ -185,7 +185,7 @@ class ErrorHandlingTest { assertThatThrownBy({ client.inferencePipelines().data().stream(params) }) .satisfies({ e -> - assertUnauthorized(e, ImmutableListMultimap.of("Foo", "Bar"), OPENLAYER_ERROR) + assertUnauthorized(e, Headers.builder().put("Foo", "Bar").build(), OPENLAYER_ERROR) }) } @@ -230,7 +230,11 @@ class ErrorHandlingTest { assertThatThrownBy({ client.inferencePipelines().data().stream(params) }) .satisfies({ e -> - assertPermissionDenied(e, ImmutableListMultimap.of("Foo", "Bar"), OPENLAYER_ERROR) + assertPermissionDenied( + e, + Headers.builder().put("Foo", "Bar").build(), + OPENLAYER_ERROR + ) }) } @@ -275,7 +279,7 @@ class ErrorHandlingTest { assertThatThrownBy({ client.inferencePipelines().data().stream(params) }) .satisfies({ e -> - assertNotFound(e, ImmutableListMultimap.of("Foo", "Bar"), OPENLAYER_ERROR) + assertNotFound(e, Headers.builder().put("Foo", "Bar").build(), OPENLAYER_ERROR) }) } @@ -322,7 +326,7 @@ class ErrorHandlingTest { .satisfies({ e -> assertUnprocessableEntity( e, - ImmutableListMultimap.of("Foo", "Bar"), + Headers.builder().put("Foo", "Bar").build(), OPENLAYER_ERROR ) }) @@ -369,7 +373,7 @@ class ErrorHandlingTest { assertThatThrownBy({ client.inferencePipelines().data().stream(params) }) .satisfies({ e -> - assertRateLimit(e, ImmutableListMultimap.of("Foo", "Bar"), OPENLAYER_ERROR) + assertRateLimit(e, Headers.builder().put("Foo", "Bar").build(), OPENLAYER_ERROR) }) } @@ -414,7 +418,11 @@ class ErrorHandlingTest { assertThatThrownBy({ client.inferencePipelines().data().stream(params) }) .satisfies({ e -> - assertInternalServer(e, ImmutableListMultimap.of("Foo", "Bar"), OPENLAYER_ERROR) + assertInternalServer( + e, + Headers.builder().put("Foo", "Bar").build(), + OPENLAYER_ERROR + ) }) } @@ -462,7 +470,7 @@ class ErrorHandlingTest { assertUnexpectedStatusCodeException( e, 999, - ImmutableListMultimap.of("Foo", "Bar"), + Headers.builder().put("Foo", "Bar").build(), toJson(OPENLAYER_ERROR) ) }) @@ -550,7 +558,7 @@ class ErrorHandlingTest { assertThatThrownBy({ client.inferencePipelines().data().stream(params) }) .satisfies({ e -> - assertBadRequest(e, ImmutableListMultimap.of(), OpenlayerError.builder().build()) + assertBadRequest(e, Headers.builder().build(), OpenlayerError.builder().build()) }) } @@ -561,7 +569,7 @@ class ErrorHandlingTest { private fun assertUnexpectedStatusCodeException( throwable: Throwable, statusCode: Int, - headers: ListMultimap, + headers: Headers, responseBody: ByteArray ) { assertThat(throwable) @@ -571,41 +579,33 @@ class ErrorHandlingTest { .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(statusCode) assertThat(e.body()).isEqualTo(String(responseBody)) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } - private fun assertBadRequest( - throwable: Throwable, - headers: ListMultimap, - error: OpenlayerError - ) { + private fun assertBadRequest(throwable: Throwable, headers: Headers, error: OpenlayerError) { assertThat(throwable) .asInstanceOf(InstanceOfAssertFactories.throwable(BadRequestException::class.java)) .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(400) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } - private fun assertUnauthorized( - throwable: Throwable, - headers: ListMultimap, - error: OpenlayerError - ) { + private fun assertUnauthorized(throwable: Throwable, headers: Headers, error: OpenlayerError) { assertThat(throwable) .asInstanceOf(InstanceOfAssertFactories.throwable(UnauthorizedException::class.java)) .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(401) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } private fun assertPermissionDenied( throwable: Throwable, - headers: ListMultimap, + headers: Headers, error: OpenlayerError ) { assertThat(throwable) @@ -615,27 +615,23 @@ class ErrorHandlingTest { .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(403) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } - private fun assertNotFound( - throwable: Throwable, - headers: ListMultimap, - error: OpenlayerError - ) { + private fun assertNotFound(throwable: Throwable, headers: Headers, error: OpenlayerError) { assertThat(throwable) .asInstanceOf(InstanceOfAssertFactories.throwable(NotFoundException::class.java)) .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(404) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } private fun assertUnprocessableEntity( throwable: Throwable, - headers: ListMultimap, + headers: Headers, error: OpenlayerError ) { assertThat(throwable) @@ -645,27 +641,23 @@ class ErrorHandlingTest { .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(422) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } - private fun assertRateLimit( - throwable: Throwable, - headers: ListMultimap, - error: OpenlayerError - ) { + private fun assertRateLimit(throwable: Throwable, headers: Headers, error: OpenlayerError) { assertThat(throwable) .asInstanceOf(InstanceOfAssertFactories.throwable(RateLimitException::class.java)) .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(429) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } private fun assertInternalServer( throwable: Throwable, - headers: ListMultimap, + headers: Headers, error: OpenlayerError ) { assertThat(throwable) @@ -673,7 +665,12 @@ class ErrorHandlingTest { .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(500) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } + + private fun Headers.toMap(): Map> = + mutableMapOf>().also { map -> + names().forEach { map[it] = values(it) } + } }