Skip to content

Commit

Permalink
chore(internal): codegen related update (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Nov 23, 2024
1 parent 58407f3 commit e2385b2
Show file tree
Hide file tree
Showing 113 changed files with 2,873 additions and 2,806 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,22 @@ val client = BraintrustOkHttpClient.builder()
.build()
```

## Logging

We use the standard [OkHttp logging interceptor](https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor).

You can enable logging by setting the environment variable `BRAINTRUST_LOG` to `info`.

```sh
$ export BRAINTRUST_LOG=info
```

Or to `debug` for more verbose logging.

```sh
$ export BRAINTRUST_LOG=debug
```

## Semantic versioning

This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
Expand Down
1 change: 1 addition & 0 deletions braintrust-kotlin-client-okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {
api(project(":braintrust-kotlin-core"))

implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")

testImplementation(kotlin("test"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,38 @@ import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import okio.BufferedSink

class OkHttpClient
private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val baseUrl: HttpUrl) :
HttpClient {

private fun getClient(requestOptions: RequestOptions): okhttp3.OkHttpClient {
val timeout = requestOptions.timeout ?: return okHttpClient
return okHttpClient
.newBuilder()
.connectTimeout(timeout)
.readTimeout(timeout)
.writeTimeout(timeout)
.callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
.build()
val clientBuilder = okHttpClient.newBuilder()

val logLevel =
when (System.getenv("BRAINTRUST_LOG")?.lowercase()) {
"info" -> HttpLoggingInterceptor.Level.BASIC
"debug" -> HttpLoggingInterceptor.Level.BODY
else -> null
}
if (logLevel != null) {
clientBuilder.addNetworkInterceptor(
HttpLoggingInterceptor().setLevel(logLevel).apply { redactHeader("Authorization") }
)
}

val timeout = requestOptions.timeout
if (timeout != null) {
clientBuilder
.connectTimeout(timeout)
.readTimeout(timeout)
.writeTimeout(timeout)
.callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
}

return clientBuilder.build()
}

override fun execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ constructor(

fun removeAcls(): List<RemoveAcl>? = removeAcls

fun _additionalHeaders(): Headers = additionalHeaders

fun _additionalQueryParams(): QueryParams = additionalQueryParams

fun _additionalBodyProperties(): Map<String, JsonValue> = additionalBodyProperties

internal fun getBody(): AclBatchUpdateBody {
return AclBatchUpdateBody(
addAcls,
Expand Down Expand Up @@ -168,25 +174,6 @@ constructor(
"AclBatchUpdateBody{addAcls=$addAcls, removeAcls=$removeAcls, additionalProperties=$additionalProperties}"
}

fun _additionalHeaders(): Headers = additionalHeaders

fun _additionalQueryParams(): QueryParams = additionalQueryParams

fun _additionalBodyProperties(): Map<String, JsonValue> = additionalBodyProperties

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return /* spotless:off */ other is AclBatchUpdateParams && addAcls == other.addAcls && removeAcls == other.removeAcls && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
}

override fun hashCode(): Int = /* spotless:off */ Objects.hash(addAcls, removeAcls, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */

override fun toString() =
"AclBatchUpdateParams{addAcls=$addAcls, removeAcls=$removeAcls, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"

fun toBuilder() = Builder().from(this)

companion object {
Expand All @@ -204,11 +191,11 @@ constructor(
private var additionalBodyProperties: MutableMap<String, JsonValue> = mutableMapOf()

internal fun from(aclBatchUpdateParams: AclBatchUpdateParams) = apply {
this.addAcls(aclBatchUpdateParams.addAcls ?: listOf())
this.removeAcls(aclBatchUpdateParams.removeAcls ?: listOf())
additionalHeaders(aclBatchUpdateParams.additionalHeaders)
additionalQueryParams(aclBatchUpdateParams.additionalQueryParams)
additionalBodyProperties(aclBatchUpdateParams.additionalBodyProperties)
addAcls = aclBatchUpdateParams.addAcls?.toMutableList() ?: mutableListOf()
removeAcls = aclBatchUpdateParams.removeAcls?.toMutableList() ?: mutableListOf()
additionalHeaders = aclBatchUpdateParams.additionalHeaders.toBuilder()
additionalQueryParams = aclBatchUpdateParams.additionalQueryParams.toBuilder()
additionalBodyProperties = aclBatchUpdateParams.additionalBodyProperties.toMutableMap()
}

/**
Expand Down Expand Up @@ -387,8 +374,8 @@ constructor(

fun build(): AclBatchUpdateParams =
AclBatchUpdateParams(
if (addAcls.size == 0) null else addAcls.toImmutable(),
if (removeAcls.size == 0) null else removeAcls.toImmutable(),
addAcls.toImmutable().ifEmpty { null },
removeAcls.toImmutable().ifEmpty { null },
additionalHeaders.build(),
additionalQueryParams.build(),
additionalBodyProperties.toImmutable(),
Expand Down Expand Up @@ -1380,4 +1367,17 @@ constructor(
override fun toString() =
"RemoveAcl{objectType=$objectType, objectId=$objectId, userId=$userId, groupId=$groupId, permission=$permission, restrictObjectType=$restrictObjectType, roleId=$roleId, additionalProperties=$additionalProperties}"
}

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return /* spotless:off */ other is AclBatchUpdateParams && addAcls == other.addAcls && removeAcls == other.removeAcls && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
}

override fun hashCode(): Int = /* spotless:off */ Objects.hash(addAcls, removeAcls, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */

override fun toString() =
"AclBatchUpdateParams{addAcls=$addAcls, removeAcls=$removeAcls, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ constructor(

fun userId(): String? = userId

fun _additionalHeaders(): Headers = additionalHeaders

fun _additionalQueryParams(): QueryParams = additionalQueryParams

fun _additionalBodyProperties(): Map<String, JsonValue> = additionalBodyProperties

internal fun getBody(): AclCreateBody {
return AclCreateBody(
objectId,
Expand Down Expand Up @@ -241,25 +247,6 @@ constructor(
"AclCreateBody{objectId=$objectId, objectType=$objectType, groupId=$groupId, permission=$permission, restrictObjectType=$restrictObjectType, roleId=$roleId, userId=$userId, additionalProperties=$additionalProperties}"
}

fun _additionalHeaders(): Headers = additionalHeaders

fun _additionalQueryParams(): QueryParams = additionalQueryParams

fun _additionalBodyProperties(): Map<String, JsonValue> = additionalBodyProperties

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return /* spotless:off */ other is AclCreateParams && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
}

override fun hashCode(): Int = /* spotless:off */ Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */

override fun toString() =
"AclCreateParams{objectId=$objectId, objectType=$objectType, groupId=$groupId, permission=$permission, restrictObjectType=$restrictObjectType, roleId=$roleId, userId=$userId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"

fun toBuilder() = Builder().from(this)

companion object {
Expand All @@ -282,16 +269,16 @@ constructor(
private var additionalBodyProperties: MutableMap<String, JsonValue> = mutableMapOf()

internal fun from(aclCreateParams: AclCreateParams) = apply {
this.objectId = aclCreateParams.objectId
this.objectType = aclCreateParams.objectType
this.groupId = aclCreateParams.groupId
this.permission = aclCreateParams.permission
this.restrictObjectType = aclCreateParams.restrictObjectType
this.roleId = aclCreateParams.roleId
this.userId = aclCreateParams.userId
additionalHeaders(aclCreateParams.additionalHeaders)
additionalQueryParams(aclCreateParams.additionalQueryParams)
additionalBodyProperties(aclCreateParams.additionalBodyProperties)
objectId = aclCreateParams.objectId
objectType = aclCreateParams.objectType
groupId = aclCreateParams.groupId
permission = aclCreateParams.permission
restrictObjectType = aclCreateParams.restrictObjectType
roleId = aclCreateParams.roleId
userId = aclCreateParams.userId
additionalHeaders = aclCreateParams.additionalHeaders.toBuilder()
additionalQueryParams = aclCreateParams.additionalQueryParams.toBuilder()
additionalBodyProperties = aclCreateParams.additionalBodyProperties.toMutableMap()
}

/** The id of the object the ACL applies to */
Expand Down Expand Up @@ -777,4 +764,17 @@ constructor(

fun asString(): String = _value().asStringOrThrow()
}

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return /* spotless:off */ other is AclCreateParams && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
}

override fun hashCode(): Int = /* spotless:off */ Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */

override fun toString() =
"AclCreateParams{objectId=$objectId, objectType=$objectType, groupId=$groupId, permission=$permission, restrictObjectType=$restrictObjectType, roleId=$roleId, userId=$userId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ constructor(

fun aclId(): String = aclId

fun _additionalHeaders(): Headers = additionalHeaders

fun _additionalQueryParams(): QueryParams = additionalQueryParams

fun _additionalBodyProperties(): Map<String, JsonValue> = additionalBodyProperties

internal fun getBody(): Map<String, JsonValue>? {
return additionalBodyProperties.ifEmpty { null }
}
Expand All @@ -35,25 +41,6 @@ constructor(
}
}

fun _additionalHeaders(): Headers = additionalHeaders

fun _additionalQueryParams(): QueryParams = additionalQueryParams

fun _additionalBodyProperties(): Map<String, JsonValue> = additionalBodyProperties

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return /* spotless:off */ other is AclDeleteParams && aclId == other.aclId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
}

override fun hashCode(): Int = /* spotless:off */ Objects.hash(aclId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */

override fun toString() =
"AclDeleteParams{aclId=$aclId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"

fun toBuilder() = Builder().from(this)

companion object {
Expand All @@ -70,10 +57,10 @@ constructor(
private var additionalBodyProperties: MutableMap<String, JsonValue> = mutableMapOf()

internal fun from(aclDeleteParams: AclDeleteParams) = apply {
this.aclId = aclDeleteParams.aclId
additionalHeaders(aclDeleteParams.additionalHeaders)
additionalQueryParams(aclDeleteParams.additionalQueryParams)
additionalBodyProperties(aclDeleteParams.additionalBodyProperties)
aclId = aclDeleteParams.aclId
additionalHeaders = aclDeleteParams.additionalHeaders.toBuilder()
additionalQueryParams = aclDeleteParams.additionalQueryParams.toBuilder()
additionalBodyProperties = aclDeleteParams.additionalBodyProperties.toMutableMap()
}

/** Acl id */
Expand Down Expand Up @@ -207,4 +194,17 @@ constructor(
additionalBodyProperties.toImmutable(),
)
}

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return /* spotless:off */ other is AclDeleteParams && aclId == other.aclId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
}

override fun hashCode(): Int = /* spotless:off */ Objects.hash(aclId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */

override fun toString() =
"AclDeleteParams{aclId=$aclId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"
}
Loading

0 comments on commit e2385b2

Please sign in to comment.