Skip to content

Commit

Permalink
chore(internal): codegen related update (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Oct 1, 2024
1 parent c1f2747 commit 9ae6b15
Show file tree
Hide file tree
Showing 48 changed files with 206 additions and 979 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# syntax=docker/dockerfile:1
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y \
RUN apt-get update && apt-get install -y --no-install-recommends \
libxkbcommon0 \
ca-certificates \
ca-certificates-java \
make \
curl \
git \
openjdk-17-jdk \
openjdk-17-jdk-headless \
unzip \
libc++1 \
vim \
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ Sometimes, the API may support other properties that are not yet supported in th
you can attach them using the `putAdditionalProperty` method.

```java
import com.braintrustdata.api.models.core.JsonValue;
ProjectCreateParams params = ProjectCreateParams.builder()
// ... normal properties
.putAdditionalProperty("secret_param", "4242")
.putAdditionalProperty("secret_param", JsonValue.from("4242"))
.build();
```

Expand Down Expand Up @@ -156,7 +157,7 @@ if (field.isMissing()) {
Sometimes, the server response may include additional properties that are not yet available in this library's types. You can access them using the model's `_additionalProperties` method:

```java
JsonValue secret = project._additionalProperties().get("secret_field");
JsonValue secret = acl._additionalProperties().get("secret_field");
```

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ package com.braintrustdata.api.errors

import com.google.common.collect.ListMultimap

class BadRequestException
constructor(
class BadRequestException(
headers: ListMultimap<String, String>,
private val error: BraintrustError,
) : BraintrustServiceException(headers, "${error}") {
override fun statusCode(): Int = 400

fun error(): BraintrustError = error
}
body: String,
error: BraintrustError,
) : BraintrustServiceException(400, headers, body, error)
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import com.google.common.collect.ListMultimap
abstract class BraintrustServiceException
@JvmOverloads
constructor(
private val statusCode: Int,
private val headers: ListMultimap<String, String>,
message: String? = null,
private val body: String,
private val error: BraintrustError,
message: String = "$statusCode: $error",
cause: Throwable? = null
) : BraintrustException(message, cause) {
abstract fun statusCode(): Int

fun statusCode(): Int = statusCode

fun headers(): ListMultimap<String, String> = headers

fun body(): String = body

fun error(): BraintrustError = error
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package com.braintrustdata.api.errors

import com.google.common.collect.ListMultimap

class InternalServerException
constructor(
private val statusCode: Int,
class InternalServerException(
statusCode: Int,
headers: ListMultimap<String, String>,
private val error: BraintrustError,
) : BraintrustServiceException(headers, "${error}") {
override fun statusCode(): Int = statusCode

fun error(): BraintrustError = error
}
body: String,
error: BraintrustError,
) : BraintrustServiceException(statusCode, headers, body, error)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ package com.braintrustdata.api.errors

import com.google.common.collect.ListMultimap

class NotFoundException
constructor(
class NotFoundException(
headers: ListMultimap<String, String>,
private val error: BraintrustError,
) : BraintrustServiceException(headers, "${error}") {
override fun statusCode(): Int = 404

fun error(): BraintrustError = error
}
body: String,
error: BraintrustError,
) : BraintrustServiceException(404, headers, body, error)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ package com.braintrustdata.api.errors

import com.google.common.collect.ListMultimap

class PermissionDeniedException
constructor(
class PermissionDeniedException(
headers: ListMultimap<String, String>,
private val error: BraintrustError,
) : BraintrustServiceException(headers, "${error}") {
override fun statusCode(): Int = 403

fun error(): BraintrustError = error
}
body: String,
error: BraintrustError,
) : BraintrustServiceException(403, headers, body, error)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ package com.braintrustdata.api.errors

import com.google.common.collect.ListMultimap

class RateLimitException
constructor(
class RateLimitException(
headers: ListMultimap<String, String>,
private val error: BraintrustError,
) : BraintrustServiceException(headers, "${error}") {
override fun statusCode(): Int = 429

fun error(): BraintrustError = error
}
body: String,
error: BraintrustError,
) : BraintrustServiceException(429, headers, body, error)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ package com.braintrustdata.api.errors

import com.google.common.collect.ListMultimap

class UnauthorizedException
constructor(
class UnauthorizedException(
headers: ListMultimap<String, String>,
private val error: BraintrustError,
) : BraintrustServiceException(headers, "${error}") {
override fun statusCode(): Int = 401

fun error(): BraintrustError = error
}
body: String,
error: BraintrustError,
) : BraintrustServiceException(401, headers, body, error)
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package com.braintrustdata.api.errors

import com.google.common.collect.ListMultimap

class UnexpectedStatusCodeException
constructor(
private val statusCode: Int,
class UnexpectedStatusCodeException(
statusCode: Int,
headers: ListMultimap<String, String>,
private val body: String
) : BraintrustServiceException(headers, "Unexpected status code: ${statusCode}") {
override fun statusCode(): Int = statusCode

fun body() = body
}
body: String,
error: BraintrustError,
) : BraintrustServiceException(statusCode, headers, body, error)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ package com.braintrustdata.api.errors

import com.google.common.collect.ListMultimap

class UnprocessableEntityException
constructor(
class UnprocessableEntityException(
headers: ListMultimap<String, String>,
private val error: BraintrustError,
) : BraintrustServiceException(headers, "${error}") {
override fun statusCode(): Int = 422

fun error(): BraintrustError = error
}
body: String,
error: BraintrustError,
) : BraintrustServiceException(422, headers, body, error)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ constructor(
private val startingAfter: String?,
private val additionalQueryParams: Map<String, List<String>>,
private val additionalHeaders: Map<String, List<String>>,
private val additionalBodyProperties: Map<String, JsonValue>,
) {

fun objectId(): String = objectId
Expand Down Expand Up @@ -67,8 +66,6 @@ constructor(

fun _additionalHeaders(): Map<String, List<String>> = additionalHeaders

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

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
Expand All @@ -82,8 +79,7 @@ constructor(
this.limit == other.limit &&
this.startingAfter == other.startingAfter &&
this.additionalQueryParams == other.additionalQueryParams &&
this.additionalHeaders == other.additionalHeaders &&
this.additionalBodyProperties == other.additionalBodyProperties
this.additionalHeaders == other.additionalHeaders
}

override fun hashCode(): Int {
Expand All @@ -96,12 +92,11 @@ constructor(
startingAfter,
additionalQueryParams,
additionalHeaders,
additionalBodyProperties,
)
}

override fun toString() =
"AclListParams{objectId=$objectId, objectType=$objectType, endingBefore=$endingBefore, ids=$ids, limit=$limit, startingAfter=$startingAfter, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}"
"AclListParams{objectId=$objectId, objectType=$objectType, endingBefore=$endingBefore, ids=$ids, limit=$limit, startingAfter=$startingAfter, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders}"

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

Expand All @@ -121,7 +116,6 @@ constructor(
private var startingAfter: String? = null
private var additionalQueryParams: MutableMap<String, MutableList<String>> = mutableMapOf()
private var additionalHeaders: MutableMap<String, MutableList<String>> = mutableMapOf()
private var additionalBodyProperties: MutableMap<String, JsonValue> = mutableMapOf()

@JvmSynthetic
internal fun from(aclListParams: AclListParams) = apply {
Expand All @@ -133,7 +127,6 @@ constructor(
this.startingAfter = aclListParams.startingAfter
additionalQueryParams(aclListParams.additionalQueryParams)
additionalHeaders(aclListParams.additionalHeaders)
additionalBodyProperties(aclListParams.additionalBodyProperties)
}

/** The id of the object the ACL applies to */
Expand Down Expand Up @@ -221,20 +214,6 @@ constructor(

fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) }

fun additionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) = apply {
this.additionalBodyProperties.clear()
this.additionalBodyProperties.putAll(additionalBodyProperties)
}

fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
this.additionalBodyProperties.put(key, value)
}

fun putAllAdditionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) =
apply {
this.additionalBodyProperties.putAll(additionalBodyProperties)
}

fun build(): AclListParams =
AclListParams(
checkNotNull(objectId) { "`objectId` is required but was not set" },
Expand All @@ -245,7 +224,6 @@ constructor(
startingAfter,
additionalQueryParams.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(),
additionalHeaders.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(),
additionalBodyProperties.toUnmodifiable(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package com.braintrustdata.api.models

import com.braintrustdata.api.core.JsonValue
import com.braintrustdata.api.core.NoAutoDetect
import com.braintrustdata.api.core.toUnmodifiable
import com.braintrustdata.api.models.*
Expand All @@ -13,7 +12,6 @@ constructor(
private val aclId: String,
private val additionalQueryParams: Map<String, List<String>>,
private val additionalHeaders: Map<String, List<String>>,
private val additionalBodyProperties: Map<String, JsonValue>,
) {

fun aclId(): String = aclId
Expand All @@ -33,8 +31,6 @@ constructor(

fun _additionalHeaders(): Map<String, List<String>> = additionalHeaders

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

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
Expand All @@ -43,21 +39,19 @@ constructor(
return other is AclRetrieveParams &&
this.aclId == other.aclId &&
this.additionalQueryParams == other.additionalQueryParams &&
this.additionalHeaders == other.additionalHeaders &&
this.additionalBodyProperties == other.additionalBodyProperties
this.additionalHeaders == other.additionalHeaders
}

override fun hashCode(): Int {
return Objects.hash(
aclId,
additionalQueryParams,
additionalHeaders,
additionalBodyProperties,
)
}

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

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

Expand All @@ -72,14 +66,12 @@ constructor(
private var aclId: String? = null
private var additionalQueryParams: MutableMap<String, MutableList<String>> = mutableMapOf()
private var additionalHeaders: MutableMap<String, MutableList<String>> = mutableMapOf()
private var additionalBodyProperties: MutableMap<String, JsonValue> = mutableMapOf()

@JvmSynthetic
internal fun from(aclRetrieveParams: AclRetrieveParams) = apply {
this.aclId = aclRetrieveParams.aclId
additionalQueryParams(aclRetrieveParams.additionalQueryParams)
additionalHeaders(aclRetrieveParams.additionalHeaders)
additionalBodyProperties(aclRetrieveParams.additionalBodyProperties)
}

/** Acl id */
Expand Down Expand Up @@ -125,26 +117,11 @@ constructor(

fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) }

fun additionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) = apply {
this.additionalBodyProperties.clear()
this.additionalBodyProperties.putAll(additionalBodyProperties)
}

fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
this.additionalBodyProperties.put(key, value)
}

fun putAllAdditionalBodyProperties(additionalBodyProperties: Map<String, JsonValue>) =
apply {
this.additionalBodyProperties.putAll(additionalBodyProperties)
}

fun build(): AclRetrieveParams =
AclRetrieveParams(
checkNotNull(aclId) { "`aclId` is required but was not set" },
additionalQueryParams.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(),
additionalHeaders.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(),
additionalBodyProperties.toUnmodifiable(),
)
}
}
Loading

0 comments on commit 9ae6b15

Please sign in to comment.